0

アイコンを別のアイコンと重ねてレンダリングする次のスニペットがあります。div 全体がリンクです。現在、私は 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>

4

2 に答える 2

1

float: right含まれている divにposition: relative

これにより、内部スパンの絶対位置が、ページではなく div に対して相対的になります。

上と右/左の値を微調整し、次のことを行います。

.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 によって不明瞭にならないように、全体を少し左に動かしました。

于 2015-08-12T15:09:45.360 に答える
0

正しく配置するか、フォント サイズを小さくする必要があります。

スニペット

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

これはうまくいきますか?

于 2015-08-12T14:58:20.263 に答える