CSS:在父级中浮动,没有定义宽度
请参阅下面的小提琴以查看代码和结果:
http://jsfiddle.net/jhacks/nnZWB/ 7/
我试图让两个 div 浮动:位于其没有定义宽度的父 div 内。如果我设置一个定义的宽度,它就可以工作,但由于其中一个子 div 需要具有可变宽度,我只是希望父 div 能够拉伸以适合子 div。然而,正如你从小提琴中看到的,他们不想为我水平漂浮。
我尝试添加一些不同的样式(例如溢出:隐藏)但无法使其工作。
感谢任何和所有的帮助。谢谢!
Please see the fiddle below to see the code and result:
http://jsfiddle.net/jhacks/nnZWB/7/
I am trying to get two divs to float:right within their parent div that doesn't have a defined width. It works if I set a defined width, but as one of the children divs needs to have a variable width, I simply want the parent div to just stretch to fit the children divs. However, as you can see from the fiddle, they don't want to float horizontally for me.
I've tried adding a few different styles (e.g. overflow:hidden) but can't get it to work.
Any and all help is appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您提到的问题是在 div
topProfile
内,那么您只需将float: right
添加到topName
即可。如果这不是问题,那么您可能需要包含一个图像来帮助表示您希望布局的外观。
If the problem you are refering to is within the div
topProfile
then you just need to addfloat: right
totopName
.If this is not the problem then you might have to include an image to help represent how you would like your layout to look.
将
topProfilePic
div 移动到topName
div 内。http://jsfiddle.net/nnZWB/8/
Move the
topProfilePic
div inside thetopName
div.http://jsfiddle.net/nnZWB/8/