使文本始终位于框的右上方

时间:2018-09-14 07:44:44

标签: html css

目标:
文字“ test”应始终位于该框的右上方

问题:
为了实现目标,我缺少什么代码?

信息:
*无论id =“ length”大小如何

谢谢!

#length
{
  width: 200px;
  background-color: lightblue;
}


#asdf {
    position: relative;
    top: 5px;
    left: 50px;
    width: 40px;
    height: 10px;
    border: 1px solid #73AD21;
}
  <div id="length">
    
    <div id="asdf">
      test
    </div>
    aa<br/>
    bb<br/>
    cc<br/>
    dd<br/>
    ee<br/>
    ff<br/>
    <br/>

  </div>

1 个答案:

答案 0 :(得分:1)

您的父元素应该是相对的,因此它成为嵌套在其中的任何绝对定位元素的新容器。删除#asdf的高度和宽度,使其大小与其内容相同。

#length
{
  width: 200px;
  background-color: lightblue;
  position: relative
}

#asdf {
    position: absolute;
    top: 5px;
    right: 5px;
    border: 1px solid #73AD21;
}
相关问题