[英]CSS styling of definition lists
I have a list of title/values. 我有一个标题/值列表。 I am thinking a definition list is the way to go.
我认为定义列表是要走的路。 I want the title and definition to be on the same line, and I do not want the titles to have the same width of each other, but for each to have it's width based on the amount of text in the title.
我希望标题和定义在同一行上,并且我不希望标题之间具有相同的宽度,但是每个标题都具有基于标题中文本量的宽度。 I also want the definitions to stay within their blocks, and not to bleed under the title.
我也希望定义保留在它们的范围内,不要在标题下流血。 Lastly, I want it to work with IE7 and greater.
最后,我希望它能与IE7及更高版本一起使用。
Okay, I come up with the following HTML/CSS, and it almost works. 好的,我想出了以下HTML / CSS,它几乎可以正常工作。 I have a live example at http://jsfiddle.net/s45Kd/ since I couldn't figure out how to add CSS with the stackoverflow window (is it possible?).
我在http://jsfiddle.net/s45Kd/上有一个在线示例,因为我不知道如何使用stackoverflow窗口添加CSS(可能吗?)。 Two problems.
两个问题。
First, how do I force definitions to break even if they do not have any white-space in them (ie "email")? 首先,即使定义中没有空格(例如,“电子邮件”),我如何强行破坏它们?
Second, why do long definitions eventually bleed under the title (ie "some text")? 第二,为什么长定义最终在标题(即“某些文本”)下流失?
While I would appreciate a "just do this", I am more looking for why this happens so I better understand. 尽管我很乐意“做到这一点”,但我仍在寻找发生这种情况的原因,以便更好地理解。
Thank you 谢谢
<style type="text/css">
dl,dt,dd {padding:0;margin:0;}
dl {width:200px;border:1px dashed black;}
dt {float:left;font-weight:bolder; padding-right:5px; border:1px dashed red;}
dd {border:1px dashed blue;}
</style>
<dl>
<dt>First Name:</dt><dd>Bob</dd>
<dt>Last Name:</dt><dd>Johnson</dd>
<dt>Email:</dt><dd>bob.johnson@stackoverflow.com</dd>
<dt>Phone Number:</dt><dd>(555) 555-1212</dd>
<dt>Some Text:</dt><dd>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</dd>
<dt>Birthday</dt><dd>January 1st</dd>
</dl>
For the first, the word wrap can be solved by setting: 首先,可以通过设置以下方式来解决自动换行:
word-wrap: break-word;
For the second, the key is to set overflow: hidden;
第二,关键是设置
overflow: hidden;
on both the dt
and dd
elements, while still floating only the dt
. 在
dt
和dd
元素上,同时仍然仅浮动dt
。
Demo in this jsFiddle: http://jsfiddle.net/fLPej/108/ 此jsFiddle中的演示: http : //jsfiddle.net/fLPej/108/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.