HTML5 中没有绝对值的图标重叠
Overlap of icons without absolute in HTML5
我有以下代码片段来呈现一个与另一个重叠的图标。整个div就是一个link。目前我正在使用 position:absolute 并调整重叠。没有绝对位置怎么办。我还希望整个 div 位于屏幕右侧(目前位于左侧)。
.btn-circle {
position: absolute;
top: 4px;
left: 25px;
width: 30px;
height: 30px;
line-height: 30px;
background: red;
border-radius: 50%;l
}
.count {
position: absolute;
top:8px;
left:38px;
font-size:16px;
font-weight: bold;
color:white;
}
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<div class="">
<a href="#">
<i class="fa fa-inbox fa-2x"></i>
<span id="red-circle" class="btn btn-circle"></span>
<span id="toDosCount" class="count">9</span>
</a>
</div>
要么你需要正确定位它,要么减小字体大小:
片段
.btn-circle {
position: absolute;
top: -15px;
right: 0;
width: 15px;
height: 15px;
line-height: 15px;
background: red;
border-radius: 50%;
}
div a {position: relative;}
.count {
position: absolute;
top: -15px;
right: 5px;
font-size: 10px;
font-weight: bold;
color: white;
text-align: center;
}
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<div class="">
<a href="#">
<i class="fa fa-inbox fa-2x"></i>
<span id="red-circle" class="btn btn-circle"></span>
<span id="toDosCount" class="count">9</span>
</a>
</div>
这对你有用吗?
如果您使包含的 div 具有 position: relative
,您仍然可以在 float: right
旁边使用绝对定位
这使得内部 span 的绝对位置相对于 div 而不是页面。
对顶部和 right/left 值进行了一些调整,并且:
.btn-circle {
position: absolute;
top: -4px;
right: -4px;
width: 20px;
height: 20px;
background: red;
border-radius: 50%;
}
.count {
position: absolute;
top: -4px;
right: -1px;
font-size:16px;
font-weight: bold;
color:white;
padding: 2px;
}
.wrapper {
float: right;
position: relative;
margin-right: 100px;
}
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<div class="wrapper">
<a href="#">
<i class="fa fa-inbox fa-2x"></i>
<span id="red-circle" class="btn btn-circle"></span>
<span id="toDosCount" class="count">9</span>
</a>
</div>
我也将整个内容向左微移了一点,这样它就不会被 FULL PAGE 片段遮挡
我有以下代码片段来呈现一个与另一个重叠的图标。整个div就是一个link。目前我正在使用 position:absolute 并调整重叠。没有绝对位置怎么办。我还希望整个 div 位于屏幕右侧(目前位于左侧)。
.btn-circle {
position: absolute;
top: 4px;
left: 25px;
width: 30px;
height: 30px;
line-height: 30px;
background: red;
border-radius: 50%;l
}
.count {
position: absolute;
top:8px;
left:38px;
font-size:16px;
font-weight: bold;
color:white;
}
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<div class="">
<a href="#">
<i class="fa fa-inbox fa-2x"></i>
<span id="red-circle" class="btn btn-circle"></span>
<span id="toDosCount" class="count">9</span>
</a>
</div>
要么你需要正确定位它,要么减小字体大小:
片段
.btn-circle {
position: absolute;
top: -15px;
right: 0;
width: 15px;
height: 15px;
line-height: 15px;
background: red;
border-radius: 50%;
}
div a {position: relative;}
.count {
position: absolute;
top: -15px;
right: 5px;
font-size: 10px;
font-weight: bold;
color: white;
text-align: center;
}
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<div class="">
<a href="#">
<i class="fa fa-inbox fa-2x"></i>
<span id="red-circle" class="btn btn-circle"></span>
<span id="toDosCount" class="count">9</span>
</a>
</div>
这对你有用吗?
如果您使包含的 div 具有 position: relative
float: right
旁边使用绝对定位
这使得内部 span 的绝对位置相对于 div 而不是页面。
对顶部和 right/left 值进行了一些调整,并且:
.btn-circle {
position: absolute;
top: -4px;
right: -4px;
width: 20px;
height: 20px;
background: red;
border-radius: 50%;
}
.count {
position: absolute;
top: -4px;
right: -1px;
font-size:16px;
font-weight: bold;
color:white;
padding: 2px;
}
.wrapper {
float: right;
position: relative;
margin-right: 100px;
}
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<div class="wrapper">
<a href="#">
<i class="fa fa-inbox fa-2x"></i>
<span id="red-circle" class="btn btn-circle"></span>
<span id="toDosCount" class="count">9</span>
</a>
</div>
我也将整个内容向左微移了一点,这样它就不会被 FULL PAGE 片段遮挡