CSS - Paddings & Right&left Margins Always Combine, But Bottom & Top Margins Don't, Right?
Hi!
Could some experienced CSS developer please confirm this: All paddings, and right and left margins, always combine (what I mean is if you have a left object with a 5px right margin and a right object with a 5px left margin, the distance between the two will be 10px). However, bottom & top margins never combine. Is all this true? Similar TutorialsHi! I have some perilous questions on margins and paddings: 1/ Can I apply padding and margin to both block and inline elements? 2/ Can I apply width and height to both block and inline elements? Thanks I am having a problem where I have a <div> that holds my body image, margin: 0 auto; Inside that is my content <div> with margin:15px; but this is visually dropping the background image's margin by 15px. The problem compounds every time I add another margin/padding requirement into the rest of the <div>. Code: html, body { margin:0px; padding:0px; background-image:url(images/interface/background.png); } #body_image { width:935; margin:0 auto; padding:0px; background-image:url(images/interface/body.png); background-repeat:no-repeat; background-position:center; } #container { width:904px; height:750px; margin:15px; } #slug { height:15px; } Code: <div id="body_image"> <div id="container"> <div id="header">Header</div> <div id="nav">Nav</div> <div id="sidebar">Sidebar</div> <div id="content">Content</div> <div id="footer">Footer</div> </div> </div> The extent of my CSS is a few tutorials online and the class I took 10 years ago where the teacher said "Here's CSS, you can't do much more than change your font size and color with it... on to tables!" Thought it'd only be fair to give you a little background. [sorry] Hello, I am having a real problem with my template at URL ; when I preview the template it looks great but once i save it and publish it, the scrollbar doesn't appear lilac and the left margins on my posts are too close to the left. I really don't know how to arrange this, I am new to html and of course a newbie to css. So here I include the code and if someone can give me some help i will be really grateful. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head><meta name="author" content="SOUL" /> <meta name="dc.language" content="en" /> <meta name="copyright" content="This work is licensed under a Creative Commons License. " /> <meta name="description" content="Looking back to the times of cotton fields, coffee engines... and chivalry" /> <meta name="keywords" content="SLAVE,SLAVERY,DOMINANT,DOMINANCE,EROTICA,INTERRACIAL" /> <title><$BlogPageTitle$></title> <$BlogMetaData$> <style type="text/css"> /* ----------------------------------------------- Blogger Template Style Name: Minima Designer: Douglas Bowman URL: URL Date: 26 Feb 2004 ----------------------------------------------- */ body {scrollbar-base-color: #cc99ff; background-color: #f5ecff;} blockquote, p, h1, h3, .blogpost {font-family: "Trebuchet MS", arial, sans-serif; font-size: normal; color: black;} .outerborder {background-color: #f5ecff; width: 285px;} .menuheader {font-family: "Harrington", "Trebuchet MS", arial; background-color: #e7d1fd; color: black; font-size: 18px; font-weight: bold; text-align: center; border-color: #7d00be; border-width: 1px; border-style: dashed; padding-left: 5px; padding-top: 2px; padding-bottom: 3px;} .menutext {background-color: #f5ecff; font-size: 16px; padding-top: 5px; padding-left: 10px;} h2 {font-family: "Harrington","Trebuchet MS", arial;} .dateheader {background-color: #e7d1fd; color: black; text-align: left; border-bottom: 1px dashed #7d00be; border-top: 1px solid #7d00be; padding-left: 5px; padding-top: 2px; padding-bottom: 3px;} .postinfo {font-style: italic; font-weight: bold; color: black;} .contentcell {background-color: white; width: 100%; border-color: #7d00be; border-style: solid; border-right-width: 1px; border-left-width: 1px; border-bottom-width: 1px; border-top-width: 0px;} a:link {color: #7d00be; text-decoration: none;} a:visited {color: mediumpurple; text-decoration: none;} a:active {color: #cc66ff; text-decoration: none;} a:hover {background-color: #cc99ff; color: black; text-decoration: none;} a img { border-width:0; } .blogpost {margin-left: 15px; margin-right: 10px;} blockquote {padding: 5px; font-size: smaller; border-color: #cc99ff; border-width: 1px; border-style: dashed;} .post { margin:.5em 0 1.5em; border-bottom:1px dotted #fff; padding-bottom:1.5em; } .comment-link { font:78%/1.4em "Trebuchet MS",Trebuchet,Arial,Verdana,Sans-serif; text-transform:uppercase; letter-spacing:.1em; } .comment-link { margin-left:.6em; } .post a { font-weight:bold; } #comments h4 { margin:1em 0; font:bold 78%/1.6em "Trebuchet MS",Trebuchet,Arial,Verdana,Sans-serif; text-transform:uppercase; letter-spacing:.2em; color:#774; } #comments-block dt { margin:.5em 0; } #comments-block dd { margin:.25em 0 0; } #comments-block dd.comment-timestamp { margin:-.25em 0 2em; font:78%/1.4em "Trebuchet MS",Trebuchet,Arial,Verdana,Sans-serif; text-transform:uppercase; letter-spacing:.1em; } </style> </head> <body> <!-- You may add banner here. --> <center> <img border="0" src="http://www.passionatelove.net/title.JPG" width="385" height="300"><p id="description"> <font face="Antigoni"><$BlogDescription$></font></p> <p id="description"> <!-- Start FastOnlineUsers.com --> <font face="Banjoman Open Bold"> <a href="http://www.fastonlineusers.com"><script src=http://fastonlineusers.com/online.php?d=www.unmerciful-tara.blogspot.com></script> online</a></font><!-- End FastOnlineUsers.com --> </p> <p> </p> </center> <table border="0" cellpadding="5" cellspacing="0" width="100%"> <tr> <td valign="top" width="100%"> <!-- You may move banner here if needed. --> <div class="contentcell"> <Blogger> <BlogDateHeader><h2 class="dateheader"><font face="AucoinLight"><$BlogDateHeaderDate$></font></h2></BlogDateHeader> <!-- Begin .post --> <div class="post"><a name="<$BlogItemNumber$>"></a> <BlogItemTitle> <h3 class="post-title" align="center"> <a href="<$BlogItemUrl$>" title="external link"> <BlogItemUrl></BlogItemUrl> <font size="4" face="AucoinLight"><$BlogItemTitle$> </font> <BlogItemUrl></BlogItemUrl> </a> </h3> </BlogItemTitle> <div class="post-body"> <p style="margin-left: 6"> <font face="Georgia" size="3"> <$BlogItemBody$> </font> </p> </div> <p class="post-footer"> <em><font face="Book Antiqua"> posted by <$BlogItemAuthorNickname$> at </font> <a href="<$BlogItemPermalinkUrl$>" title="permanent link"> <font face="Book Antiqua"><$BlogItemDateTime$></font></a></em><font face="Book Antiqua"> </font> <MainOrArchivePage><BlogItemCommentsEnabled> <a class="comment-link" href="<$BlogItemPermalinkURL$>#comments"> <font face="Book Antiqua"><$BlogItemCommentCount$> comments</font></a><font face="Book Antiqua"> </font> </BlogItemCommentsEnabled></MainOrArchivePage> <font face="Book Antiqua"><$BlogItemControl$> </font> </p> </div> <!-- End .post --> <!-- Begin #comments --> <ItemPage> <div id="comments"> <BlogItemCommentsEnabled><a name="comments"></a> <h4><font size="2" face="Book Antiqua"><$BlogItemCommentCount$> Comments:</font></h4> <dl id="comments-block"> <BlogItemComments> <dt class="comment-poster" id="c<$BlogCommentNumber$>"><a name="c<$BlogCommentNumber$>"></a> <$BlogCommentAuthor$> said... </dt> <dd class="comment-body"> <p><$BlogCommentBody$></p> </dd> <dd class="comment-timestamp"><a href="#<$BlogCommentNumber$>" title="comment permalink"><$BlogCommentDateTime$></a> <$BlogCommentDeleteIcon$> </dd> </BlogItemComments> </dl> <p class="comment-timestamp"> <$BlogItemCreate$> </p> </BlogItemCommentsEnabled> <p class="comment-timestamp"> <a href="<$BlogURL$>"><< Home</a> </p> </div> </ItemPage> <!-- End #comments --> </Blogger> </div></div> <!-- End #main --> <br> </p> </td> <td valign="top" width="300"> <!-- You may add an image here. --> <div class="outerborder"> <div class="menuheader"><font face="AucoinLight">Soul</font></div> <p class="menutext"> <$BlogMemberProfile$></p> <p class="menutext"> <font face="AucoinLight" size="3"> The Irreverent 1700's Governor's Wife</font></p> <ul> <p style="text-align: center"> <b><font size="2" color="#668844" face="Antigoni Light">*some adult content*</font></b></p> <p style="text-align: right"> <a href="http://feeds.archive.org/validator/check.cgi?url=http://unmerciful-tara.blogspot.com/atom.xml"> <img src="http://www.passionatelove.net/valid-atom.png" alt="[Valid Atom]" title="Validate my Atom feed" width="88" height="31" /></a></p> <p style="text-align: right"> <a href="http://www.bloglines.com/sub/http://unmerciful-tara.blogspot.com/"> <img src="http://www.passionatelove.net/sub_modern6.gif" border="0" alt="Subscribe with Bloglines" width="80" height="15" /> </a></p> <p style="text-align: right"><script src="http://blogsnob.simpleads.net/ad/11824" type="text/javascript">blogsnob. show off your websites. http://blogsnob.simpleads.net</script></p> </ul> <div class="menuheader"><font face="AucoinLight">Ledger</font></div> <p class="menutext"> <script type="text/javascript" src="<$BlogArchiveFileName$>"></script> <h2 class="sidebar-title" style="text-align: right"><b> <font size="2" face="Footlight MT Light">Previous Posts</font></b></h2> <ul id="recently"> <BloggerPreviousItems> <li> <p style="text-align: right"><a ETC. ETC.... (THE PROBLEM SEEMS TO BE ABOVE) </body> </html> THANKS FOR YOUR HELP! Hi All, This seems to be a bit of a recurring problem for me in a lot of the new CSS designs I'm trying... but it seems that IE interprets both padding and margins differently than how firefox interprets them. Sometimes it seems to do it the same, and other times differently. Take a look at this: http://zeroonedesign.com/beta/newsite/index.html CSS he http://zeroonedesign.com/beta/newsite/style.css Now look at it first in Firefox (the desired effect) and then in IE. IE seems to be incapable of understanding this particular piece of the code Code: #menu {padding-top:140px;text-align:left;padding-left:38px;} #menu ul{margin:0px;} #menu ul li{display:inline;margin-right:10px;padding:5px 7px 5px 7px;color:#fff;} #menu ul li a{color:#fff;font-size:10pt;text-decoration:none;} #menu ul li a:hover{color:#fff;font-size:10pt;border-bottom:3px solid #fff;} #menu ul li a.selected{color:#f88000;font-size:10pt;border-bottom:2px solid #f88000;} Ideas? Help? I know the box model is different for IE than it is for FF but I've tried the box model hack and it doesn't seem to do anything. according to the css 2.1 spec if you specify the margin/padding of an element in ems then it takes the measurement from that element's font size, this means that * { font size: 1em; } h1 { font-size: 1.5em; margin-bottom: 1em; } gives h1 a margin of ... 1.5em ... which sucks. and is counter intuitive IMO. how is one supposed to go about having fixed margin spaces when using scalable fonts? now i know that margins overlap so theoretically setting p { margin-top: 1em; } instead would work, but only where a p lies under a h1. if i had a h1 then a h2 then a p then how large would the gap be between the h1 and the h2? and how would i control that reliably? the only way around this i can think of is this * { font-size: 1em; /*let's say this equates to 10px on the device it's being viewed on*/ } h1 { font-size: 1.5em; /*...then this would be 15px*/ margin-bottom 0.67em; /*..this would be 67% of 15px = 10px!*/ } h2 { font-size: 1.2em; /*12px*/ margin-bottom: 0.83em; /*83% of 12px = ... 10px!*/ } p { margin-botton: 1em; } Now, when i scale the font size all the margins should scale in accordance with the <p>. at least, according to my understanding of the spec. i'll try it in the next couple of hours (first thing monday morning just got to work)... anyone else thought of a scalable friendly alternative? Anyone know why the margins change on the links when I hover over them with IE. (check left column navigation) http://section31.us/temp/tortilla/tortilla.html Note: This works fine on firefox, but goes ape**** on IE. Hello, I have the following issue. I need to create a full screen gray div with another white div inside it, positioned with 5 pixel margin. Basically it looks like a white div with 5px border around it. That wouldn't be a problem after i set body and html height to 100%, but here's what breaks: i add the first gray div (relatively positioned) and make it's min-height: 100%, then add lots of text and see if it autoexpands. It does! Now i add another absolutely positioned white div inside of it and set its position to 5px from each side. And now everything breaks ... doesn't autoexpand ... at least in opera. Here's the css: Code: body, html { width: 100%; height: 100%; margin: 0; padding: 0; } #maindiv { position: relative; left: 0; top: 0; width: 100%; min-height: 100%; background: #777777; } #fullscr { position: absolute; left: 5px; top: 5px; bottom: 5px; right: 5px; background: #FFFFFF; } <div id="maindiv"><div id="fullscr"> lots of text with linebreaks </div></div> Does anyone have any ideas how to make it work? I have a couple of problems. 1) I have an unwanted margin around my page. I have tried and searched everything I could to get rid of it and I cannot. Ca someone please explain why it is doing this? 2) No matter how hard I try, the Navigation list will not move to where I would like it to go (Centered in the grey area). What am I doing wrong? Code below html Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <link rel="stylesheet" type="text/css" href="./CSS/style1.css" /> <title>Cakefaced - Miles out of the box</title> </head> <body> <div id="Banner" /> <div id="Logo" /> <div id="NaviRear" /> <ul class="NaviLink"> <li class="NaviLink"><a class="NaviLink" href="index.html">Home</a></li> <li class="NaviLink"><a class="NaviLink" href="index.html">Projects</a></li> <li class="NaviLink"><a class="NaviLink" href="index.html">Geuestbook</a></li> <li class="NaviLink"><a class="NaviLink" href="index.html">Profile</a></li> </ul> </div> <div id="Blog" /> <div id="Links" /> </body> </html> CSS: Code: @charset "utf-8"; /* CSS Document */ /*CSS Sheet Copyright(C) 2011 to Cakefaced.co.uk All Rights Reserved This style sheet cannot be used without permission from Cakefaced.co.uk Administrator */ /* ----------------------------------------------------------------------------------------------- Begin Banner Styling ----------------------------------------------------------------------------------------------- */ #Banner { background-image:url('../Images/BannerRear.jpg'); background-repeat:repeat-x; height:200px; margin:0; position:relative; } /* ----------------------------------------------------------------------------------------------- End Banner Styling ----------------------------------------------------------------------------------------------- */ /* ----------------------------------------------------------------------------------------------- Begin Navigation Styling ----------------------------------------------------------------------------------------------- */ #NaviRear { background-image:url('../Images/NaviBack.jpg'); background-repeat:repeat-x; top:150px; height:60px; margin:0; position:relative; } ul.NaviLink { list-style-type:none; margin:0; } li.NaviLink { display:inline; bottom: 10px; position:float; } a:link.NaviLink { font-size:1.875em; color:#000000; /* unvisited link */ font-family:"Arial Black", Gadget, sans-serif; } a:visited.NaviLink { color:#000000; /* visited link */ } a:hover.NaviLink { color:#FF00FF; /* mouse over link */ } /* ----------------------------------------------------------------------------------------------- End Navigation Styling ----------------------------------------------------------------------------------------------- */ ok im having a no brainer and i cant figure out what i did wrong, can someone take a look at this and tell me how to remove the space below. im posting a link, it has the css text posted on the page with the menu im working on that im having difficulty with. thanks in advance, Trizen www dot cooperativecreditsystems slash Untitled-2 dot html apparently being a new user i cant post links but just add the dots as dots and you should be able to find it. I am having a heck of a time with this side sub-menu. I cannot seem to get the left margins to be equal in IE 6, 7 or 8? My html: Code: <!-- show_menu2 --> <ul id="sub_menu" class="menu" style="margin-left:-5px;position: relative; background-color:#CFF"> <li><a href="#" class="menu-expand menu-first navlev2" title="Project">Add-ons Project</a></li> <li><a href="#" class="menu-expand menu-parent navlev2" title="What Modules">Modules</a> <ul class="ullev3"> <li><a href="#" class="menu-sibling menu-first navlev3" title="Modules Here">Module</a></li> <li><a href="#" class="menu-sibling navlev3" title="Admin Tools">Admin Tools</a></li> <li><a href="#" class="menu-current navlev3" title="Random">Code Snippets</a></li> <li><a href="#" class="menu-sibling menu-last navlev3" title="Droplet of Link">Droplets</a></li> </ul> </li> <li><a href="#" class=" navlev2" title="AMASP">AMASP</a> </li> <li><a href="#" class=" navlev2" title="Templates">Templates</a> </li> <li><a href="#" class="menu-last navlev2" title="Backend Pages">Backend Themes</a></li> </ul> </div> <!-- end of subnavigation --> My CSS: Code: #submenu { padding: 0; /* [disabled]width: 247px; */ /* [disabled]position: relative; */ /* [disabled]left: -15px; */ } #submenu a { text-decoration :none; color :#5b9acf; padding-left :12px; display :block; background-image: url(../images/bullets_micro/square3.gif); background-repeat: no-repeat; background-position: 2px 50%; } #submenu a:hover { color :#003366; background-image: url(../images/bullets_micro/square1.gif); background-repeat: no-repeat; /* [disabled]background-position: 4px 50%; */ } #submenu a:active { border: none; } #submenu a.menu-current { font-weight :bold; color :#003366; background-image: url(../images/bullets_micro/asst3.gif); background-repeat: no-repeat; background-position: 4px 50%; } #submenu ul { margin-top: 0; margin-right: 0; margin-bottom: 0px; /* [disabled]margin-left: -25px; */ /* [disabled]position: relative; */ /* [disabled]left: -10px; */ } #submenu ul li { padding :5px 0; /* [disabled]line-height :1.4em; */ font-size :12px; list-style-type :none; border-bottom :#cccccc 1px solid; } #submenu ul li.a { padding: 0px 10px; } #submenu ul li li { border-bottom :none; padding-bottom :0px; font-size :11px; } #submenu ul li li a:link, #submenu ul li li a:visited { color :#003366; background-image: url(../images/bullets_micro/diamond4.gif); background-repeat: no-repeat; background-position: 2px 50%; } #submenu ul li li a:hover { background-image: url(../images/bullets_micro/diamond.gif); background-repeat: no-repeat; /* [disabled]background-position: 4px 50%; */ color: #6DB9FA; } /* ====================== */ My test page: (pardon the blue background I just added this to see the container.) http://new.ssmarts.org/page.html Thanks so much. 'Ello, I have a slight problem with some CSS I am using, it works perfectly fine in other browsers but in IE 6 it doesn't. What I basically want is the body of the page to have a 10pixel margin on the left and right of the page and 0 at the top and bottom, this bit I can do. I also want everything on the page to stretch from the end of each margin (so they basically start 10 pixels in from the left and 10 pixels in from the right), which I have got working fine. Now what I am trying to do is have one div layer stretching from the very left to the very right of the page and I am getting a bit stuck on it. What I have managed to do is set that div layer to be absolute positioning so I can use "left: 0px;" to get it all the way up against the left hand edge, but how can I get it right up against the left hand edge? I am sure if I set it to be the width of the page so for example if the page is 500 pixels wide and I use "width: 500px;" it would go from end to end, but what I want is it to go from end to end no matter what the width of the window is. For the rest of the layers that are not going from end to end but are staying within the body margins I used "width: 100%;" which works fine, but when I try it with the one that I want to go from end to end it only goes up to the body margin, but right to the end, well in IE it does anyway other browsers are fine with it. Does anyone know how to get around this? I have tried looking on the net but I can't find anything on it. All help will be greatly welcome. Thank you in advance, El Barto. Hi, I have a list item that extends onto a second line. How do I keep the second line the indented more than the first line? thanks -S I thought I had this worked out before with the help of this forum, but it seems to be back again! In IE 6 (and maybe others, who knows. I am running Ubuntu =/ ) there is a big gap between the top horizontal nav and the comic. http://www.jjsunshines.com/ Any help would be greatly appreciated! I'll even trade you php help! Hi All, I am very new to CSS and i am working on preparing a document of an existing CSS. Can someone tell me if the margins are set as this, margin:0px 31px 0px; Is it top,right and bottom? Thanks Prena I've got two child divs nested in a parent div. They are shown below. The problem I am having is that in IE 5.x for Mac, the top margins do not work, while the left margins are applied properly. The following script works just fine in: safari, mozilla, firefox, opera, netscape, etc. It is only in IE for mac that the top margin is not applied and the two children are positioned improperly. If anyone knows of any fixes, hacks, or just sees some junk in my code, please let me know. All help is greatly appreciated! #parent { width: 700px; height: 66px; } #child1 { width: 288px; height: 56px; margin: 8px 0 0 10px; background-image: url(whatever); background-repeat: no-repeat; float: left; } #child2 { width: 115px; height: 40px; margin: 14px 0 0 165px; background-image: url(whatever); background-repeat: no-repeat; float: left; } Hey, I am currently learning how to do layouts in pure CSS and am running into a few problems. Some of these i've cleared up, but i'm still learning obviously. My currently issue is that margin / top settings are not consistent throughout browsers. Example: in FF/Mozilla a margin setting or "top" pixel setting is "lower" than in IE. The reason for this is, apparantly, when margins are set to zero my lower div table actually rides up "under" the above div's bottom border, this creates an offset of 5 pixels when setting margins, etc. Whereas, in IE, the div sits directly beneath the 5px border, as I would assume it should. Here are the files i'm using: 1) Webpage: http://www.binjured.com/index2.php 2) CSS File: http://www.binjured.com/style2.css important css (as i see it) a #nav, .top, .main (these are all near the bottom of the file, if you wish to skip extraneous code). I am trying to understand WHY css does the things it does and how I can make it do the right thing. Any help would be extremely appreciated. Finally, there may be some extraneous code that those who know css, know does nothing. It's in there because I am trying to "debug" it but i'm completely lost for the answer now . Hi Guys, I have a question about me not understanding how margins work... I am quite perplexed...I am trying to remove the white space between borders of table cells. I am using: Code: td { margin: 0; } But there is still white space between the cells...how do I make no space between the cells? Code is located he http://www.taipeitripper.com/senshin_center/training_schedule.html Thank you, Evan Jerkunica I'm working on a set of tabs within tabs (or subtabs). My code is something like this: Code: <ul class="tabs" <li class="selected">1</li> <li>2</li> <li>3</li> <li>4</li> </ul> <div class="tab_content"> <ul class="subtabs"> <li class="selected">1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul> Now, "tab_content" has padding of 10px, because the subtabs won't always be there. But I don't want the padding on the subtabs, so I was giving them a negative margin of -10px. This works in all browsers but IE, which applies everything but the right margin, leaving a white gap. See the image I'm attaching to see what the problem looks like. Anyone know of easy fixes for this? |