Home > Article > Web Front-end > Can You Set Dimensions on Anchor Tags for Background Images?
Setting Dimensions on Anchor Tags for Background Images
Is it possible to set specific dimensions (width and height) on anchor tags while incorporating a background image? This scenario allows for a text element within the anchor to be maintained while retaining the background image.
Solution:
To accomplish this, the anchor element must be assigned a display property of either block or inline-block. By doing so, it becomes capable of accepting both width and height values.
Example:
<code class="css">li { display: inline-block; width: 32px; height: 32px; background-color: orange; } li a { width: 32px; height: 32px; background-color: red; }</code>
<code class="html"><li><a href="#">Something</a></li></code>
In this example, the anchor tag within the li element is set to display as an inline-block and assigned a width and height of 32 pixels. It also has a background color of red, while the background color of the li element is orange. The text "Something" remains visible within the anchor tag, as desired.
The above is the detailed content of Can You Set Dimensions on Anchor Tags for Background Images?. For more information, please follow other related articles on the PHP Chinese website!