子元素溢出父元素

用户名

我有一个由2个导航栏(顶部),顶部图形(中间)弹性框和一个内容弹性框(底部)组成的主体。

我想在顶部图形的Flexbox中插入一个黑匣子,在其中放置文本。当我制作此框时,它不会溢出父框的顶部,但是会溢出父框的底部和右侧,并在我调整页面大小时继续进入我的内容框。我希望我的盒子保持在其父元素的边界之内,并在设置宽度/高度时尊重我的父元素,以使我在调整网站大小时不会与内容flexbox重叠。

.nav {
  display: flex;
  flex: 1;
  background-color: white;
  flex-direction: column;
}
.topnav {
  flex: 1;
  background-color: white;
  border-bottom: ridge 1px;
}
.bottomnav {
  flex: 1;
  background-color: white;
}
.topgraphic {
  overflow: hidden;
  position: relative;
  flex: 2;
  background-color: lightblue;
  z-index: -2;
}
.topgraphic img {
  background-size: cover;
  background-repeat: no-repeat;
  position: absolute;
  width: 100%;
  height: 100%;
  -moz-box-shadow: inset 0px 12px 15px -12px #696868;
  -webkit-box-shadow: inset 0px 12px 15px -12px #696868;
  box-shadow: inset 0px 12px 15px -12px #696868;
  z-index: -1;
}
.topgraphic .textbox {
  box-sizing: inherit;
  position: absolute;
  margin-right: 5%;
  margin-bottom: 10%;
  width: 30%;
  height: 80%;
  background-color: rgba(0, 0, 0, 0.6);
}
.content {
  z-index: -5;
  flex: 7;
  background-color: white;
  min-height: 25%;
}
<div class="nav">
    <div class="topnav"></div>
    <div class="bottomnav"></div>
</div>
<div class="topgraphic">
    <img alt="TopGraphic" class="auto-style1" src="Images/Topgraphic.jpg" />
    <asp:Image ID="Image1" runat="server" />
    <div class="textbox">
        <!-- <div class="topText">
        <h1>Demonstration</h1>
        </div> -->
    </div>
</div>

一个儿子

由于要真正理解您要查找的内容有点困难,因此我在这里根据您现有的代码进行了猜测。

这是您要寻找的整体布局吗?

* {
  box-sizing: border-box;
}
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  color: gray;
  padding: 1%;
}
.outer {
  display: flex;
  flex-flow: column;
  height: 98%;
  width: 90%;
  margin: 0 auto;
  box-shadow: 0px 0px 10px 0px #696868;
}
.top { 
  display: flex;
  flex-flow: column;
  background-color: white;
}
.middle { 
  background-color: lightblue;
  background-image: url(http://lorempixel.com/400/100/sports/9/);
  background-size: cover;
  background-repeat: no-repeat;
  clear: right;
}
  .middle .textbox {
     float: right;
     width: 30%;
     height: 70px;
     background-color: rgba(0,0,0,0.7);
  }
.content {
  position: relative;
  flex: 1 0 auto;
  height: 0;
}
.content-inner {
  background-color: white;
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
}
<div class="outer">
  <div class="top">
    <div class="top">top top</div>
    <div class="bottom">top bottom</div>
  </div>
  <div class="middle">
      <div class="textbox">
          text box
      </div>
    </div>
  <div class="content">
    <div class="content-inner">content</div>
  </div>
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章