让hr线进入另外两个div之间

时间:2015-05-18 07:32:53

标签: html css

我想在两个hr之间获取div代码。

我已将hr标记放在第一个div下方和第二个上方。我将divhr标记设置为displayinline,希望这是一个序列并一个接一个地显示。我的问题是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标记停止的位置。

任何人都知道我做错了什么?

3 个答案:

答案 0 :(得分:1)

你可以试试这个

Fiddle Demo

.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%:

https://jsfiddle.net/31ytnun2/8/

答案 2 :(得分:1)

尽管hr表示专题中断,但它也是“横向规则”的缩写。所以它的论证是否应该在没有等价vr的情况下垂直使用,但是,它可能是最接近的元素。

鉴于您的标记以及您尝试实现的目标,您可能最适合使用CSS表格,其优点是通过将hr替换为单元格边框,它将随内容缩放酌情。

&#13;
&#13;
.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;
&#13;
&#13;