Welcome to Dream.In.Code
Getting Help is Easy!

Join 118,587 Programmers for FREE! Ask your question and get quick answers from experts. There are 838 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Make a styled <DIV> look like an <HR /> that works in all

 
Reply to this topicStart new topic

> Make a styled <DIV> look like an <HR /> that works in all

fyrestorm
Group Icon



post 24 Nov, 2006 - 10:35 AM
Post #1


If you've ever used CSS to style an <HR> for IE you know full well that it's difficult to make it look the way you want it to, and then once it looks the way you want it to in IE it's usually jacked up in FireFox. And of course, vise-a-versa.

I've recently learned that I can style a <div> to look like an <hr> and now you can too!

You can do this either by using a linked stylesheet, internal styles, or inline styles. This snippet below shows the method with either a linked stylesheet or internal styles, but you can easily replace it with inline styles.

In your html code, put
CODE

<div class="hr"> </div>


Where you would put
CODE

<hr />


Wherever you put your styles, be them internal or external, add this snippet
CODE

.hr {
background-color: #FFFFFF;
border: 1px solid #000000;
height: 10px;
margin: 10px 0;
width: 760px;
}


If you want an inline style, you can do it as so
CODE

<div style="background-color: #FFFFFF; border: 1px solid #000000; height: 10px; margin: 10px 0; width: 760px;"> </div>



You can change the colors to whatever you like, the width, and the height. Just make sure that whatever you set the height to, you also change the margin to match.


You now have an <hr /> look alike that's fully stylable and works in all browsers.
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

roberts
*



post 11 Mar, 2007 - 12:11 AM
Post #2
hi,fyrestorm,

Thanks for this an <hr /> look alike tip, it is useful,
but it seem not same with FF and IE7.

btw if someone set IE with large font size, it will large than <hr />


Go to the top of the page
+Quote Post

roberts
*



post 19 Apr, 2007 - 05:15 AM
Post #3
hi,

It work fine wirh opera.

--------------------------
software reviews

This post has been edited by roberts: 19 Apr, 2007 - 05:15 AM
Go to the top of the page
+Quote Post

beef
Group Icon



post 19 Apr, 2007 - 12:39 PM
Post #4
Nice!

Make sure your font size is 10px or less for that too, the height of the div will stretch to the height of the font if the font's height is larger even if there is no text in the div. I think FireFox may limit how small it can be too, but I think the limit is around 6-8px.
Go to the top of the page
+Quote Post

Janet Kellman
*



post 9 Jul, 2007 - 08:43 AM
Post #5
This code works perfectly in opera, ie, ff and safari with little customization. Thanks, fyrestorm!

__________
Janet Kellman, software reviews

This post has been edited by Janet Kellman: 9 Jul, 2007 - 08:44 AM
Go to the top of the page
+Quote Post

angela08
*



post 3 Jul, 2008 - 06:50 PM
Post #6
biggrin.gif Wow, I never know that <DIV> can be used to style an <HR>, that's great. I've tried the code, it works fine in Maxthon.

Thanks for sharing.


__________
software downloads
Go to the top of the page
+Quote Post


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 10/11/08 07:28PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month