text-align:在li标签内的span上

时间:2014-07-17 13:37:42

标签: html css text-align

我的结构如下:

<ul class="grupa-playerow">Blabla
    <li class="player-li">Layout1<span class="player-godziny">15.00-17.00</span></li>
    <li class="player-li">Layout2<span class="player-godziny">17.00-22.00</span></li>
    <li class="player-li">Layout3<span class="player-godziny">22.00-24.00</span></li>
</ul>

这就是风格:

.grupa-playerow {
position: relative;
width: 300px;
list-style-type: none;
padding: 7px 0 7px 0;
border-bottom: 1px solid #CDCDCD;
font-size: 11px;
cursor: pointer;
}


.player-li {
padding: 2px 0 2px 20px;
width: 100%;
text-align: left;
}

.player-godziny {
text-align: right !important;
color: #5ACFC9;
}

我希望.player-godziny跨越右边。为什么不起作用?

这是一个小提琴:http://jsfiddle.net/wL2SF/

3 个答案:

答案 0 :(得分:7)

尝试:

float: right;

而不是:

text-align: right;

<强> JSFiddle

如果您发现对齐问题,则可能是因为您的填充设置

答案 1 :(得分:3)

您需要添加float:right;

DEMO

<ul class="grupa-playerow">Blabla
    <li class="player-li">Layout1<span class="player-godziny">15.00-17.00</span></li>
    <li class="player-li">Layout2<span class="player-godziny">17.00-22.00</span></li>
    <li class="player-li">Layout3<span class="player-godziny">22.00-24.00</span></li>
</ul>

.grupa-playerow {
position: relative;
width: 300px;
list-style-type: none;
padding: 7px 0 7px 0;
border-bottom: 1px solid #CDCDCD;
font-size: 11px;
cursor: pointer;
}


.player-li {
padding: 2px 0 2px 20px;
width: 100%;
text-align: left;
}

.player-godziny {
text-align: right !important;
color: #5ACFC9;
  float:right;/*ADD*/
}

答案 2 :(得分:2)

尝试:

.player-godziny {
float: right;
color: #5ACFC9;
}