00 Votes

CSS: span with a fixed width

Question by Guest | 2012-08-02 at 23:41

I would like to give a <span></span> element a fixed width. However, every browser seems to ignore the assignment. What can I do?

ReplyPositiveNegative
-1Best Answer1 Vote

The <span> element is an inline element, so you can not assign a fixed width to the element as long as it remains an inline element.

You have to set the <span> element to display:block, so that it becomes a block element and only then, it is sensitive to width specifications.

However, with this, several span elements will be displayed below each other (probably you do not want that). To prevent this, you can still float the element with float:left, so it slides to the left.
2012-08-04 at 13:31

ReplyPositive Negative
Reply

Related Topics

The Secure Password

Info | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.