2

I have a link with main title and description, and I would like to wrap the description line according to the width of the first line. Can I achieve that by using only CSS?

I have following code:

<a href="http://google.com">
  <span class="ht">Oficiální stránky</span>
  <span class="hb">Podívejte se na oficiální web festivalu</span>
</a>

https://jsfiddle.net/kybernaut/9uh24zns

Desired output:

enter image description here

Note: there will be more links in the line with different width of the first bold title.

Stickers
  • 75,527
  • 23
  • 147
  • 186
Karolína Vyskočilová
  • 1,305
  • 1
  • 18
  • 29

3 Answers3

4

Here's sneaky way of achieving this effect.

.limit {
   border: 1px solid red;
  display: table;
  width: 1%;
  
}

.ht {
  color: black;
  font-size: 24px;
  font-weight: bold;
  white-space: nowrap; /* stop text wrapping */
}

.hb {
  color: #555;
  font-size: 18px;
  display: block;
}
<a href="http://google.com" class="limit">
  <span class="ht">Oficiální stránky</span>
  <span class="hb">Podívejte se na oficiální web festivalu</span>
</a>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
2

You could try the CSS table + table-caption solution.

.container {
  display: table;
}
.hb {
  display: table-caption;
  caption-side: bottom;
}
<a class="container" href="#">
  <span class="ht">FIRST LINE</span>
  <span class="hb">second line some example content here</span>
</a>

jsFiddle

Stickers
  • 75,527
  • 23
  • 147
  • 186
-1

You may use

word-wrap property but None of the major browsers support the text-wrap property.

.ht {
  color: black;
  font-size: 24px;
  font-weight: bold;
  display: block;
}

.hb {
  color: #555;
  font-size: 18px
}
#wrapDiv{
  width: 190px;
  word-wrap: normal
}
<div id="wrapDiv">
  <a href="http://google.com">
  <span class="ht">Oficiální stránky</span>
  <span class="hb" >Podívejte se na oficiální web festivalu</span>
</a>
</div>

You can also refer, it's same as How to word wrap text in HTML?

Community
  • 1
  • 1
Kumar Ashutosh
  • 1,121
  • 10
  • 33