I am trying to create a list of definitions (using this guide ) with its dt and dd elements having different contents. Of course, I could hardcode the width for these elements, but I would like the list to occupy the longest dt element and make my siblings have a length. In addition, when the content of the dd element is larger than the available space, a new line should not start below the dt element, but rather, where the dd element begins, as in the second screenshot in this question .
I thought I could solve this with the display: flex attribute, but was stuck with a non-working solution. Is it impossible or am I mistaken?
Here is what I still have (violin) :
HTML:
<dl> <dt>dt: Lorem Ipsum</dt> <dd>dd: Lorem imperdiet</dd> <dt>dt: Lorem id libero in Ipsum and so on and so on</dt> <dd>dd: Lorem id libero in ipsum dolor</dd> <dt>dt: Lorem Ipsum</dt> <dd>dd: I should be sitting to the right of the previous dt and not wrapping round below it.</dd> <dt>dt: Lorem id libero in Ipsum</dt> <dd>dd: Lorem in ipsum dolor</dd> </dl>
CSS
dl { display: flex; flex-flow: column nowrap; } dt { background: gold; display: flex; flex-flow: row wrap; } dd { background: yellowgreen; display: flex; flex-flow: row wrap; width: auto; margin: 0; padding: 0; }
html css flexbox
user1014412
source share