Home > Article > Web Front-end > Can Anchor Tags () Have Specific Width and Height in Pixels?
) Have Specific Width and Height in Pixels? " />
Question:
Can anchor tags () have specific width and height in pixels? How do we achieve this while preserving the text within the anchor?
Background:
Consider the following CSS code:
<code class="css">li { width: 32px; height: 32px; background-color: orange; } li a { width: 32px; height: 32px; background-color: red; }</code>
HTML:
<code class="html"><li><a href="#">Something</a></li></code>
Resolution:
To enable width and height customization for anchor tags, it's necessary to modify their display property:
<code class="css">li a { display: block; // or display: inline-block; width: 32px; height: 32px; background-color: red; }</code>
By setting display: block or display: inline-block, the anchor tag becomes an inline-level element that supports both width and height. This way, the anchor tag can retain its text content while also displaying a background image.
The above is the detailed content of Can Anchor Tags () Have Specific Width and Height in Pixels?. For more information, please follow other related articles on the PHP Chinese website!