如何在p和h1标签之间加上边距?

时间:2017-05-08 22:15:42

标签: html css

我打电话给行动栏,里面有一个标语为h1标签,另一个标签带有实际号召性用语的链接。我无法在p标签上正确地使用它们进行标记。

SCREENSHOT

HTML

<div id="call-to-act">
<h1>We are Andia, a super cool design agency.We design beautiful websites, logos and prints. Your project is safe with us.</h1>
<p><a href="#" class="call2act">Contact Us</a></p>

</div> <!-- end of call-to-action -->

CSS:

div#call-to-act {
    background: #fff;
    width: 100%;
    height: 100px;
    position: relative;
    margin: 50px auto;
    -webkit-box-shadow: inset 10px 10px 72px -28px rgba(0,0,0,0.75);
    -moz-box-shadow: inset 10px 10px 72px -28px rgba(0,0,0,0.75);
    box-shadow: inset 10px 10px 72px -28px rgba(0,0,0,0.75);
    width: 80%;
}
div#call-to-act p {
    height: 100%;
}


div#call-to-act a.call2act {
    text-indent:0;
    border:1px solid #dcdcdc;
    display:inline-block;
    color:#777777;
    font-family:arial;
    font-size:15px;
    font-weight:bold;
    font-style:normal;
    height:44px;
    line-height:44px;
    width:120px;
    text-decoration:none;
    text-align:center;
    text-shadow:1px 1px 0px #ffffff;
    position: absolute;
    right: 20px;
    top: 20px;  
}

1 个答案:

答案 0 :(得分:1)

您可以使用position: absolute; right: 0; top: 50%;将按钮放在右侧50%的顶部,然后transform: translateY(-50%)将按钮向上移动一半自己的宽度,使其垂直居中。然后将padding-right: 130px应用于父级,为120px宽按钮腾出空间。

&#13;
&#13;
* {
  margin: 0;
  padding: 0;
}

div#call-to-act {
  background: #fff;
  width: 100%;
  min-height: 46px;
  position: relative;
  margin: 50px auto;
  -webkit-box-shadow: inset 10px 10px 72px -28px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: inset 10px 10px 72px -28px rgba(0, 0, 0, 0.75);
  box-shadow: inset 10px 10px 72px -28px rgba(0, 0, 0, 0.75);
  width: 80%;
  box-sizing: border-box;
  padding-right: 130px;
}

div#call-to-act p {}

div#call-to-act a.call2act {
  text-indent: 0;
  border: 1px solid #dcdcdc;
  display: inline-block;
  color: #777777;
  font-family: arial;
  font-size: 15px;
  font-weight: bold;
  font-style: normal;
  height: 44px;
  line-height: 44px;
  width: 120px;
  text-decoration: none;
  text-align: center;
  text-shadow: 1px 1px 0px #ffffff;
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
}
&#13;
<div id="call-to-act">
  <h1>We are Andia, a super cool design agency.We design beautiful websites, logos and prints. Your project is safe with us.</h1>
  <p><a href="#" class="call2act">Contact Us</a></p>

</div>
<!-- end of call-to-action -->
&#13;
&#13;
&#13;