在div c右上角的位置关闭课程?

时间:2016-03-04 13:18:22

标签: css

我在这里将div close放在div c的右上角有一个问题。对此最好的方法是什么? Fiddle

.c{
  width:300px;
  height:100px;
  border:1px solid #000;
  margin:5px;
}

.close{
  position:absolute;
  top: 5px;
  right: 5px;
  font-size:12px;
  font-weight:bold;
  color:#000;
}
<div class=c>some text<span class=close>x</span></div>
<div class=c>some text<span class=close>x</span></div>
<div class=c>some text<span class=close>x</span></div>
<div class=c>some text<span class=close>x</span></div>

1 个答案:

答案 0 :(得分:2)

position: relative添加到.c

.c {
  width:300px;
  height:100px;
  border:1px solid #000;
  margin:5px;
  position: relative;
}

.close {
  position:absolute;
  top: 5px;
  right: 5px;
  font-size:12px;
  font-weight:bold;
  color:#000;
}
<div class="c">some text<span class="close">x</span></div>
<div class="c">some text<span class="close">x</span></div>
<div class="c">some text<span class="close">x</span></div>
<div class="c">some text<span class="close">x</span></div>