【问题标题】:How to position text to be on the top edge of its container div?如何将文本定位在其容器 div 的顶部边缘?
【发布时间】:2021-12-11 03:29:14
【问题描述】:

这里是我想要实现的 Lorem ipsum 文本。

我尝试将容器 div 设置为相对位置,将文本容器设置为绝对位置并使用 top: 负值移动它,但它似乎没有做我想要的。

【问题讨论】:

  • 请添加一些代码。
  • 最简单的方法是使用负上边距。

标签: css sass less


【解决方案1】:

.container {
    border: 1px solid black;
    padding: 20px;
    width: 200px;   
}
h3 {
    padding: 0;
    margin-top: -30px;
}
<div class="container">
    <h3>Lorem Ipsum</h3>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-21
    • 1970-01-01
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-15
    相关资源
    最近更新 更多