Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove line breaks without making spans blocks

Tags:

css

Is there any CSS property/solution to prevent the need of a <br> between every <span>?

For example, instead of having:

  HTML
<span>a</span>
<br>
<span>b</span>
<br>
<span>c</span>

Have something like this:

  CSS
span{break-line:true}

  HTML
<span>a</span>
<span>b</span>
<span>c</span>

I know I can use display:block but I don't want to change the span's size.
One example to why that would be bad is color the background of the span.

like image 204
Math Avatar asked Mar 23 '26 20:03

Math


2 Answers

You can use float and clear on them:

span {
float: left;
clear: both;
background: #ddd;
}
<span>a</span>
<span>b</span>
<span>c</span>
like image 140
Johannes Avatar answered Mar 26 '26 09:03

Johannes


You can use the :after pseudo-element with white-space: pre;

span:after {
  content: '\A'; /* a newline */
}
span {
  white-space: pre;
}
<span>a</span>
<span>b</span>
<span>c</span>
like image 34
j08691 Avatar answered Mar 26 '26 08:03

j08691