DaF-Student DaF-Student - 17 days ago 7
CSS Question

how to put margin between p and h1 tag?

I have call to action bar, inside it there is a h1 tag for slogan and a p tag with a link for actual call to action. I can not marging them properly h1 tag ride on p tag.

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

Answer

You can use position: absolute; right: 0; top: 50%; to put the button on the right side 50% from the top, then transform: translateY(-50%) to move the button up half of it's own width to center it vertically. Then apply padding-right: 130px to the parent to make room for the 120px wide button.

* {
  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%);
}
<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 -->