为什么CSS边距没有影响?

时间:2017-09-15 08:38:45

标签: css margin margins

旨在:段落和“链接按钮”之间的垂直间隙。

我似乎可以将我的链接按钮的边距更改为任何数字,但它似乎没有任何效果。 (我可以通过在我的'段落'样式中添加边距底部来解决这个问题,但我仍然不知道为什么我不明白为什么我的代码不能正常工作。)

有谁知道我在这里缺少什么?

 <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">  
    <style>
    .link {
        padding: 15px 30px;
        border: solid 2px black;
        margin-top: 600px; <!-- Why does this have no effect?-->
     }
     </style>
</head>


<body>
     <p>
​This is a paragraph text.
    </p>
    <a class="link" href="google.com">Google</a>
</body>

2 个答案:

答案 0 :(得分:0)

试试这个

CSS:

.link {
    padding: 15px 30px;
    border: solid 2px black;
    margin-top: 600px; 
    display:inline-block;
 }

答案 1 :(得分:0)

请在display:inline-block css

中添加.link

&#13;
&#13;
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">  
    <style>
    .link {
        padding: 15px 30px;
        border: solid 2px black;
        margin-top: 600px;
        display:inline-block;
     }
     </style>
</head>


<body>
     <p>
​This is a paragraph text.
    </p>
    <a class="link" href="google.com">Google</a>
</body>
&#13;
&#13;
&#13;

相关问题