2

I have a text over many lines. Example:

CSS: wrap text on many lines

Can the text be adapted to the div?

In this example, after the word "text" there is a space with color blue. In CSS there is a method to avoid the blue space after the word "text"?

If I have several texts with different lengths, is there a way to generalize this behavior?

.box {
  border: 1px solid red;
  width: 200px;
  position: relative;
  padding-top: 40px;
}

.label {
  position: absolute;
  top: -10px;
  background-color: blue;
}
<h1>My First Heading</h1>

<div class="box">
  I'm a box.
  <div class="label">
    I'm a label without a text wrapped.
  </div>
</div>
ocram88
  • 349
  • 1
  • 3
  • 7

2 Answers2

1

To avoid space after text and align it property to both side, use text-align css property.

View on Codepen

.box {
  border: 1px solid red;
  width: 200px;
  position: relative;
  padding-top: 40px;
}
.label {
  position: absolute;
  top: -10px;
  background-color: blue;
  text-align: justify;
}
<h1>My First Heading</h1>

<div class="box">
    I'm a box.
    <div class="label">
        I'm a label without a text wrapped.
    </div>
</div>
cursorrux
  • 1,382
  • 4
  • 9
  • 20
0

you could use a margin-right: <unit of measument>; in order to remove the excess blue though this would not be very responsive if the size of that box is going to change.

AlignSD
  • 21
  • 1
  • 7