Home  >  Article  >  Web Front-end  >  How to Achieve Fixed Width in a Span Within an Unordered List without Modifying Padding or Tags?

How to Achieve Fixed Width in a Span Within an Unordered List without Modifying Padding or Tags?

Linda Hamilton
Linda HamiltonOriginal
2024-11-05 18:30:02859browse

How to Achieve Fixed Width in a Span Within an Unordered List without Modifying Padding or Tags?

Achieving Fixed Width in a Span within an Unordered List

When working with unordered lists, it can be desirable to align text after a fixed-width span. However, modifying the padding or adding/altering tags is not permissible. The following solution provides a means to achieve this goal without violating these restrictions:

Using CSS

An ideal approach would be to use the following CSS:

span {
  display: inline-block;
  width: 50px;
}

This solution is effective in all browsers aside from Firefox 2 and earlier iterations. For these legacy browsers, consider using the -moz-inline-box value instead. However, be mindful that it behaves differently from inline-block and may produce unexpected results in certain scenarios.

The above is the detailed content of How to Achieve Fixed Width in a Span Within an Unordered List without Modifying Padding or Tags?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn