CSS - Absolutely Positioned <div> Tag W/padding Overlapping
Sorry if this has been discussed, I can't seem to find it if it has been. I'm attempting to absolutely display several <div> tags, with padding and a set width/height. However, when I place them side by side, the borders overlap, and the width/height is larger than the values I've assigned. Is there some sort of formula to calculate the left, top, width and height values to make it so they do not overlap, the padding is applied, and the correct width/height is displayed (cross-browser, back to at least IE 6)? Thanks!
Similar TutorialsCan someone tell me how z-index calculated on two elements that are both absolute position I've been playing around with centering an absolutely positioned div and in this post is the method I've come up with. I've tested it in firefox and IE but am curious as to whether it works in opera and if there are better ways of doing it. The div needs to be absolutely positioned because I'm using top & bottom to set it's height. Here's the code Code: <!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" lang="en" xml:lang="en"> <head> <title>Center Test</title> <style> body { margin: 0px; height: 100%; } .centered { position: absolute; border: 2px solid black; width: 196px; background: orange; margin: auto; top: 100px; left: 0px; right: 0px; bottom: 100px; min-height: 50px; height: expression((document.body.clientHeight < 250 ? 50 : document.body.clientHeight - 200 ) + 'px'); left: expression('auto'); right: expression(((document.body.clientWidth < 200 ? document.body.clientWidth - 200: document.body.clientWidth / 2 - 100 )) + 'px'); } </style> </head> <body> <div class='centered'> I'm a centered absolutely positioned div. </div> </body> </html> The goal of the following code is to have a search box with several tabs above it to narrow down the search. The issue is that the design calls for a little upside down triangle to appear below the tab and bleed into the text box. The code works great in Firefox and even in IE6 where the Doctype was switched to HTML 3.2. I'm using 4.01 Transitional and noticing that the arrow doesn't center itself below the tab, rather it centers itself in the entire page. If I take out the width: 100% from .searchbox li.active .downarrow, then both browsers behave the same, although the downarrow now appears in the left bottom corner of the tab rather than the center. Note that I've stripped most of the code away to narrow down the issue. Code: <style> .searchbox ul { float: left; padding-left: 10px; list-style: none; padding: 0; margin: 10px 0 0 0; } .searchbox li { float: left; } .searchbox li .downarrow { display: none; } .searchbox li a { display: block; float: left; font-size: 12px; padding: 3px; color: #213327; } .searchbox li.active { position: relative; } .searchbox li.active a { color: #fff; border: 1px solid #b3b2b0; background: #266d1e url('/c2footsearchbg.jpg') repeat-x scroll top left; } .searchbox li.active a:hover { text-decoration: none; } .searchbox li.active .downarrow { display: block; position: absolute; bottom: -9px; width: 100%; height: 10px; text-align: center; margin: auto; } .searchbox div { clear: both; display: inline-block; } .searchbox input.txt { border: 2px solid #999; padding: 5px 0 0 3px; width: 305px; height: 30px; } .searchbox input.submit { font-weight: bold; font-size: 12px; color: #fff; width: 71px; height: 30px; border: 0; background: transparent url('/c2searchbutton.jpg') no-repeat scroll top left; vertical-align: top; cursor: pointer; } .searchbox input.submit:hover { background-position: 0 -30px; } </style> <div class="searchbox"> <h3>Search</h3> <ul id="c2FootSearch"> <li class="active"><a href="/index.php">Main</a><div class="downarrow">↓</div></li> <li><a href="/groups/">Groups</a><div class="downarrow">↓</div></li> <li><a href="/people/">People</a><div class="downarrow">↓</div></li> <li><a href="/petitions/">Petitions</a><div class="downarrow">↓</div></li> <li><a href="/news/">News</a><div class="downarrow">↓</div></li> <li><a href="http://www.google.com">Google</a><div class="downarrow">↓</div></li> </ul> <div> <form action="/searchall.html" method="post"> <input type="hidden" name="search" value="main" /> <input type="text" name="q" class="txt" /> <input type="submit" value="Search" class="submit" /> </form> </div> </div> What causes this? I have my small login form absolutely positioned relative to the content div, and it displays differently when there is/isn't content in it... have a look Test you can click the link to remove the data and position the bitlogin div as it is supposed to be... when the content is added, the bitlogin div moves down approx. 13px... What's the deal? Hi I need to create a base box with 9 sub elements, four boxes in each of the four corners, four edges between the corners and a center box. The problem I'm having is that I can only position the corner and edge boxes precisely if I make the base box absolute and position the sub boxes absolutely. The problem with this though is that the base box "offsetHeight" property never grows when items are added to it. The items appear in their correct position but the base box height is always zero. The only time the base box changes size is if I add text to it. Is there no way to create a box with precisely positioned sub elements that grows in depth in response to added sub divs? Thanks for any help. I have an absolutely positioned <div> containing a block of text. I have not specified a width for this <div>. This <div> is nested within another <div> for which I have specified a width of 200px. So something like: html4strict Code: Original - html4strict Code <div style="position: relative; width: 200px;"> <div style="position: absolute; top: 10px; left: 20px; z-index: 100;"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur eu purus a tellus mollis consequat. Phasellus aliquam sapien quis mauris. </div> </div> <div style="position: relative; width: 200px;"> Since the absolutely positioned <div> is not part of the page's normal flow, I would expect that its width would expand according to its contents (and the browser window's boundries). Instead, in Firefox only, the width of the absolutely positioned <div> expands only to the width of its parent - in this case 200px. Am I doing something wrong? or is there a workaround for this? I'm using a relative-positioned div as a container for an image, which is absolute-positioned. I'm doing this so that the image will automatically scale down to fit inside the containing div (nothing else I've tried has done this for me- so if there is another way to achieve this, please fill me in). This part works fine, but the image isn't as wide as the containing div, so I would like to center the image inside the div- but I can't seem to get it to work. I tried the obvious text-align:center in the div. That actually worked... kinda. The image's left-side was in the center of the div, but obviously isn't the 'centering' that I'm looking for. I then tried setting margin-left and margin-right on the image to auto, and that did nothing. I suspect that the fact that I have my image absolute-positioned is the culprit here, but I don't know how to get around it- or IF I can get around it without drastically changing my approach. Admittedly, the container div resides inside a table cell. I know that isn't the best practice, but I spent so much time trying a div-only approach only to waste time and become frustrated that I went back to what I know works- at least for now. I tried removing the container div from the table and inserting the image directly to the table cell- but encountered more issues with the sizing of the image. Essentially, my code is something like this: CSS: Code: td#CONTENTDISPLAY { width: 100%; height: 100%; text-align: left; vertical-align: top; padding: 0 0 0 0; margin: 0 0 0 0; } div#CONTENTBANNER { position: relative; height: 100%; padding: 0 0 0 0; } img.CONTENTIMG { position: absolute; height: 100%; } HTML: Code: ... <td id="CONTENTDISPLAY"> <div id="CONTENTBANNER"> <img class="CONTENTIMG" /> </div> </td> ... Nothing flashy, I know. One thing I should mention, however, is that the image is ALWAYS placed inside the container div using a Javascript function (it's a dynamic image). I doubt that makes a difference, but I figure it's worth mentioning. Can anyone help point me in the right direction? Thanks! - skubik I have a section of my application where I need a menu containing forms in a box aligned to the left. When one of these form names are clicked, I need it to unhide the div and display the proper form to the right of the menu. This works fine in Internet Explorer, but when the forms become visible in Firefox they completely cover up the menu. Here's what I've got: CSS Code: #forms .form { display: none; position: absolute; left: 0; top: 0; } #forms { position: relative; } #adminbar { float: left; border: 1px solid #000; padding: 5px; position: relative; } HTML Code: <div id="adminbar"> <a href="javascript:void(0);" onclick="hide(getElementsByClassName('form')); show('software');">Software</a> </div> <div id="forms"> <div id="software" class="form"> <h1>Software Administration</h1> <form class="ttcform"> <fieldset> <legend>New Software Item</legend> <ol> <li> <label>Software Name</label> <input type="text" size="30" name="name"/> </li> </ol> </fieldset> <fieldset class="submit" align="center"> <input type="submit" name="submit" value="Create Software"/> </fieldset> </form> <hr> <form class="ttcform"> <fieldset> <legend>Edit Software Item</legend> <ol> <li> <label>Software Name</label> <input type="text" size="30" name="name"/> </li> </ol> </fieldset> <fieldset class="submit" align="center"> <input type="submit" name="submit" value="Create Software"/> </fieldset> </form> </div> </div> Javascript (In case you need it): Code: function show(el) { if(typeof el == 'string') { document.getElementById(el).style.display = 'block'; return true; } else if(typeof el == 'object') { for(var i = 0; i < el.length; i++) { if(typeof el == 'object') { hide(el[i].id); } else { hide(el[i]); } } return true; } return false; } function hide(el) { if(typeof el == 'string') { document.getElementById(el).style.display = 'none'; return true; } else if(typeof el == 'object') { for(var i = 0; i < el.length; i++) { if(typeof el == 'object') { hide(el[i].id); } else { hide(el[i]); } } return true; } return false; } function getElementsByClassName(className) { var retEls = []; var els = document.getElementsByTagName('*'); for(var i = 0; i < els.length; i++) { if(els[i].className == className) { retEls.push(els[i]); } } return retEls } Hey everyone, I remember once reading an article on positioning everything relative when doing a float site using CSS. The problem is, if I do something like: css Code: Original - css Code html *{ position:relative; }
It seems to only apply relative positioning to absolutely nothing. Then if I do something like: css Code: Original - css Code html * *{ position:relative; }
It seems to apply anything that is an immediate child of <body> Now the real problem is, if I do something like: css Code: Original - css Code html * * *{ position:relative; }
It seems to only apply the relative positioning to grandchildren of <body>. That is to say children of children of <body>. IE: html4strict Code: Original - html4strict Code <body> <div><!-- not relative --> <p><!-- is relative --> </div> </body>
Is there way to easily set it up so that everything is relatively positioned? Hello I have a DIV (let's call it "the parent") which contains three child DIVs. Each of the children has some text in it. Neither the parent nor any of the three children have any special positioning attributes applied to them, and so the parent sizes just so that it wraps the children. So far so good. Now I want another DIV child, which when visible will completly fill the parent (using the size the parent now has because of its other three children, not stretching the parent in any way). I tried giving the parent "position:relative", and giving this fourth child "position:absolute; top:0; left:0; width:100%; height:100%", which works fine in FF but doesn't work in IE. I tried also "bottom:0; right:0" instead of the "width:100%; height:100%", still to no avail. Is there a way to make this work in IE? Is there maybe another way to make this without absolutely-positioning the fourth DIV? Cheers, Calius Sample code follows: Code: <html> <body> This is a test<br /> <div style="width:400px; position:relative; border:1px solid red;"> <div style="position:absolute; background-color:green; height:100%; left:0; top:0; width:100%;">COVER ALL</div> <div style="border:1px solid blue; margin-bottom:16px;">1</div> <div style="border:1px solid blue; margin-bottom:16px;">2</div> <div style="border:1px solid blue;">3</div> </div> This is a test<br /> </body> </html> Hello, Is there a way to have padding (say 15px) all around a cell, but allow for expections, like having one div element float:left and align far left against cell border while everything else is inset 15px. ie. Code: <style> #menubox { float:left; margin-left:15px; margin-bottom:7px; } .main_cell { padding:15px; } </style> <body> <table width=600 border=0 cellpadding=0 cellspacing=0> <tr> <td valign=top class="main_cell"><div id="menubox">table with menu items taht is achored far left against cell wall</div> Some text that wraps around "menubox" but needs to be padded around cell walls.</td> </tr> </table> </body> Thanks, Rey Hey everyone, I am making a design to kill some time, and I have come across a problem. I have a menu at the top which has no top padding unless I give it padding of 87px. I find this very odd, and it happens in every browser( Firefox 2.0.0.3, Opera 9, IE6-7 ); is it a bug in CSS itself or am I doing something wrong? Here is my code, maybe I am missing something. html4strict Code: Original - html4strict Code <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <title></title> <style type="text/css"> body { background-color: #082567; color: #FFFFFF; margin: 0; padding: 0; font-family: verdana,tahoma,"Bitstream Vera Sans",arial,helvetica,sans-serif; font-size: 12px; text-align: justify; } #top-menu { background-image: url( http://secretgeek.net/Gradient.aspx?Direction=H&Length=130&StartColor=082567&EndColor=0C39A1&Format=jpeg ); background-repeat: repeat-x; height: 130px; } #top-menu h1 { float: left; font-weight: bold; letter-spacing: -3px; font-size: 31px; padding: 5px; } #menu { float: right; list-style-type: none; text-align: center; } #menu li { display: inline; } #menu a { background-image: url( http://secretgeek.net/Gradient.aspx?Direction=H&Length=130&StartColor=082567&EndColor=0C39A1&Format=jpeg ); background-repeat: repeat-x; color: #FFFFFF; padding: 50px; } #menu a:hover { background-image: url( http://secretgeek.net/Gradient.aspx?Direction=H&Length=130&StartColor=0C39A1&EndColor=082567&Format=jpeg ); background-repeat: repeat-x; } </style> </head> <body> <div id="top-menu"> <h1>ryon.hunter</h1> <div id="menu"> <ul> <li><a href="">asdf</a></li> <li><a href="">asdf</a></li> <li><a href="">asdf</a></li> <li><a href="">asdf</a></li> <li><a href="">asdf</a></li> </ul> </div> </div> </body> </html> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" I validated it and it validates fine, any suggestions? I have a Calendar of Events that I actually made quite a while ago, and it works great, but now I'm incorporating it into a different site... I used to handle the events on the calendar with absolutely positioned spans, but I'm going to try and do something a little different (being able to have tooltip like hovers with the possibility of using lists in the hover), and you can't do that with spans... but my css doesn't seem to be behaving properly. I've got some example data, the event(bitcalevent) is supposed to sit on the bottom of the day(bitweek div), but it doesn't... when it was a span it did (though I had to add border:0 and width:100%)... maybe there is another rule that I'm not seeing that isn't letting this happen??? [edit]Note that I made the bottom -10px just so it looks ok for now... but it's like it's not separating the bottom from the top... [/edit] We don't use position absolute for anything else on our site, but it seems that our drop down still goes under some content. Here is the css: Code: #nav { background-image: url('../images/nav-full-bg.jpg'); background-repeat: repeat-x; width: 967px; height: 69px; padding: 0; margin: 0; overflow: hidden; } #nav, #nav ul { /* all lists */ padding: 0; margin: 0; list-style: none; line-height: 1; } #nav a { display:block; padding: 11px 12px 13px 12px; font-weight:bold; font-size: 13px; font-family: "Trebuchet MS", Bitstream Vera Sans, Verdana; color: #626262; margin: 0; text-decoration: none; } #nav li { /* all list items */ float: left; } #nav li ul { /* second-level lists */ position:absolute; width: 200px; left: -999em; /* using left instead of display to hide menus because display: none isn't read by screen readers */ border-bottom: 2px solid #808080; background-image: url(../images/davidpng2.png); z-index: 900; } #nav ul li { float: left; width: 10em; /* width needed or else Opera goes nuts */ } #nav li ul li a{ padding:5px; display: block; width: 190px; color: #000; font-weight:normal; font-family:verdana; font-size:11px; } #nav li ul li a:hover{ background-color:#a2c9f4; } #nav li ul ul { /* third-and-above-level lists */ margin: -23px 0 0 200px; ; } #nav li ul li ul li a{ display: block; } #nav li:hover ul ul, #nav li.sfhover ul ul { left: -999em; } #nav li:hover ul, #nav li li:hover ul, #nav li.sfhover ul, #nav li li.sfhover ul { /* lists nested under hovered list items */ left: auto; } hey guys JonnoWalmsley.com is giving me grief. I have a nav bar which is position:absolute; bottom:0px (so stuk to the bottom of the screen at all times, with the appropriate z-index etc). It works fine on FF, but IE seems to be starting from the center of the page, which effectively pushes the nav bar over to the right, and partially off the screen on smaller screens. Code: <div style="position:fixed; bottom:0px; background-color:#0a2a1a; width:899px;">...nav links...</div> I need IE to render the same as FF, and start the nav panel from the left. Any ideas? IE Screenshot FF Screenshot Hello all, I dont understand why the image placed inside the right column appears incorrect here. Please check the attachment or the following website and you will understand what I am refering. http://www.refinethetaste.com/yk/clients.asp Code: #content { float:left; width: 956px; min-height:800px; background:url(images/bg_content.gif) 0px 0px #e2eceb no-repeat; } #content #lcolumn { float:left; width:401px; } #content #lcolumn .logo { float:left; width:100%; } #content #lcolumn img.logo { float:left; width:401px; height:104px; border:0px } #content #lcolumn .head { float:left; width:100%; height:20px; background:#99adcc; } #content #lcolumn .head .text { float:left; width:100%; text-align:center; font-size: 13px; font-weight:bold; line-height:20px; color:#083684; } #content #lcolumn .main { float:left; width:361px; padding:20px; } #content #lcolumn p { font-size:15px; } #content #rcolumn { float:left; width:555px; height:505px; } #content #rcolumn img { float:left; border:0px; } Hey all, I am creating a site which sells Three 3G Mobile Phones and at the bottom of the pages i have a footer which is included into each page, see here. If you view the site in Firefox then the footer is in the correct place and rests just where the main content finishes. However in IE the footer is miles down the page creating a box effect arround the content which to be honest looks crap. If anyone would be so kind as to give me an idea why this is happening then i would be very grateful. Also, there are many sites around which give tutorials etc about text decoration and such with CSS, but i am yet to find a really good begginers tutorial on how to layout a page with CSS and Divs, does anyone know of one? Thanx for reading. CSS Code (siteInfo is the footer in question: Code: #masthead{ padding: 0px 0px 0px 0px; border-bottom: 1px solid #cccccc; width: 100%; } #navBar{ float: left; width: 15%; margin: 0px; padding-right: 2px; height: 100%; } #headlines{ float:right; width: 45%; padding-right: 2px; } #content{ float: left; width: 70%; padding: 0px 0px 0px 0px; background-color: #FFFFFF; position: inherit; } #siteInfo{ clear: both; font-size: 75%; color: #FFFFFF; padding: 10px 10px 10px 10px; text-align: center; background-color: #CCCCCC; border-top: 1px solid #107FA4; position: relative; font-weight: bold; } Edited to add CSS. Hi I've come up on the old <select> elements showing through <div>s that are made visible on top of them. What I want to do is find out the id's of the select elements under my <div> so that i can hide them using CSS / Javascript. The basic layout of my page is a grid of <select> elements, each one of these would have a hidden <div> layer associated with it containing extra information etc. By the side of each of the <select> elements is a little image / button that the user will click and the layer with the extra stuff in is made visible. The layer will overlap a number of <select> elements (not the parent <select> element). Each <div> pops up in a different position (calculated dynamically as an x,y offset from the parent) can I find the Ids of the elements it overlaps? Hope this is clear, and thanks in advance. flipflops. It seems strange to me if I begin a page with: body{text-align: center} and a following div with a wrapper: #wrapper{position: absolute; top: 0px} that this would push everything to the left or the right depending on the browser. It seems the logical thing to occur would be that the body tag would shift everything to the center and the wrapper would simply press up to the top of the screen. My problem is fixed simply by changing the position to relative for the wrapper, but I'm curious why that's the case. Thanks. |