logo

Let’s just see what happens

Newsletter

Videos

Speaker

Hard to Read? Choose a style: Style 1 Style 2 Style 3 Default Toggle Sidebars

Wanna play Fix My Code?

Posted on July 10th, 2008

LATER THAT DAY: I took Wray Cummings’ advice in the comments below, which worked. So, now all the examples of uncentered HR statements in this post are in fact examples of centered HR statements, which makes the post rather mysterious. Imagine, if you will, then, that all of the little horizontal rules are left-justified. And, thanks, Wray!


I know I’m going to be embarrassed about this, but for months, if not for years, I’ve been unable to bend the simple <hr> element to my will. I can adjust its length, but I can’t get the little !@#$% to center itself.

I’ve tried everything I can think of to make it work:

<hr width=’100pt’ >:


<hr width=’100pt’ align=center />:


<hr width=’100pt’ align=’center’ />:


<hr width=’100pt’ style=’text-align:center’ />:


None of these work in Firefox or Safari. I have not intentionally redefined hr in any of my many CSS style sheets, but wouldn’t the local, inline setting take precedence anyway?

What incredibly obvious, embarrassing thing am I missing? Go ahead, make me look bad. And I’ll thank you for it. [Tags: html hr ]

Categories: tech

Previous: « Making your Mac lively again || Next: Support EFF’s FISA challenge »

14 Responses to “Wanna play Fix My Code?”

  1. Devan, on July 10th, 2008 at 8:46 am Said:

    Here’s the funny thing- they all looked fine (centered) inside Google Reader, but when I came to this page, they are left aligned. Google knows how to fix it. I’m using Firefox 3, but unfortunately due to some AJAX-ey goodness that Google uses, I can’t view the source for the Google Reader snippet. I will try harder and report back…

  2.  

  3. Bruno Amaral, on July 10th, 2008 at 8:53 am Said:

    Off the top of my head
    ?

    not 100% sure on this, but at home I will see if it works.

  4.  

  5. Devan, on July 10th, 2008 at 8:55 am Said:

    I believe it has something to do with the rest of your page, not the HR-center tag alone. Create a separate html file with just one line (the HR center align line) and open it in Firefox. It will come out center-aligned. So the problem is in something else on this page that is not allowing it to center.

  6.  

  7. jonathan peterson, on July 10th, 2008 at 9:05 am Said:

    The centering syntax you’re using is deprecated, which is moot, since hr is centered by default

    You’ve got hr in your style.css

    body, h1, h2, h3, h4, h5, h6, address, blockquote, dd, dl, hr, p, form{
    margin: 0;
    padding: 0;
    }
    Explicit css centering would probably work

  8.  

  9. jonathan peterson, on July 10th, 2008 at 9:05 am Said:

    you ate my html

  10.  

  11. miles, on July 10th, 2008 at 9:35 am Said:

    Sometimes the margins can collapse, even without margins set to 0 as Jonathan has pointed out, and your centering will look like it isn’t working. If you don’t want to monkey with your stylesheet for some reason, you could try breaking out of the 0-defined margins by giving your left and right hr margins a value of “auto” in your in-line styles. Let me know if you you try it and it works.

  12.  

  13. Bob, on July 10th, 2008 at 9:42 am Said:

    Jonathan’s hit on the problem, I believe. Your stylesheet override is the culprit. Try giving HR’s margin: 0 auto in your CSS.

  14.  

  15. Wray Cummings, on July 10th, 2008 at 10:14 am Said:

    Extracted from context and dropped into a standalone page your hr’s behave as expected — link

    FireBug in FireFox 3.0 thnks the hr’s in the post are 100pt wide and so they very well may be centered. Or left or right justified.

    In order to avoid potential blowback from changing a global css setting, something like –

    div.entry hr {margin: 0 auto}

    may give desired results sans undesired side effects.

    Sure wish there was preview …

  16.  

  17. davidw, on July 10th, 2008 at 10:37 am Said:

    I made Wray’s change, It worked. Thank you!

    So, CSS in style sheets overrides inlines style settings? Wow, that seems wrong to me! Or am I misunderstanding again? Still? Evermore?

    Oh, wait. The page is picking up a margin setting from my style sheet, and that setting is rendering ineffective my inline alignment setting. If I set the margin locally, that would override the style sheet. Got it. I think.

  18.  

  19. Emil Sotirov, on July 10th, 2008 at 10:45 am Said:

    These days… you don’t have to know anything… but how to formulate a good search in Google… Try this one:

    hr tag center

    I think the first result is a good one… didn’t have the time to read it… hope it helps.

  20.  

  21. orcmid, on July 10th, 2008 at 10:53 am Said:

    Even my RSS reader (NewsGator Inbox) got it right. The first one spanned the page but the ones with align attributes (even the one with no quotes on the value) showed up as short and centered.

    Of course, the RSS reader doesn’t use your CSS, so lacks the previously-unsolved problem.

  22.  

  23. dario, on July 10th, 2008 at 10:57 am Said:

    > So, CSS in style sheets overrides inlines style settings?

    No, it doesn’t

    inline style overrides the external style sheet: it’s “cascade”

    but text-align: center isn’t right specify to center the HR.

    right way is margin: 0 auto.

  24.  

  25. dario, on July 10th, 2008 at 11:02 am Said:

    in your external CSS:

    hr{
    /*clear: both;*/
    margin: 15px 0 5px;
    …
    }

    the right way is

    margin: 15px auto 5px auto;

    or, inline, if you wont to apply this only a single HR

  26.  

  27. faisal, on January 10th, 2009 at 1:46 am Said:

    bom-bom sex you ???

  28.  

Leave a Reply


Web Joho only

 

Entries (RSS)
Copy this link as RSS address

Comments (RSS).
Creative Commons License
Joho the Blog by David Weinberger is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.

Creative Commons license: Attribute it to me, share it with others, don't use it commercially without my permission.

Joho the blog uses WordPress blogging software.
Thanks, WordPress!