简体   繁体   English

带有左右图标的HTML

[英]HTML with icon on left and right side

I want to create an un-order list in html. 我想在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. 文字在2个图标中,应自动占据可用的屏幕宽度。 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. 更新:我需要分隔标签上的图标,例如divimg预先感谢。

Just combine some CSS tricks: 只需结合一些CSS技巧:

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 . 样品提琴

You can use floats: Demo 1 可以使用浮点数: 演示1

And you can use position absolute: Demo 2 您可以使用绝对位置: 演示2

Ignore if it's not what you are after. 忽略是否​​不是您追求的目标。

you can take advantage of calc 你可以利用calc

maybe something like this. 也许像这样。

Sample Fiddle 样品小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM