Home  >  Article  >  Web Front-end  >  How to remove spaces in html

How to remove spaces in html

藏色散人
藏色散人Original
2021-04-12 10:21:544197browse

How to remove spaces in html: First open the corresponding HTML code file; then set the "font-size:0;" style on the parent element to remove the spaces caused by line breaks between html code tags.

How to remove spaces in html

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.

How to remove the spaces caused by line breaks between HTML code tags

When using inline-block, the spaces between HTML elements will be displayed on the page. In order to maintain the beauty of the code, it is not recommended. Use all on one line or use methods that affect aesthetics.

Recommended method: Set font-size on the parent element: 0;


Example:

<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        body {            margin: 0;            padding: 0;        }
        p {            height: 41px;            border-top: 4px solid red;            border-bottom: 1px solid gray;        }
        a {            display: inline-block;            height: 41px;            text-align: center;            line-height: 41px;            text-decoration: none;            padding: 0px 5px;            background-color: red;            font-size: 14px;            font-family: 楷体;        }
        .shouye {            margin-left: 200px;        }
        .shouye:hover {            background-color: gray;        }
    </style></head><body>
    <p>
        <a class="shouye" href="#">设为首页</a>
        <a href="#">手机新浪网</a>
        <a href="#">移动客户端</a>
    </p></body></html>

Effect preview:
How to remove spaces in html


##Modified code:

<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        body {            margin: 0;            padding: 0;        }
        p {            font-size: 0;/*关键代码*/
            height: 41px;            border-top: 4px solid red;            border-bottom: 1px solid gray;        }
        a {            display: inline-block;            height: 41px;            text-align: center;            line-height: 41px;            text-decoration: none;            padding: 0px 5px;            background-color: red;            font-size: 14px;            font-family: 楷体;        }
        .shouye {            margin-left: 200px;        }
        .shouye:hover {            background-color: gray;        }
    </style></head><body>
    <p>
        <a class="shouye" href="#">设为首页</a>
        <a href="#">手机新浪网</a>
        <a href="#">移动客户端</a>
    </p></body></html>

Effect preview:


How to remove spaces in html

【Recommended learning:

HTML video tutorial

The above is the detailed content of How to remove spaces in html. 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