1

I want to create an un-order list in html. Each of list item, there will be an icon on left side and an icon on right side. The text is among 2 icons and should auto occupy available screen width. In the case of long text, it will be ellipsis. The list item should like this:

++++++ ++++++++++++++++++++++++++ ++++++
+icon+ + short text             + +icon+
++++++ ++++++++++++++++++++++++++ ++++++

++++++ ++++++++++++++++++++++++++ ++++++
+icon+ + long text long text ...+ +icon+
++++++ ++++++++++++++++++++++++++ ++++++

++++++ ++++++++++++++++++++++++++ ++++++
+icon+ + short text             + +icon+
++++++ ++++++++++++++++++++++++++ ++++++

I tried many ways to create the list but didn't success. Please help! Any solution or recommends are welcome.

UPDATE: I need the icons on separated tags, such as div or img Thanks in advance.

Nguyen Minh Binh
  • 23,891
  • 30
  • 115
  • 165

3 Answers3

2

Just combine some CSS tricks:

ul {
    margin:0;
    padding:0;
}
li {
    background:url(http://www.caloriedagboek.nl/_lib/img/icons/icon_help.gif) right center no-repeat;
    margin:0;
    overflow:hidden;
    padding:0 24px 0 0;
    text-overflow:ellipsis;
    white-space:nowrap;
}
li:before {
    content:url(http://www.caloriedagboek.nl/_lib/img/icons/icon_help.gif);
    margin:0 0.5em;
}

Sample fiddle.

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
  • Great help. But there is any way to separate the icons into independent tags? such as `img` – Nguyen Minh Binh May 04 '13 at 10:18
  • As discussed below - you could for the first icon (just move it inline and remove the `:before` declaration). For the second one it's not possible since the ellipsis would cut it off. You could however simply do it from HTML by setting `style="background-image:url(...)"` on the `
  • ` element for the second icon. There are more complex solutions that would allow putting both in `` tags, those would severely complicate matters and require positioning hacks though.
  • – Niels Keurentjes May 04 '13 at 10:25
  • This means that we can add separated `img` at right side if the text isn't ellipsis any more? – Nguyen Minh Binh May 04 '13 at 10:34