- This topic is empty.
-
AuthorPosts
-
January 25, 2013 at 9:59 am #42246darrylmMember
A margin is appearing between my html tag and body tag but only in Firefox.
I have declared *{margin:0; padding:0} in the stylesheet and using Firefox’s developer tool shows that there is no margin or padding or margin calculated, however this problem persists.
I have found the apparent cause, but I’m uncertain as to the reason.
I have a nested div within a container, and this div has a margin:20px 0px;
When this margin is set, it also creates a 20px margin between html tag and body tag and likewise if removed.
However, adding padding to the adjacent sibling of body tag (a nav tag) removes this unwanted margin.Why is this?
I realise the obvious solution is to either add padding to the nav or remove the margin from the nested div, but this would be papering over the cracks and doesn’t deal with the issue at hand, it also messes with how my layout should look
January 25, 2013 at 10:07 am #122278Paulie_DMemberWe’d need to see a link to be sure but IIRC it’s related to the top margin you have set not having (in effect) anything to push against so it pushes itself away.
The simplest method, as you say, is to add padding but since you don’t want to do that, give the container a top border of 1px solid transparent or whatever color you want.
That should do it and it’s practically invisible.
January 25, 2013 at 10:10 am #122279darrylmMemberI’ve checked with IE9 and current version of Safari, Opera and Chrome and all ignore the border.
I knew there’d be a logical reason behind it, especially with it being the case in Firefox, but couldn’t think what it could possibly be.
January 25, 2013 at 10:14 am #122280Paulie_DMemberSorry, was editing my reply.
Ideally a link would be best option to make sure my suspicions are correct.
January 25, 2013 at 10:16 am #122281darrylmMemberI feel like I’m hacking around adding an invisible border or thin padding, forgive me.
Is there a ‘clean’ solution to have:
– 0 margin between top of the page and div #1
– 20px margin between div #2 and div #1
– 20px margin between div #2 and div #3(Thank you for the help, by the way)
January 25, 2013 at 10:18 am #122283January 25, 2013 at 10:28 am #122284Paulie_DMemberUnfortunately, I don’t have FF on this laptop but I’m sure others here can help you.
January 25, 2013 at 10:31 am #122285darrylmMemberThanks for the help up to now…
January 25, 2013 at 12:02 pm #122297S_HonderdosMemberI’m not sure why or how but this wil fix it (for me Aurora 16.0a2)
add:
nav#top{
display:inline-block;
width:100%;
}Maby someone who really understands it can explain why.
January 25, 2013 at 3:51 pm #122325wolfcry911ParticipantI can somewhat explain why, but I still haven’t figured out why it’s needed. The display: inline-block changes the block formatting context of nav. The same results are true if you use display: table, or don’t change the display at all, but add overflow:hidden to #top (all of which change the BFC). Normally a margin would be protruding out the top of nav, and then #container, and again body; but there’s no top margins – I can’t find why it’s happening. I have seen this before however, and I just used the overflow: hidden to correct it.
January 28, 2013 at 5:02 am #122536darrylmMemberThanks for the suggestions
January 28, 2013 at 10:52 am #122584darrylmMemberAs said, both display:inline-block and overflow:hidden will fix this, however overflow:hidden will cause problems if using CSS for a drop-down menu.
January 28, 2013 at 10:58 am #122585wolfcry911ParticipantYou can put the overflow: hidden; on the #container and not have it affect the dropdown.
January 28, 2013 at 11:56 am #122594darrylmMemberOkay, thanks for the help
January 30, 2014 at 4:05 am #161392ignaciolfloresParticipantS_Honderdos answer works for me!
Thanks!!
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.