Home > Web Front-end > CSS Tutorial > How to eliminate the style of tags occupying a line by themselves in css

How to eliminate the style of tags occupying a line by themselves in css

WBOY
Release: 2021-11-24 17:35:54
Original
4590 people have browsed it

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;}".

How to eliminate the style of tags occupying a line by themselves in css

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>
Copy after login

Output result:

How to eliminate the style of tags occupying a line by themselves in css

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>
Copy after login

Output result:

How to eliminate the style of tags occupying a line by themselves in css

(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!

Related labels:
css
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template