<div>之间的水平规则</div>

时间:2013-05-23 04:21:36

标签: html css rule

现在,我有3个div,Content1,Content2,Content3

我想添加一个简单的程式化规则来分隔每个内容。这是我正在使用的代码。

HTML

     <div id="Content1">
     <p><strong>Content1</strong></p>
     </div>

     <div id="Content2">
     <p><strong>Content2</strong></p>
     </div>

     <div id="Content3">
     <p><strong>Content3</strong></p>
     </div>

我想在Content1和Content2之间以及Content2和Content3之间添加水平规则。

我已经包含了一张图片,因此您可以清楚地看到我的意思。

enter image description here

谢谢!

5 个答案:

答案 0 :(得分:12)

不要使用<hr>,因为它主要是一个语义元素而不是表示元素。底部边框是理想的选择。例如。 http://codepen.io/pageaffairs/pen/pjbkA

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<style media="all">

div {width: 500px; padding-bottom: 10px; }
#Content1, #Content2 {border-bottom: 3px solid #4588ba; margin-bottom:10px;}
div p {background: #4588ba; line-height: 150px; font-size: 2em; font-family: sans-serif; color: white; margin: 0; padding-left: 30px;}

</style>

</head>
<body>

     <div id="Content1">
     <p><strong>Content1</strong></p>
     </div>

     <div id="Content2">
     <p><strong>Content2</strong></p>
     </div>

     <div id="Content3">
     <p><strong>Content3</strong></p>
     </div>

</body>
</html>

答案 1 :(得分:4)

您可以使用hr标记分隔div元素

<div id="Content1">
     <p><strong>Content1</strong></p>
</div>
<hr />
     <div id="Content2">
     <p><strong>Content2</strong></p>
</div>
<hr />
<div id="Content3">
     <p><strong>Content3</strong></p>
</div>

Demo

您可以使用solid border

重置hr代码的默认3D样式
hr {
    margin: 20px 0;
    border: 1px solid #f00;
}

答案 2 :(得分:2)

如果您不想使用hr标签。你可以用另一个div绑定每个div并装饰它。像这样: 请参阅演示:jsfiddle

<div id="Content1" class="divOutside">
    <div class="divInside">
        <strong>Content1</strong>       
    </div>
</div>
<div id="Content2" class="divOutside">
    <div class="divInside">
       <strong>Content2</strong>        
    </div>
</div>
<div id="Content3" class="divOutside last">
    <div class="divInside">
       <strong>Content3</strong>     
    </div>
</div>

和Css:

.divOutside {
    border-bottom:2px blue solid;
    width:200px;
    padding-bottom:5px;
    padding-top:5px;
}
.divInside {
    width:200px;
    height:80px;
    color:#fff;
    background-color:blue;
}
.last {
    border-bottom:0;
}

答案 3 :(得分:1)

试试这个

demo

<强> HTML

<div id="Content1" class="content">
     <p><strong>Content1</strong></p>
</div>
<div class="break"></div>
     <div id="Content2" class="content">
     <p><strong>Content2</strong></p>
</div>
<div class="break"></div>
     <div id="Content3" class="content">
     <p><strong>Content3</strong></p>
</div>

<强> CSS

.content {
    padding:20px;
    background:#3E87BC;
    font-size: 24px;
    margin-bottom:10px;
    font-family: Arial;
    color: #FFF;
}
.break { 
    background: #3E87BC;
    height: 2px;
    margin: 5px 0 10px 0;
    width: 100%;
}

答案 4 :(得分:-1)

<div id="Content1" style="background-color:#2554C7;width:300px;height:50px;">
<p style="padding-left:40px;padding-top:10px;color:white;font-size:26px;"><strong>Content1</strong></p>
</div>
<div id="Content4" style="background-color:#2554C7;width:300px;height:5px;">
<hr style="color:#2554C7;"></hr>
</div>
<div id="Content2" style="background-color:#2554C7;width:300px;height:50px;">
<p style="padding-left:40px;padding-top:10px;color:white;font-size:26px;"><strong>Content2</strong></p>
</div>
<div id="Content5" style="background-color:#2554C7;width:300px;height:5px;">
<hr style="color:#2554C7;"></hr>
</div>
<div id="Content3" style="background-color:#2554C7;width:300px;height:50px;">
<p style="padding-left:40px;padding-top:10px;color:white;font-size:26px;"><strong>Content3</strong></p>
</div>
<div id="Content6" style="background-color:#2554C7;width:300px;height:5px;">
<hr style="color:#2554C7;"></hr>
</div>