Home > Web Front-end > CSS Tutorial > Can You Set Dimensions on Anchor Tags for Background Images?

Can You Set Dimensions on Anchor Tags for Background Images?

Susan Sarandon
Release: 2024-10-30 17:53:31
Original
323 people have browsed it

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>
Copy after login
<code class="html"><li><a href="#">Something</a></li></code>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template