Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a horizontal line with <span> or <div>, instead of <hr>?

Tags:

html

css

I would like to know how I can make the tag <hr> effect with the tag <span> or <div>.

I see in large websites the horizontal lines, but they do not use the <hr> tag.

<!DOCTYPE html>
<html lang="pt-Br">
  <head>
    <title> H - Line </title>
   </head>
 <body>
    <hr/>
 </body>
</html>

.


2 Answers

you can use any other HTML tag, define it as follows:

span{
   display:block;
   width:100% /*or whatever width you want the effect of <hr>*/
   border-top: 1px solid #ccc
}

Note you could use border-bottom or border-top and make it any color you want (#ccc resembles the hairline tag pretty well)

Good luck!

like image 94
CreMedian Avatar answered Oct 20 '25 07:10

CreMedian


First, <hr> can be styled with CSS.

hr {
    height: 12px;
    border: 0;
    box-shadow: inset 0 12px 12px -12px rgba(0, 0, 0, 0.5);
}

Code above courtesy of CSS-Tricks.com. See more examples.

Whenever possible, you should stick to horizontal rules for their semantic value. Simply because "large websites" don't use hr tags doesn't mean it's the wrong thing to do, especially since the reasons they don't use them are unknown.

If you want to avoid using <hr> tags, then consider CSS border properties.

div {
  height: 50px;
  border-bottom: 2px solid black;
}
<div></div>
like image 29
Michael Benjamin Avatar answered Oct 20 '25 06:10

Michael Benjamin