I am trying to style a definition list in HTML to resemble a table using th
and td
elements in two separate columns, while also having alternating row backgrounds. I have implemented the following CSS for this purpose:
dl {
font-family: Verdana, Geneva, sans-serif;
font-size: 0.6em;
overflow: hidden;
width: 200px;;
}
dl dt {
font-weight: bold;
float: left;
clear: left;
padding-right: 1%;
width: 48%;
}
dl dt:nth-of-type(odd),
dl dd:nth-of-type(odd) {
background-color: #EEE;
}
dl dt:nth-of-type(even),
dl dd:nth-of-type(even) {
background-color: #DDD;
}
dl dd {
float: left;
width: 50%;
padding-left: 1%;
margin-left: 0;
}
Below is the sample HTML code:
<dl>
<dt>Key 1</dt>
<dd>Value 1</dd>
<dt>Very very very long key 2</dt>
<dd>Value 2</dd>
<dt>Key 3</dt>
<dd>Value 3 with<br /> line breaks</dd>
<dt>Key 4</dt>
<dd>Value 4</dd>
</dl>
The issue I am facing is that, due to varying heights of the content, there are "holes" with no background color in the list:
Is there a solution to this problem?