-1

I am trying to achieve this effect below:

enter image description here

How can I get this effect? I want the empty space to adjust to the text. Can anyone give me advice?

.box {
  border: 1px solid black;
  position: relative;
  min-height: 50px;
}

.box__title {
  position: absolute;
  bottom: 16px;
  left: 30px;
}
<div class="box">
<h2 class="box__title">Box title</h2>
</div>
Dave
  • 1
  • 1
  • 9
  • 38

2 Answers2

6

You can use the <fieldset> and <legend>tag.

<fieldset>
    <legend>Box Title</legend>

    <h1>More stuff here!</h1>
</fieldset>
SecretTimes
  • 331
  • 1
  • 15
1

Ya you can add a background color and some left and right padding to your box title

.box {
  border: 1px solid black;
  position: relative;
  min-height: 50px;
}

.box__title {
  position: absolute;
  bottom: 16px;
  left: 30px;
  background: #fff;
  padding: 0 5px;
}
<div class="box">
<h2 class="box__title">Box title</h2>
</div>
zgood
  • 12,181
  • 2
  • 25
  • 26
  • the thing is I will have a texture as a background color, so I cant add just white background. Possible to add "empty" background? – Dave Oct 11 '21 at 14:34
  • well then see if the answer from SecretTimes works for you – zgood Oct 11 '21 at 14:37