3

I want to be able to select a "code" by double-clicking it. But when I do so, the whole definition is selected.

dt {
  float: left;
  clear: left; 
}
dd {
  float: left;
  font-family: monospace;
}
<dl>
  <dt>Code</dt>
  <dd>123456</dd>
  <dt>Code</dt>
  <dd>abcdef</dd>
</dl>

What can I do so that a double-click will select the contents of the dd only?

Oliver Salzburg
  • 21,652
  • 20
  • 93
  • 138

4 Answers4

7

This is a Chrome issue so to solve it you will need to add space before you close the html tag. So you have to do it like this.

<dl>
  <dt> Code </dt>
  <dd> 123456 </dd>
  <dt> Code </dt>
  <dd> abcdef </dd>
</dl>
E.Agolli
  • 552
  • 2
  • 11
2

Use a table instead of a styled description list that looks like a table

<table>
  <tr>
    <td>Code</td>
    <td>123456</td>  
  </tr>
  <tr>
    <td>Code</td>
    <td>abcdef</td>  
  </tr>
</table>
dnaranjo
  • 3,647
  • 3
  • 27
  • 41
  • A definition list is a semantically appropriate structure in many cases—notably in the case of 1:1 title/definitions. Tables are for tabular data, so this “solution” is not really helpful. – fantasticrice Jul 13 '18 at 15:58
2

You float left all your element, I thinks it make confusing for double click action known what element is selected. Remove "float:left" attribute on your <dd> element. float and clear

dt {
  float: left;
  clear: left; 
  margin-right: 10px;
}
dd {
  font-family: monospace;
}
<dl>
  <dt>Code</dt>
  <dd>123456</dd>
  <dt>Code</dt>
  <dd>abcdef</dd>
</dl>
-1

Don't need to modify the html. You can use css:

dl dd::before { content: '.'; display: block; height: 0; width: 0; visibility: hidden; }
dl dd::after { content: '.'; display: block; height: 0; width: 0; visibility: hidden; }
dl dt::before { content: '.'; display: block; height: 0; width: 0; visibility: hidden; }
dl dt::after { content: '.'; display: block; height: 0; width: 0; visibility: hidden; }
Tifu
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 15 '22 at 16:29