简体   繁体   English

在顶部的Div内对齐跨度

[英]Align Span inside Div on top

I want to align the red sticker on right hand side top of the div block . 我想将div block右上方的红色标签对齐。 This is my progress http://jsfiddle.net/E2aWr/158/ 这是我的进度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;
}

Easy way. 简单的方法。

.block{
     position:absolute;
}

.red-sticker {
    font-family: Arial,sans-serif;
    position: absolute;
    right: -10px;
    top: -10px;
    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);
}

Here is the working example in jsfiddle 这是jsfiddle中的工作示例

Try adding this to your css: 尝试将其添加到您的CSS:

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

Try this can be help 试试这个可以帮助

 .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; } 
 <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> 

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

All you needed to do was to make the containing div with class "block" have relative positioning, as when you use absolute positioning it takes the element out of the flow of the document. 您需要做的就是使包含“ block”类的div具有相对定位,因为当您使用绝对定位时,它将使元素脱离文档流。

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

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

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

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