我在这里将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>
答案 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>