4

I found the solution how to break line on white space between words in this solution which is very helpful: Break line on white space between words

.test{
text-align:center;
}
h1{
word-spacing:9999px;
}

<div class="test">
<h1>split this</h1>
</div>

However, can do I change the font size in css after break the line??? example below: Example

Anie Hiles
  • 43
  • 3

2 Answers2

2

Yes you can, target the first line to make its size bigger:

.test {
  text-align: center;
  font-size:8px;
}
.test:first-line {
  font-size:40px;
}

h1 {
  word-spacing: 9999px;
}
<div class="test">
  <h1>split this</h1>
</div>

And here is another trick to create line break with word-spacing

.test {
  width:min-content;
  margin:auto;
  text-align: center;
  font-size:8px;
}
.test:first-line {
  font-size:40px;
}
<div class="test">
  <h1>split this</h1>
</div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
0

As suggested above. You can create span tags and use the pseudo class nth-child to stylise the desired span.

<div class="test">
  <span class="text">split</span>
  <span class="text">this</span>
</div>

.test {
  text-align: center;
}
.test .text {
  display: block;
  font-size: 1rem;
}
.test .text:nth-child(2) {
  font-size: 3rem
}
yellowskull
  • 167
  • 2
  • 12