[英]How do I get a hanging indent on a DD tag in CSS while also using content:before
We have this page with a bunch of definition lists.我们有这个页面有一堆定义列表。 The guy making style mockups in Word came up with this brilliant idea to render the definition lists as "term - value" and hanging indents.
在 Word 中制作样式模型的人想出了这个绝妙的主意,将定义列表呈现为“术语 - 值”并悬挂缩进。 I have to admit it actually is brilliant but it's difficult.
我不得不承认它确实很棒,但很难。 I've been playing around with this quite a bit and the hanging indents really are necessary or the page becomes very ugly.
我一直在玩这个很多,悬挂缩进真的是必要的,否则页面变得非常难看。
If I try to use grid (which is suboptimal anyway);如果我尝试使用网格(无论如何都是次优的); the page rendering breaks down because of content before.
页面渲染由于之前的内容而崩溃。 But it appears that the hanging indent style on
dd
just isn't honored.但似乎
dd
上的悬挂缩进样式不被尊重。
dl dd { display: inline; margin: 0; padding-top: .25em; } dl dd:after{ display: block; content: ''; } dl dt{ display: inline-block; padding-top: .25em; } dl dd:before { content: "- "; } dl dd{ text-indent: 3.5em hanging; }
<dl> <dt>term</dt> <dd>sentence sized definition belongs here</dd> <dt>term with long name</dt> <dd>sentence sized definition belongs here</dd> <dt>term</dt> <dd>paragraph sized definition paragraph sized definition paragraph sized definition paragraph sized definition I'm not going the really type it long but long enough to get hanging indent</dd> </dl>
I had actually tried the opposed margin
and text-indent
method of saying hanging indent before using the hanging keyword and it was glitchy;在使用hanging关键字之前,我实际上尝试过使用hanging indent的相反的
margin
和text-indent
方法,但它有问题; like the rendering believed I was trying to do something else.就像渲染相信我正在尝试做其他事情一样。
dl dd { display: inline; margin: 0; padding-top: .25em; } dl dd:after{ display: block; content: ''; } dl dt{ display: inline-block; padding-top: .25em; } dl dd:before { content: "- "; } dl dd{ text-indent: -3.5em; margin-left: 3.5em; }
<dl> <dt>term</dt> <dd>sentence sized definition belongs here</dd> <dt>term with long name</dt> <dd>sentence sized definition belongs here</dd> <dt>term</dt> <dd>paragraph sized definition paragraph sized definition paragraph sized definition paragraph sized definition I'm not going the really type it long but long enough to get hanging indent</dd> </dl>
Your dd
elements are display: inline
— text-indent
won't work on those.您的
dd
元素是display: inline
— text-indent
不适用于这些元素。
Now that grouping terms and descriptions using div
s is allowed, doing that lets you use hanging indents quite straightforwardly by applying text-indent
to the div
s instead.现在允许使用
div
对术语和描述进行分组,这样做可以让您通过将text-indent
应用于div
来非常直接地使用悬挂缩进。 I strongly recommend not using the hanging
keyword right now as the few browsers that support it only do so with experimental features enabled.我强烈建议现在不要使用
hanging
关键字,因为支持它的少数浏览器只有在启用实验性功能的情况下才会这样做。 For now, use padding, and a negative text-indent
to simulate the hanging indent:现在,使用填充和负
text-indent
来模拟悬挂缩进:
dl dt, dl dd { display: inline; margin: 0; } dl dd::before { content: "- "; } dl div { text-indent: -3.5em; padding-top: .25em; padding-left: 3.5em; }
<dl> <div> <dt>term</dt> <dd>sentence sized definition belongs here</dd> </div> <div> <dt>term with long name</dt> <dd>sentence sized definition belongs here</dd> </div> <div> <dt>term</dt> <dd>paragraph sized definition paragraph sized definition paragraph sized definition paragraph sized definition I'm not going the really type it long but long enough to get hanging indent</dd> </div> </dl>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.