CSS 边距和填充

问题描述 投票:0回答:1

我尝试删除 CSS 代码中的填充和边距,但它不起作用。我不知道该怎么办,因为我三天前开始 CSS 编程,而且我已经观看了 CSS 课程。

我尝试使用 * 标签来接受所有代码的边距和填充,但它不起作用。

CSS代码:

* {
    margin: -0px;
    padding: 0px;
}

body {
    height: 2000px;
}

#side aside a {
    position:absolute;
    text-decoration: none;
    color: white;
    font-size: 16px;
    padding: 20px;
    background: grey;
    width: 10%;
    height: 3%;
}

#fir {
    top: 30px;
}

#sec {
    top: 90px;
}

#thi {
    top: 150px;
}

#for {
    top: 210px;
}

HTML代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TestServer</title>
    <link rel="stylesheet" href="main.css">
</head>
<body>
    <div id="side">
        <aside>
            <a href="" id="fir">Главная</a>
            <a href="" id="sec">О нас</a>
            <a href="mailto:[email protected]" id="thi">Наша почта</a>
            <a href="" id="for">Контакты</a>
        </aside>
    </div>

</body>
</html>
html css padding margin
1个回答
0
投票

用这个替换你的CSS:

* {
    margin: 0px;
}

body {
    height: 2000px;
}

#side aside a {
    display: flex;
    text-decoration: none;
    color: white;
    font-size: 16px;
    padding: 20px;
    background: grey;
    width: 10%;
    height: 3%;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TestServer</title>
    <link rel="stylesheet" href="main.css">
</head>
<body>
    <div id="side">
        <aside>
            <a href="" id="fir">Главная</a>
            <a href="" id="sec">О нас</a>
            <a href="mailto:[email protected]" id="thi">Наша почта</a>
            <a href="" id="for">Контакты</a>
        </aside>
    </div>

</body>
</html>

问题是你有“position:absolute;”应该设置为 flex。

© www.soinside.com 2019 - 2024. All rights reserved.