将Div内部的跨度对齐在顶部

时间:2015-11-02 13:46:17

标签: html css html5 css3

我想对齐div block右上方的红色标签。这是我的进步http://jsfiddle.net/E2aWr/158/

html

<div class="block">
<a href="#"><img src="http://www.balloontothemoon.com/images/Bubbles.jpg">
<span class="red-sticker">1<p>2</p></span>
</a>
</div>

css

.red-sticker {
font-family: Arial,sans-serif;
position: absolute;
right: 0px;
top: 0px;
display: block;
width: 32px;
height: 32px;
padding-top: 5px;
font-size: 12px;
line-height: 12px;
text-align: center;
float: left;
color: #FFF;
border-radius: 50%;
background-color: #A50200;
background-image: linear-gradient(to bottom, #CB0400, #A50200);
}
p:last-child {
 margin-bottom: 0px;
}

4 个答案:

答案 0 :(得分:2)

简单方法。

5555

这是jsfiddle中的working example

答案 1 :(得分:1)

尝试将此添加到您的css:

.block
{
    position: relative;
    float:left;
}

答案 2 :(得分:1)

试试这可以提供帮助

&#13;
&#13;
collectionview
&#13;
.block{position: relative;width: 284px;}
.red-sticker {
font-family: Arial,sans-serif;
position: absolute;
right: 0px;
top: 0px;
display: block;
width: 32px;
height: 32px;
padding-top: 5px;
font-size: 12px;
line-height: 12px;
text-align: center;
float: left;
color: #FFF;
border-radius: 50%;
background-color: #A50200;
background-image: linear-gradient(to bottom, #CB0400, #A50200);
}
p:last-child {
 margin-bottom: 0px;
}
&#13;
&#13;
&#13;

链接: http://jsfiddle.net/E2aWr/162/

答案 3 :(得分:1)

您需要做的就是使用类&#34;阻止&#34;具有相对定位,因为当您使用绝对定位时,它会将元素从文档流中取出。

.block {
   position: relative;
   width: 280px;
}

http://jsfiddle.net/E2aWr/158/