CSS 向左浮动不起作用
我试图将两个 div 分成左右两部分。左侧是静态的(300px 高度),右侧是非静态的(例如帖子和评论)。底部有页脚。
<div>
<div>
<div class="right"><img src="images/members/bigava/crays.png" style="width: 630px; height: 130px;" /></div>
</div>
<div>
<div class="left" style="float: left;"><img src="images/members/ava/crays.jpg" style="width:120px; height:80px;" /></div>
</div>
我将主 div 的宽度设置为 760px,因此通过这些设置,我还有 10px 的空闲空间。现在的问题是,我无法将 float-right 分配给具有右类的 div,而只能将 float-left 分配给具有左类的 div。我尝试上下更改 div,重新分配位置,但我得到的不是我想要的。有什么帮助吗?
编辑
CSS
.right {
font-family: verdana;
font-size: 12px;
border-radius: 3px;
}
.left {
font-family: verdana;
font-size: 10px;
color: #000000;
border-radius: 3px;
}
这是我得到的结果,但我不想要
我想要的是
i'm trying to split two divs into two section, left and right. With the left one being static (300px height) and right one is not static (such as posts and comments). With a footer at the bottom.
<div>
<div>
<div class="right"><img src="images/members/bigava/crays.png" style="width: 630px; height: 130px;" /></div>
</div>
<div>
<div class="left" style="float: left;"><img src="images/members/ava/crays.jpg" style="width:120px; height:80px;" /></div>
</div>
I made my main div with a width of 760px, hence with those setting, i still have 10px to spare. The problem now is, i cannot assign float-right to the div with right class, and can only assign float-left to the div with left class. I tried changing the div up and down, reassigning the positions, but what i get isn't what i want. Any help?
edit
CSS
.right {
font-family: verdana;
font-size: 12px;
border-radius: 3px;
}
.left {
font-family: verdana;
font-size: 10px;
color: #000000;
border-radius: 3px;
}
This is the results i get which i don't want
what i want is
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DIV
是一个块元素,因此您可以将float
或inline-block
赋予right div
以获取其实际值width
像这样:编辑:
回答下面的评论
,如果您将
float
给div
那么您必须清除其父级像这样:
DIV
is a block element so you can givefloat
orinline-block
to yourright div
to take its actualwidth
like this:EDIT:
answer your comment below
if you give
float
to thedivs
then you have toclear its parent
like this :您需要删除一些 div 或将浮动分配给右、左 div 的父 div。
这应该有效。
you need to get rid of some divs or assign floating to parent divs of right, left divs.
this should work.
如果宽度测量正确,则可以通过将所有内容实际浮动到左侧来获得该布局。你的 div 顺序必须正确堆叠,它会自然地浮动到你想要的位置。您拥有的 div 数量超出了必要的数量。一定要把这个清理干净。
If you do the width measurements right, you can get that layout by actually floating everything to the left. Your div order has to stack right, and it will naturally float to where you want it. You have more divs than necessary. Be sure to clean this up.