css 将文本放在div的顶部

bxgwgixi  于 2023-01-06  发布在  其他
关注(0)|答案(3)|浏览(138)

我试图把一个文本/标题放在一个div的顶部。我在图片中用红色表示,但是我做不到。
My image
我的代码:

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">

  <div class="row">

    <div class="col col-md-1">
      <img src="assets/icons/intercambiar.png" alt="intercambiar" />
    </div>
    <div class="col col-md-4 border border-white border-4" style="background-color: rgb(22, 111, 212); color: white;"> 01-15-12-03
    </div>
    <div class="col col-md-4 border border-white border-4" style="background-color: rgb(255, 255, 255); color: black;">

    </div>

  </div>

</div>

谢谢
我试过标签标签,但它滚动一切。

u0njafvf

u0njafvf1#

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row">
    <div class="col col-md-1">
      <img src="assets/icons/intercambiar.png" alt="intercambiar" />
    </div>
    <div class="col col-md-4">
      <label>text 1</label>
      <div class="border border-white border-4" style="background-color: rgb(22, 111, 212); color: white">
        01-15-12-03
      </div>
    </div>
    <div class="col col-md-4">
      <label>text 2</label>
      <div class="border border-white border-4" style="background-color: rgb(255, 255, 255); color: black">
        01-15-12-03
      </div>
    </div>
  </div>
</div>
11dmarpk

11dmarpk2#

在内容之前添加另一个行div并添加标签

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="row">
      <div class="col col-md-1"></div>
      <div class="col col-md-4">Label 1</div>
      <div class="col col-md-4">Label 2</div>
  </div>
  <div class="row">

    <div class="col col-md-1">
      <img src="assets/icons/intercambiar.png" alt="intercambiar" />
    </div>
    <div class="col col-md-4 border border-white border-4" style="background-color: rgb(22, 111, 212); color: white;"> 01-15-12-03
    </div>
    <div class="col col-md-4 border border-white border-4" style="background-color: rgb(255, 255, 255); color: black;">

    </div>

  </div>

</div>
cnh2zyt3

cnh2zyt33#

您可以使用CSS中的::before属性来完成此操作:

.div::before{
    content: "[YOUR TEXT]";
    top: -50px;
    left: 50px;
}

你必须调整顶部和左侧到你的div。

相关问题