简体   繁体   English

"具有多个 dd 元素到 1 个 dt 元素的内联定义列表"

[英]Inline definition list with multiple dd elements to 1 dt element

Done some Googling and Stackoverflowing on this subject, but I haven't found quite what I'm looking for.在这个主题上做了一些谷歌搜索和 Stackoverflowing,但我还没有找到我想要的东西。 I'm looking to use CSS to style a definition list that has multiple dd elements in an inline style.我正在寻找使用 CSS 来设置具有内联样式中的多个 dd 元素的定义列表的样式。 What I mean is I need this:我的意思是我需要这个:

DT first definition term:         DD term 1-1 // DD term 1-2 // DD term 1-3
DT second definition term:        DD term 2-1
DT third definition term:         DD term 3-1 // DD term 3-2 // DD term 3-3 // DD term 3-4 // DD
                                  term 3-5
.
.
DT twenty-first definition term:  DD term 21-1 // DD term 21-2

Make <dd> inline-block and <dt> element inline.使<dd>内联块和<dt>元素内联。 By default they are block element.默认情况下,它们是块元素。 Now insert line breaks via pseudo element on <dt>现在通过<dt>上的伪元素插入换行符

 dt { display: inline; margin-right:20px; } dt::before { content: "\\A"; white-space: pre; } dd { display: inline; margin:0; }
 <dl> <dt>Buy from author::</dt> <dd>Black hot drink</dd> <dd>//White cold drink</dd> <dd>//White cold drink</dd> <dd>//Black hot drink</dd> <dd>//White cold drink</dd> <dd>//White cold drink</dd> <dd>//Black hot drink</dd> <dt>Milk:</dt> <dd>White cold drink</dd> <dt>Coffee:</dt> <dd>Black hot drink</dd> <dd>//White cold drink</dd> <dd>//White cold drink</dd> <dt>Milk:</dt> <dd>White cold drink</dd> <dd>//White cold drink</dd> </dl>

you can make use of blocks instead of line-breaks using a variation on the original answer.您可以使用原始答案的变体来使用块而不是换行符。

 dl, dt, dd { margin: 0; padding: 0; } dt, dd { display: inline; } dt { font-weight: bold; } dt::before { content: ''; display: block; }<\/code><\/pre>
 <dl> <dt>English<\/dt> <dd>coffee<\/dd> <dt>Dutch<\/dt> <dd>koffie<\/dd> <dt>Ottoman Turkish<\/dt> <dd>قهوه (kahve)<\/dd> <dt>Arabic<\/dt> <dd>قَهْوَة (qahwah)<\/dd> <dd>قَهِيَ (qahiya) [to lack hunger]<\/dd> <\/dl><\/code><\/pre>

If you desire a layout with terms and definitions aligned in two columns, display: grid;<\/code>如果您需要在两列中对齐术语和定义的布局,请display: grid;<\/code> seems like the best option, as some comments have suggested.正如一些评论所建议的那样,似乎是最好的选择。 There are a lot of great resources for css grid on MDN<\/a> and Grid By Example<\/a> . MDN<\/a>和Grid By Example<\/a>上有很多很棒的 CSS 网格资源。 It's an extremely versatile layout!这是一个非常通用的布局!

"

The strucure described sounds alot like a row oriented table with the first column as the header and the rest of the columns are at amounts on each row.所描述的结构听起来很像一个面向行的表格,第一列作为标题,其余列在每一行的数量。

The DL<\/code> is the table................................................................................. display: table<\/code> DL<\/code>是表...................................................... ..................... display: table<\/code>
Then a DIV<\/code>然后是一个DIV<\/code><\/em><\/sup> is a row:...................................................................... display: table-row<\/code><\/em>是一行:.................................................. ............. display: table-row<\/code><\/em>
<\/em> Finally, DT<\/code> abd DD<\/code> are cells....................................................... display: table-cell<\/code><\/em>最后, DT<\/code> abd DD<\/code>是细胞...................................... ...... display: table-cell<\/code><\/em>
<\/sup><\/em> div<\/code> ***IS VALID<\/strong><\/em> div<\/code> ***有效<\/strong><\/em>

 :root { font: 1ch\/1.5 'Segoe UI' } body { font-size: 1.5rem } dl { display: table } div { display: table-row } dt, dd { display: table-cell; } dt { color: red } . table { border-color: #930 } dt { color: tomato }<\/code><\/pre>
 <DL> <DIV> <DT>DEFINITION TERM<\/DT> <DD>DEFINITION DESCRIPTION<\/DD> <DD>DEFINITION DESCRIPTION<\/DD> <DD>DEFINITION DESCRIPTION<\/DD> <\/DIV> <DIV> <DT>DEFINITION TERM<\/DT> <DD>DEFINITION DESCRIPTION<\/DD> <DD>DEFINITION DESCRIPTION<\/DD> <DD>DEFINITION DESCRIPTION<\/DD> <\/DIV> <DIV> <DT>DEFINITION TERM<\/DT> <DD>DEFINITION DESCRIPTION<\/DD> <DD>DEFINITION DESCRIPTION<\/DD> <DD>DEFINITION DESCRIPTION<\/DD> <\/DIV><\/code><\/pre>

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM