-1

Here is an example:

enter image description here

I would like for the width of the h1 or a surrounding div to "clip" the text so that I can, for example, draw a border around only the text.

James Shapiro
  • 4,805
  • 3
  • 31
  • 46

2 Answers2

1

Just make the header element an inline element by giving it a display attribute of inline or inline-block:

h1 {
  border: 3px dotted black;
  display: inline-block;
}
<h1>Title</h1>

Alternatively, you can make the surrounding element have width: fit-content, though note that this is not supported in Internet Explorer:

.container {
  width: fit-content;
}

h1 {
  border: 3px dotted black;
}
<div class="container">
  <h1>Title</h1>
</div>
Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
1

Just set the element style to display:inline or display:inline-block

.index-header {
    display: inline
}
Mikael Dalholm
  • 121
  • 1
  • 8