我想在两个hr
之间获取div
代码。
我已将hr
标记放在第一个div
下方和第二个上方。我将div
和hr
标记设置为display
为inline
,希望这是一个序列并一个接一个地显示。我的问题是hr
标记从最顶部开始,并停在其他div
的位置。
我附上了一个小提琴来展示我得到的东西:
https://jsfiddle.net/31ytnun2/
.contactpagelower {
margin-top: 40px;
}
.spancenter {
text-align: center;
}
.contactpagecommunityContainer {
float: left;
width: 50%;
margin-top: 30px;
display: inline;
}
.contactpagecommunity {
float: right;
margin-right: 37%;
background-color: #12BDB8;
color: #FFFFFF;
font-size: 16px;
padding: 15px;
}
.contactpagecommunity a:link {
background-color: #12BDB8;
color: #FFFFFF;
outline: none;
text-decoration: none;
}
.contactpagecommunity a:visited {
background-color: #12BDB8;
color: #FFFFFF;
outline: none;
}
.contactpagesellwithusContainer {
float: right;
width: 50%;
margin-top: 30px;
display: inline;
}
.contactpagesellwithus {
float: left;
margin-left: 35%;
background-color: #12BDB8;
color: #FFFFFF;
font-size: 16px;
padding: 15px;
}
.contactpagesellwithus a:link {
background-color: #12BDB8;
color: #FFFFFF;
outline: none;
text-decoration: none;
}
.contactpagesellwithus a:visited {
background-color: #12BDB8;
color: #FFFFFF;
outline: none;
}
.hrafter {
display: inline;
margin: 0 auto;
}
<div class="contactpagelower">
<div class="spancenter"><span class="teallarge">Extras gfgfggsfgfgsfd</span>
</div>
<div class="contactpagecommunityContainer">
<p class="subscribebodytext">We want to hear from you, let us know what we can do to make your experience better!</p>
<button onClick="#" class="contactpagecommunity"><a href="community.php">Visit our community</a>
</button>
</div>
<hr class="hrafter" width="1" size="500">
<div class="contactpagesellwithusContainer">
<p class="subscribebodytext">Have you ever wanted to sell a product? We may be able to help.</p>
<button onClick="#" class="contactpagesellwithus"><a href="sellwithus.php">Sell with us</a>
</button>
</div>
</div>
我尝试通过更改div
s来将我的两个width
彼此分开,希望在中间找到一个间隙。像这样:
.contactpagecommunityContainer {
float: left;
width: 49%;
margin-top: 30px;
display: inline;
}
.contactpagesellwithusContainer {
float: right;
width: 49%;
margin-top: 30px;
display: inline;
}
我还尝试将hr
设置为inline-block
,但这只是将第div
(.contactpagesellwithusContainer
}推到hr
标记停止的位置。
任何人都知道我做错了什么?
答案 0 :(得分:1)
你可以试试这个
.contactpagecommunityContainer {
float: left;
width: 49%;
margin-top: 30px;
display: inline;
}
.contactpagesellwithusContainer {
float: right;
width: 49%;
margin-top: 30px;
display: inline;
border-left: 1px solid;
padding-left: 10px;
}
答案 1 :(得分:1)
您可以将float: left
添加到<hr/>
元素,并使第二个div的宽度为49%:
答案 2 :(得分:1)
尽管hr
表示专题中断,但它也是“横向规则”的缩写。所以它的论证是否应该在没有等价vr
的情况下垂直使用,但是,它可能是最接近的元素。
鉴于您的标记以及您尝试实现的目标,您可能最适合使用CSS表格,其优点是通过将hr
替换为单元格边框,它将随内容缩放酌情。
.contactpagelower {
margin-top: 40px;
display:table
}
.spancenter {
text-align: center;
}
.contactpagecommunityContainer {
margin-top: 30px;
display: table-cell;
padding:20px;
width:50%;
}
.contactpagecommunity {
float: right;
margin-right: 37%;
background-color: #12BDB8;
color: #FFFFFF;
font-size: 16px;
padding: 15px;
}
.contactpagecommunity a:link {
background-color: #12BDB8;
color: #FFFFFF;
outline: none;
text-decoration: none;
}
.contactpagecommunity a:visited {
background-color: #12BDB8;
color: #FFFFFF;
outline: none;
}
.contactpagesellwithusContainer {
display:table-cell;
width:50%;
padding:20px;
margin-top: 30px;
border-left:1px solid;
}
.contactpagesellwithus {
float: left;
margin-left: 35%;
background-color: #12BDB8;
color: #FFFFFF;
font-size: 16px;
padding: 15px;
}
.contactpagesellwithus a:link {
background-color: #12BDB8;
color: #FFFFFF;
outline: none;
text-decoration: none;
}
.contactpagesellwithus a:visited {
background-color: #12BDB8;
color: #FFFFFF;
outline: none;
}
&#13;
<div class="spancenter"> <span class="teallarge">Extras gfgfggsfgfgsfd</span>
</div>
<div class="contactpagelower">
<div class="contactpagecommunityContainer">
<p class="subscribebodytext">We want to hear from you, let us know what we can do to make your experience better!</p>
<button onClick="#" class="contactpagecommunity"><a href="community.php">Visit our community</a>
</button>
</div>
<div class="contactpagesellwithusContainer">
<p class="subscribebodytext">Have you ever wanted to sell a product? We may be able to help.</p>
<button onClick="#" class="contactpagesellwithus"><a href="sellwithus.php">Sell with us</a>
</button>
</div>
</div>
&#13;