I've seen this thing in many websites, but I couldn't figure out how it is done. How do I create something like this:
Asked
Active
Viewed 1,220 times
1
-
http://css-tricks.com/line-on-sides-headers/ – CBroe Oct 15 '13 at 07:59
-
there is hr tag in html http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_hr_test – mahesh Oct 15 '13 at 08:06
-
1Different pages do it in different ways. Look at their HTML and CSS (and maybe even JavaScript) code to see how they do it. – Jukka K. Korpela Oct 15 '13 at 08:08
3 Answers
3
I have already answered on this question. How do I simplify this header with lines on the side, so that it doesn't need css3 background properties?
The jsFiddle : http://jsfiddle.net/dASCv/10/
HTML
<div>
<h2>Title</h2>
</div>
CSS
div {
text-align: center;
}
h2:before,
h2:after {
border-top: 1px solid black;
display: block;
height: 1px;
content: " ";
width: 40%;
position: absolute;
left: 0;
top: 1.4em;
}
h2:after {
right: 0;
left: auto;
}

Community
- 1
- 1

Donovan Charpin
- 3,567
- 22
- 30
-
Just for my curiosity, when you strech the window, the border collapses to merge itself into the text characters, any solutions?? – Nitesh Oct 15 '13 at 08:14
-
But the stetchablity is still an issue in your solution, so my curiosity is that whether you can resolve it, as it might be an orgainic solution without using fieldset, etc. – Nitesh Oct 15 '13 at 08:25
-
It's already a complicated solution. So it's more complicated to arrange a little problem. You can play with the h2:before, h2:after width to have better results, all depend of the context on your website. – Donovan Charpin Oct 15 '13 at 08:33
1
Use the CSS pseudo-classes :before
& :after
, so you can add text, graphics or what ever you before and after the text.

Michael Schmidt
- 9,090
- 13
- 56
- 80
0
By using a legend
, you can achieve what you want as per your attached screenshot.
Here is the WORKING DEMO for the same.
The HTML:
<form>
<fieldset>
<legend>Title</legend>
</fieldset>
</form>
The CSS:
legend {
margin: 0 50%;
text-align: center;
}
fieldset {
border:5px solid black;
border-bottom: medium none;
border-left: medium none;
border-right: medium none;
}
I hope this is what you want.

Nitesh
- 15,425
- 4
- 48
- 60