Home > Article > Web Front-end > Is CSS a an inline element?
a is an inline element. Inline elements are generally containers for content. The width and height are determined by the content and cannot be set. They can coexist peacefully with other elements on the same line. The a element is used to set hyperlinks and does not occupy a line alone. It can be displayed on the same line as other inline elements; and the width and height of the a element depend on the content. The height and width attributes do not work, and the margin-top attribute does not work. And margin-bottom doesn't work either.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
Inline elements are generally containers for content and do not have their own independent space. They exist attached to other block-level elements. Under normal circumstances, inline elements can only contain content or other inline elements. The width and height are determined by the content and cannot be set. They can coexist peacefully with other elements on the same line. Inline elements are suitable for displaying specific content.
Characteristics of inline elements:
1, and other elements are on the same line;
2, height, line height and top The bottom margin and bottom margin cannot be changed;
3. The width is the width of its text or picture and cannot be changed.
In general, inline elements are generally basic elements based on semantic level. They can only accommodate text or other inline elements and are usually included in block elements. Common inline elements Elements include "a, span, b, br", etc.
a will not occupy a line by itself, it will be on the same line as other elements
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>marquee</title> <style> a{ background-color: red; } </style> </head> <body> <a href="#">a标签</a> <a href="#">a标签</a><span>span标签</span> </body> </html>
a’s height, line height, top and bottom margins cannot be changed;
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>marquee</title> <style> a,p{ background-color: red; height: 100px; width: 100px; margin-top: 50px; margin-bottom: 50px; } </style> </head> <body> <a href="#">a标签</a> <a href="#">a标签</a><span>span标签</span> <p>p标签</p> <span>span标签</span> </body> </html>
a and p tag settings The same style is applied, but a is an inline element, and the height, width, margin-top, and margin-bottom attributes cannot work; while p is a block element, these attributes can work.
(Learning video sharing: Getting started with web front-end)
The above is the detailed content of Is CSS a an inline element?. For more information, please follow other related articles on the PHP Chinese website!