I am facing a complex issue that requires attention. Let me explain the situation:
There is an unordered list consisting of list items displayed vertically with alternating background colors, all having the same width within a fixed-width div. Some list items have list item indicators while others do not. Each list item contains three floated <div>
s with text content. One needs to align left and the other two need to align right within the list item. The first and right-aligned <div>
require fixed widths to prevent overflow or content extending beyond the boundaries. The other two also need fixed widths due to minimal changes in content size.
Here's a simplified text example:
--------------------------------------
| • <Some Text> <text2><text3>|
| <Some more text>...<text2><text3>|
| <other text> <text2><text3>|
--------------------------------------
The CSS for the first item includes:
text-overflow: ellipsis; overflow: hidden; white-space: nowrap;
to manage overflow. A jQuery solution is used to handle scrolling when needed.
The challenge arises as floating elements in major browsers result in list items having no height, except for those with list indicators (list-style-type
). Adding a clearfix div at the end causes the content to be displayed below the list indicator:
--------------------------------------
| • |
| <Some Text> <text2><text3> |
--------------------------------------
The issue would be resolved if the first text did not require a fixed width (as the layout currently functions), but it is necessary here.
For demonstration purposes, the following HTML illustrates the problem:
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' lang='en' xml:lang='en'>
<head>
<title>HTML List Problem</title>
<style type="text/css">
#container { width: 420px; }
#container ul {
list-style-type: none;
margin: 0;
padding: 0 20px;
background: green;
}
.item { padding: 5px 0 4px 20px; }
.item-current {
list-style-type: square;
list-style-position: inside;
}
.item-even { background: yellow; }
.item-odd { background: orange; }
.text1 {
width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
float: left;
}
.text2, .text3 {
float: right;
width: 30px;
}
</style>
</head>
<body>
<div id="container">
<ul>
<li class="item item-current item-even">
<div class="text1 item-current">
Some Text
</div>
<div class="text2">
text2
</div>
<div class="text3">
text3
</div>
</li>
<li class="item item-odd">
<div class="text1">
Some Text
</div>
<div class="text2">
text2
</div>
<div class="text3">
text3
</div>
</li>
<li class="item item-even">
<div class="text1">
Some Text
</div>
<div class="text2">
text2
</div>
<div class="text3">
text3
</div>
</li>
<li class="item item-odd">
<div class="text1">
Some Text
</div>
<div class="text2">
text2
</div>
<div class="text3">
text3
</div>
</li>
</ul>
</div>
</body>
</html>