CSS:在父级中浮动,没有定义宽度

发布于 2024-12-22 23:48:39 字数 330 浏览 1 评论 0原文

请参阅下面的小提琴以查看代码和结果:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

_畞蕅 2024-12-29 23:48:39

如果您提到的问题是在 div topProfile 内,那么您只需将 float: right 添加到 topName 即可。

如果这不是问题,那么您可能需要包含一个图像来帮助表示您希望布局的外观。

If the problem you are refering to is within the div topProfile then you just need to add float: right to topName.

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.

蹲在坟头点根烟 2024-12-29 23:48:39

topProfilePic div 移动到 topName div 内。

<div id="topName">
    <div id="topProfilePic">    
        <div id="pic"></div>    
    </div>
    <a class="topText" href="name.html">Your Name Here</a>
</div>

http://jsfiddle.net/nnZWB/8/

Move the topProfilePic div inside the topName div.

<div id="topName">
    <div id="topProfilePic">    
        <div id="pic"></div>    
    </div>
    <a class="topText" href="name.html">Your Name Here</a>
</div>

http://jsfiddle.net/nnZWB/8/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文