具有动态宽度的内联元素旁边的float元素

时间:2012-10-26 10:59:19

标签: html css css-float

如何在动态宽度

的内联元素旁边设置float元素

演示:http://jsfiddle.net/J2Df8/

HTML

<div>
<span>Lorem ipsum dolor</span>
<span class="floater"></span>
</div>

CSS

DIV{
    width: 100px;
}


SPAN.floater{
    height:4px;
    width:4px;
    margin-top:3px;
    float:left;
    background-color: #FF0000;
}

enter image description here

2 个答案:

答案 0 :(得分:1)

查看此http://jsfiddle.net/J2Df8/12/

HTML

<div>
    <span>Lorem ipsum dolor<span class="floater"></span></span>    
    <span>Lorem ipsum dolor<span class="floater"></span></span> 
</div>

CSS

div {
    width: 100px;
}

div span {
    display:inline-block;
    position:relative;
    padding-right:10px;
}


span.floater{
    display:block;
    padding:0;
    height:4px;
    width:4px;
    top:8px;
    right:0;
    position:absolute;
    background-color: #FF0000;
}

答案 1 :(得分:0)

HI现在已经习惯了你:after

就像这样

span{
    width: 100px;
    display:block;
}


span:after{
    content:'';
    height:4px;
    display:inline-block;
    width:4px;
    background-color: #FF0000;
}

Live demo