我首先要说标题引起了一些类似的问题,但是我已经尝试了z-index
,display: inline-block
和overflow:hidden
之类的解决方案以及其他一些选择修复程序有人建议。这些都没有解决我的问题。
当我使用以下代码调整浏览器大小时,div会相互重叠。
我的aspx:
<div id="contentContainer">
<div id="contentOne">
<asp:LinkButton ID="ItemOne" runat="server" Text="Sample Item One"></asp:LinkButton>
<br />
<asp:Label ID="txt_itemOne" runat="server" Text="Sample Item Description"></asp:Label>
</div>
<div id="contentTwo">
<asp:LinkButton ID="ItemTwo" runat="server" Text="Sample Item Two"></asp:LinkButton>
<br />
<asp:Label ID="txt_itemTwo" runat="server" Text="Sample Item Description"></asp:Label>
</div>
<div id="contentThree">
<asp:LinkButton ID="ItemThree" runat="server" Text="Sample Item Three"></asp:LinkButton>
<br />
<asp:Label ID="txt_itemThree" runat="server" Text="Sample Item Description"></asp:Label>
</div>
</div>
css:
#contentOne {
border: 1px solid black;
display: inline-block;
height: 200px;
width: 20%;
max-width: 80%;
min-width: 200px;
top:0;
position: absolute;
text-align: center;
}
#contentTwo {
border: 1px solid black;
display: inline-block;
height: 200px;
width: 20%;
min-width: 200px;
top: 0;
left: 25%;
position: absolute;
text-align:center;
}
#contentThree {
border: 1px solid black;
display: inline-block;
height: 200px;
width: 20%;
min-width: 200px;
top: 0;
left: 50%;
position: absolute;
text-align:center;
}
#contentContainer {
top: 20%;
width: 100%;
position: absolute;
}
答案 0 :(得分:1)
使用CSS Tricks并不是一种将事物相对于彼此进行布局的方法。 Flexbox或Grid是用于此的CSS方法。
#contentContainer {
display: flex;
justify-content: space-between;
margin-top: 20%;
width: 100%;
}
#contentOne,
#contentTwo,
#contentThree {
border: 1px solid black;
display: inline-block;
height: 200px;
width: 20%;
max-width: 80%;
min-width: 200px;
text-align: center;
}
<div id="contentContainer">
<div id="contentOne">
<asp:LinkButton ID="ItemOne" runat="server" Text="Sample Item One"></asp:LinkButton>
<br />
<asp:Label ID="txt_itemOne" runat="server" Text="Sample Item Description"></asp:Label>
</div>
<div id="contentTwo">
<asp:LinkButton ID="ItemTwo" runat="server" Text="Sample Item Two"></asp:LinkButton>
<br />
<asp:Label ID="txt_itemTwo" runat="server" Text="Sample Item Description"></asp:Label>
</div>
<div id="contentThree">
<asp:LinkButton ID="ItemThree" runat="server" Text="Sample Item Three"></asp:LinkButton>
<br />
<asp:Label ID="txt_itemThree" runat="server" Text="Sample Item Description"></asp:Label>
</div>
</div>
grid为{{3}}入门提供了很好的指南。
#contentContainer {
display: grid;
grid-column-gap: 10%;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 200px;
margin-top: 20%;
}
#contentOne,
#contentTwo,
#contentThree {
border: 1px solid black;
text-align: center;
}
<div id="contentContainer">
<div id="contentOne">
<asp:LinkButton ID="ItemOne" runat="server" Text="Sample Item One"></asp:LinkButton>
<br />
<asp:Label ID="txt_itemOne" runat="server" Text="Sample Item Description"></asp:Label>
</div>
<div id="contentTwo">
<asp:LinkButton ID="ItemTwo" runat="server" Text="Sample Item Two"></asp:LinkButton>
<br />
<asp:Label ID="txt_itemTwo" runat="server" Text="Sample Item Description"></asp:Label>
</div>
<div id="contentThree">
<asp:LinkButton ID="ItemThree" runat="server" Text="Sample Item Three"></asp:LinkButton>
<br />
<asp:Label ID="txt_itemThree" runat="server" Text="Sample Item Description"></asp:Label>
</div>
</div>
答案 1 :(得分:0)
这是您尝试使用的方法的替代方法。它的效果可能与您所寻找的不一样,但是它具有移动响应能力,并且语法更好。
* {
box-sizing: border-box;
}
/* STRUCTURE */
.wrapper {
padding: 5px;
max-width: 960px;
width: 95%;
margin: 20px auto;
}
.columns {
display: flex;
flex-flow: row wrap;
justify-content: center;
margin: 5px 0;
}
.column {
flex: 1;
border: 1px solid gray;
margin: 2px;
padding: 10px;
&:first-child {
margin-left: 0;
}
&:last-child {
margin-right: 0;
}
}
@media screen and (max-width: 980px) {
.columns .column {
margin-bottom: 5px;
flex-basis: 40%;
&:nth-last-child(2) {
margin-right: 0;
}
&:last-child {
flex-basis: 100%;
margin: 0;
}
}
}
@media screen and (max-width: 680px) {
.columns .column {
flex-basis: 100%;
margin: 0 0 5px 0;
}
}
<div class="wrapper">
<section class="columns">
<div class="column">
<h2>1st Content Area</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sequi ratione architecto necessitatibus cum praesentium dolor totam voluptatibus recusandae?</p>
</div>
<div class="column">
<h2>2nd Content Area</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sequi ratione architecto necessitatibus cum praesentium dolor totam voluptatibus recusandae? Illo quod nemo ratione itaque dolores laudantium error vero laborum blanditiis nostrum.</p>
</div>
<div class="column">
<h2>3rd Content Area</h2>
<p>Illo quod nemo ratione itaque dolores laudantium error vero laborum blanditiis nostrum. Lorem ipsum dolor sit amet consectetur adipisicing elit. Sequi ratione architecto cum praesentium voluptatibus recusandae?</p>
</div>
</section>