gpt4 book ai didi

html - 如何在 p 和 h1 标签之间放置边距?

转载 作者:太空宇宙 更新时间:2023-11-04 08:44:48 24 4
gpt4 key购买 nike

我有号召性用语栏,里面有一个标语的 h1 标签和一个带有实际号召性用语链接的 p 标签。我不能在 p 标签上正确地保证它们的 h1 标签。

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

最佳答案

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

* {
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 -->

关于html - 如何在 p 和 h1 标签之间放置边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43858096/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com