Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a span to look like a pre with CSS?

Tags:

html

css

People also ask

How do I style a span in CSS?

How to style text with the span tag. If you want to makes some particular text or any other content different from the rest, you can wrap it in a span tag, give it a class attribute, then select it with the attribute value for styling.

Can we apply CSS on span?

The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute. The <span> tag is much like the <div> element, but <div> is a block-level element and <span> is an inline element.

How do I edit span in HTML?

Use the textContent property to change the text of a span element, e.g. span. textContent = 'Replacement text' . The textContent property will set the text of the span to the provided string, replacing any of the existing content. Here is the HTML for the examples in this article.


Look at the W3C CSS2.1 Default Style Sheet or the CSS2.2 Working Draft. Copy all the settings for PRE and put them into your own class.

pre {
    display: block;
    unicode-bidi: embed;
    font-family: monospace;
    white-space: pre;
}

See the white-space CSS property.

.like-pre { white-space: pre; }

This makes a SPAN look like a PRE:

span {
  white-space: pre;
  font-family: monospace;
  display: block;
}

Remember to change the css selector as appropriate.


Specifically, the property you're looking at is:

white-space: pre

http://www.quirksmode.org/css/whitespace.html
http://www.w3.org/TR/CSS21/text.html#white-space-prop


Try this

span {
    white-space: pre;
    font-family: monospace;
    display: block;
    unicode-bidi: embed
}

while the accepted answer is indeed correct, if you want the text to wrap you should use:

white-space: pre-wrap;