Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal Rule between <div>'s

Tags:

html

css

rule

Right now, I have 3 divs Content1, Content2, Content3

I want to add a simple stylized rule to separate the content in each. Here is the code that I am working with.

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>

I want to add a Horizontal Rule inbetween Content1 and Content2 and between Content2 and Content3.

I have included an image so you can see exactly what I mean.

enter image description here

Thanks!

like image 329
Colin Avatar asked May 23 '13 04:05

Colin


People also ask

How do I insert a horizontal line between two divs?

To add a horizontal line between two divs, just put <hr> between the divs. You can use CSS to style this in a variety of ways such as adjusting the color and thickness of the line as well as the top and bottom margins.

What is the horizontal line rule?

<hr>: The Thematic Break (Horizontal Rule) element The <hr> HTML element represents a thematic break between paragraph-level elements: for example, a change of scene in a story, or a shift of topic within a section.

What is the correct element for inserting a horizontal rule?

The <hr> element is most often displayed as a horizontal rule that is used to separate content (or define a change) in an HTML page.

How do I draw a horizontal line in a div?

Its simple to add a horizontal line in your markup, just add: <hr>. Browsers draw a line across the entire width of the container, which can be the entire body or a child element.


2 Answers

Don't use <hr> for this, as it's chiefly a semantic element rather than presentational. A bottom border is ideal for this. E.g. 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>
like image 183
ralph.m Avatar answered Oct 18 '22 22:10

ralph.m


You can use an hr tag to separate your div elements

<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

You can reset the default 3d style of an hr tag using solid border

hr {
    margin: 20px 0;
    border: 1px solid #f00;
}
like image 30
Mr. Alien Avatar answered Oct 18 '22 20:10

Mr. Alien