Home >Web Front-end >CSS Tutorial >Why can't the width be set in css a?

Why can't the width be set in css a?

藏色散人
藏色散人Original
2020-11-23 11:45:022949browse

css a cannot set the width because the a tag is an inline element and the width cannot be set. The solution is to convert the inline element to block or [inline-block] to set the width.

Why can't the width be set in css a?

Recommendation: "css video tutorial"

The operating environment of this tutorial: windows10 system, css3 version , this method is suitable for all brands of computers.

Why can’t the width of a tag be set?

Nothing happens when I use css to set the width of the a tag. Why?

Because the width and height cannot be set for inline elements, and the a tag is also an inline element, the width cannot be set. If you want to set the width, you must convert the inline element to block or inline-block,

If you convert it to a block, the element will occupy one line, which may change your layout.

If you want to keep the elements on the same page, you can set the inline block inline-block. After setting it to an inline block, it may It will appear that the element and adjacent elements are not on the same horizontal line. The solution is to set vertical-align: middle; or vertical-align: top. You can also try other attributes.

Because the width and height cannot be set for inline elements, and the a tag is also an inline element, the width cannot be set. If you want to set the width, you must convert the inline element to block or inline-block,

If you convert it to a block, the element will occupy one line, which may change your layout.

If you want to keep the elements on the same page, you can set the inline block inline-block. After setting it to an inline block, it may It will appear that the element and adjacent elements are not on the same horizontal line. The solution is to set vertical-align: middle; or vertical-align: top. You can also try other attributes.

Common block-level elements: div, p, form, ul, li, ol, dl, form, address, fieldset, hr, menu, table

Common inline elements: span, strong, em, br, img, input, label, select, textarea, cite, a

The above is the detailed content of Why can't the width be set in css a?. 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