如何在不设置显式宽度的情况下使 div 的内容换行?
我想要一系列带有标题和其他信息的帖子。问题是,根据包含的 div 有多少空间以及标题的长度,它导致我的“后摘要”(标题、日期等)div 换行到下一行,使其看起来像
:它在做什么:
这是我想要它执行的操作(注意标题已换行,但并没有导致整个“ post-summary" 换行到下一行,如前面的示例所示):
我不在乎标题换行多少或换行多少行。我只是不希望它像第一个示例中那样强制包含帖子信息的父 div 低于帖子编号。
我创建了一个示例 jsfiddle 来进一步说明我在做什么: http://jsfiddle.net/aZvVU/6/
如何使帖子标题简单当它没有足够的空间时换行并且不会导致它使整个“后摘要”div 下降到下一行?如果可以避免的话,我不想固定标题宽度。
I want to have a series of posts with titles and other information. The problem is, depending on how much space the containing div has and how long the titles are, it is causing my "post-summary" (title, date, etc) div to wrap to the next line making it look like:
Here is what it is doing:
Here is what I want it to do (note the title wrapped, but didn't cause the whole "post-summary" to wrap to the next line like in the previous example):
I don't care how much the title wraps or how many lines it wraps to. I just don't want it to force the parent div which also contains the post-info to drop below the post number like it does in the first example.
I've created an example jsfiddle to further illustrate what I'm doing:
http://jsfiddle.net/aZvVU/6/
How can I make the post-titles simply wrap when it doesn't have enough space and not cause it to make the whole "post-summary" div from dropping to the next line? I don't want to make the title width fixed if I can avoid it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将此作为起点 http://jsfiddle.net/A8csU/
HTML:
CSS:
You can use this as a starting point http://jsfiddle.net/A8csU/
HTML:
CSS:
您只需对代码进行一些调整,如下所示:
这是一个工作示例,其中代码为 http://jsfiddle。 net/YumSP/
编辑以修复标题换行 http://jsfiddle.net/YumSP/1/< /a>
You can just make a few tweaks to your code like so:
Here is a working example, with your code http://jsfiddle.net/YumSP/
edited to fix title wrapping http://jsfiddle.net/YumSP/1/
将浮动放在
.post-summary
上,您不需要它,它会导致您的换行。然后在.post-summary
中添加margin-left: 40px;
,确保有.post-number
的空间,并给出错觉.post-number
的完整高度列,而不必破坏高度。要整理导航栏,请从
.post-list
中删除浮动并删除您的清除。如果您希望导航栏占据一整列,请向
.post-list
添加margin-right:220px
。例如:
Drop the floating on
.post-summary
, you don't need it and it is causing your wrapping. Then addmargin-left: 40px;
to.post-summary
to ensure that there is room for the.post-number
and give the illusion of a full height column for the.post-number
without having to muck about the heights.To sort out the navbar, drop the floating from
.post-list
and kill off your clearing<div>
s. If you want the navbar to take up a whole column then add amargin-right:220px
to.post-list
.For example: