我有一个由2个导航栏(顶部),顶部图形(中间)flexbox和一个内容flexbox(底部)组成的正文。
在top-graphic 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>
答案 0 :(得分:0)
由于要真正了解您的需求有点困难,我在此根据您现有的代码进行了猜测。
这是您正在寻找的整体布局吗?
* {
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>