gpt4 book ai didi

html - CSS float : Why doesn't the second box shift to the left side of my floated box

转载 作者:太空宇宙 更新时间:2023-11-03 23:23:16 25 4
gpt4 key购买 nike

我有以下 HTML 和 CSS。我想知道为什么第二个盒子不会浮到第一个盒子的一边。据我了解,如果 float 了特定宽度的框,则其他 div 将 float 到 float 框/div 的左侧,直到没有更多空间可容纳同一行框。

   #content-wrapper {
border: 1px solid blue;
width: 100%
}
.first-box {
width: 450px;
border: 1px solid red;
float: left;
}
.first-box h2 {
background: url(img/top-menu-bg.jpg) no-repeat;
line-height: 45px;
padding-left: 15px;
margin-bottom: 15px;
}
.second-box {
width: 5%;
border: 1px solid red;
}
</style>
<div id="content-wrapper">
<div class="first-box">
<h2>Welcome to My Engg.</h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
<div class="second-box">
<p>Some Side bar text</p>
</div>
</div>

谢谢

最佳答案

需要设置display:inline-block

CSS

#content-wrapper{
border:1px solid blue;
width:100%;
display:block;
overflow:hidden;
}

.first-box {
width:450px;
border:1px solid red;
float:left;
display:inline-block;
}

.first-box h2{
background:url(img/top-menu-bg.jpg) no-repeat;
line-height:45px;
padding-left:15px;
margin-bottom:15px;
display:inline-block;
}

.second-box{
width:5%;
border:1px solid red;
display:inline-block; //HERE YOUR FIX
}

DEMO HERE

关于html - CSS float : Why doesn't the second box shift to the left side of my floated box,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27988098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com