In CSS, you can use the display attribute to eliminate the style of the label occupying a separate line. When the value of this attribute is "inline", the label will be set to be displayed as an inline element. At this time, there will be no line breaks before and after the label, and It will not occupy a line; the specific syntax is "label element object {display:inline;}".
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
How to eliminate the style of tags occupying a separate line in css
The reason why tags occupy a separate line is because some tags are block-level elements. A block-level element occupies the entire horizontal space of its parent element (container) and the vertical space equal to the height of its content, thus creating a "block". If you want to prevent the label from occupying its own line, you only need to set the label as an inline element and remove the line breaks before and after the element.
At this time, you need to use the display attribute. You only need to set the display attribute value of the label to inline, which means that this element will be displayed as an inline element, and there will be no line breaks before and after the element. This will eliminate the effect of the label occupying a single line.
The example is as follows:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <h3 class="h">测试标签</h3> 测试文字 </body> </html>
Output result:
After adding styles to the tag:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <style type="text/css"> .h{ display:inline; } </style> <body> <h3 class="h">测试标签</h3> 测试文字 </body> </html>
Output result:
(Learning video sharing: css video tutorial)
The above is the detailed content of How to eliminate the style of tags occupying a line by themselves in css. For more information, please follow other related articles on the PHP Chinese website!