CSS - Centering And Middling Content Of Unknown Size.
the contents of a div have an undetermined size, it varies.
I need to vertically center it as well as horizontally, which I can do the latter of. I can't use padding or margins because I don't know the size. How do I do this? Similar TutorialsHey, I have been looking EVERYWHERE for a solution and there seems to be none just quite yet. I've searched google and all sorts of help forums... and still zip, nothing. What I want to do is vertically-align the text in this example: http://www.tri-m.com/test.html in the middle of the white space. The problem though is that there is an unknown height of the whitespace because I want it to be that no matter what size you size the window, the content will always be vertically aligned... so I'm pretty stuck on how to do this. I'm needing the solution for this desperatly and I have been searching and trying everything for weeks. If anyone could help that would be VERY VERY apperciated. Thank you sooo much to everyone that tries this out. Once again here is the Example: http://www.tri-m.com/test.html Here is my code: 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" /> <title>Tri-M Systems INC.</title> <style type="text/css"> * { margin:0; padding:0; } html, body { height:100%; } body { color:#000; } #container-page { background:#fff; width:100%; min-height:100%; /* For Modern Browsers */ height:auto !important; /* For Modern Browsers */ height:100%; /* For IE */ position:relative; text-align:left; margin:0 auto; } #container-head { background:#fff; } #header { background-color:#0000FF; min-width:830px; width:expression(document.body.clientWidth < 832 ? "830px" : "auto" ); height:81px; position:relative; } #container-content { min-width:830px; width:expression(document.body.clientWidth < 832 ? "830px" : "auto" ); text-align:center; position:relative; padding: 0 0 162px 0; } #container-content:after { height:0; clear:both; display:block; content:"."; visibility:hidden; } #content-sec ul,#content-sec ul li { list-style: none none; } #container-foot { background-color:#ff0000; width:100%; min-width:830px; width:expression(document.body.clientWidth < 832 ? "830px" : "auto" ); height:162px; position:absolute; bottom:0 !important; bottom:-1px; /* For Certain IE widths */ } #foot { height:162px; } </style> </head> <body> <div id="container-page"> <div id="container-head"> <div id="header"> </div><!-- END "header" --> </div><!-- END "container-head" --> <div id="container-content"> <center> <div id="box">VERTICAL ALIGN THIS IN WHITE SPACE</div> <!-- END "box" --> </center> </div><!-- END "container-content" --> <div id="container-foot"> <div id="foot"> </div><!-- END "foot" --> </div><!-- END "container-foot" --> </div><!-- END "container-page" --> </body> </html> - Jacenta Hi, I know this may be a basic question, but I'm apparently one of the last converts from tables to css and I've been searching how to center my site within the browser window. I've currently done all my layout using css and absolute positioning... it looks great, and it sure is easier than tables... but it's as if the site is aligned to run on the left of the browser rather than the preferred center. Should I use something other than "absolute" positioning (too bad if so, because I liked the ease)? Any advice? Thanks in advance for any help. Hi: I am having trouble centering divs properly. The code I am using is below, but it seems redundant to me. I am sure there is a better way to do it. Code: <div class="clearfix"> <div style="float: left; width: 25%;"> <a href="the-family.html"><img src="images/stories/demo/mom_dad.png" width="162" height="110" style="border: 0;" /></a><br /> <h3 align=center>The Family</h3> <a href="the-family.html">Read more...</a> </div> <div style="float: left; width: 25%;"> {arifancybox activeType="flickr" type="customtext" source="photoset" photosetId="72157624434792497" apikey="166cd0f079225ba7aa06e3ec838f6e62"}<img src="images/stories/galleries/tehran-gallery.png" width="220" height="110" alt="tehran-gallery" title="Click for a slideshow." /> <h3 align=center>The City of Tehran</h3> <p align=center>View the Gallery</p>{/arifancybox} </div> <div style="float: left; width: 25%;"> {arifancybox activeType="flickr" type="customtext" source="photoset" photosetId="72157624564172740" apikey="166cd0f079225ba7aa06e3ec838f6e62"}<img src="images/stories/galleries/rasht-gallery.png" width="220" height="110" alt="rasht-gallery" title="Click for a slideshow." /> <h3 align=center>The City of Rasht</h3> <p align=center>View the Gallery</p>{/arifancybox} </div> <div style="float: left; width: 25%;"> {arifancybox activeType="flickr" type="customtext" source="photoset" photosetId="72157624427151309" apikey="166cd0f079225ba7aa06e3ec838f6e62"}<img src="images/stories/galleries/gilan-gallery.png" width="220" height="110" alt="gilan-gallery" title="Click for a slideshow." /> <h3 align=center>Gilan Province</h3> <p align=center>View the Gallery</p>{/arifancybox} </div> </div> Basically, I have a div which encloses 4 other divs. These 4 divs are each defined as "width: 25%", thus combined they take up 100% of the enclosing div. What I want is to center the content of each of those 4 divs. The content is both text and image. Should be a rather simple thing to do, and thus eliminate my need to individually center each element within the small 25% wide div. Any help would be appreciated. Thanks. I'm working on my first website. Its a simple portfolio site. I have it mostly completed, but i would like to center all the content in the browser. I found several soulutions to this and I can not seem to get any of them to work. I think it might be stemming from my use of absolute posistioning, but idk, just a newbie here. here is the html; Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Rot</title> <link rel="stylesheet" type="text/css" href="style.css"> <style type="text/css"> </style> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" > </head> <body> <div id="wrapper"> <div id="logo"><a href="index.html"><img border="no" src="text/logo.png" alt="logo"></a></div> <div id="rot"><a href="index.html"><img border="no" src="text/rot.png" alt="rot"></a></div> <a href="info.html" class="info" title="info"><span class="displace">info</span></a> <div id="work"><a href="index.html"><img border="no" src="text/worksolid.png" alt="work"></a></div> <a href="projects/dreaming_again.html" class="thumb1" title="thumb1"><span class="displace">project1</span></a> <a href="projects/futility.html" class="thumb2" title="thumb2"><span class="displace">project2</span></a> <a href="projects/grid_dreams.html" class="thumb3" title="thumb3"><span class="displace">project3</span></a> <a href="projects/transgress.html" class="thumb4" title="thumb4"><span class="displace">project4</span></a> <a href="projects/curls.html" class="thumb5" title="thumb5"><span class="displace">project5</span></a> <a href="projects/city_sleeps.html" class="thumb6" title="thumb6"><span class="displace">project6</span></a> <a href="projects/inner_turmoil.html" class="thumb7" title="thumb7"><span class="displace">project7</span></a> <a href="projects/transitions.html" class="thumb8" title="thumb8"><span class="displace">project8</span></a> <a href="projects/detritus.html" class="thumb9" title="thumb9"><span class="displace">project9</span></a> <a href="projects/emerald_city.html" class="thumb10" title="thumb10"><span class="displace">project10</span></a> </div> </body> </html> and here is the CSS Code: #wrapper { text-align: left; width:990px; margin:0px auto; /* Right and left margin widths set to "auto" */ text-align:left; /* Counteract to IE5/Win Hack */ padding:0px; border:1px dashed #333; background-color:#eee; } a { outline: none; } #logo{ position:absolute; top:15px; left:645px; } #rot{ position:absolute; top:30px; left:733px; } #work{ position:absolute; top:375px; left:15px; } #info{ position:absolute; top:285px; left:15px; } a.info { position: absolute; top:285px; left:15px; display: block; width: 75px; height: 75px; text-decoration: none; background: url("text/info.png"); } a.info:hover { background-position: 0 -75px; } .displace { position: absolute; left: -5000px; } a.work { position: absolute; top:375px; left:15px; display: block; width: 75px; height: 75px; text-decoration: none; background: url("text/work.png"); } a.work:hover { background-position: 0 -75px; } .displace { position: absolute; left: -5000px; } /* * thumb1+++++++++++++++++++++++++++++++++++ */ a.thumb1 { position: absolute; top:105px; left:105px; display: block; width: 615px; height: 75px; text-decoration: none; background: url("images/thumbs/dreaming_again.jpg"); } a.thumb1:hover { background-position: 0 -75px; } .displace { position: absolute; left: -5000px; } /* * thumb2+++++++++++++++++++++++++++++++++++ */ a.thumb2{ position: absolute; top:195px; left:105px; display: block; width: 615px; height: 75px; text-decoration: none; background: url("images/thumbs/futility.jpg"); } a.thumb2:hover { background-position: 0 -75px; } .displace { position: absolute; left: -5000px; } /* * thumb3+++++++++++++++++++++++++++++++++++ */ a.thumb3{ position: absolute; top:285px; left:105px; display: block; width: 615px; height: 75px; text-decoration: none; background: url("images/thumbs/grid_dreams.jpg"); } a.thumb3:hover { background-position: 0 -75px; } .displace { position: absolute; left: -5000px; } /* * thumb4+++++++++++++++++++++++++++++++++++ */ a.thumb4{ position: absolute; top:375px; left:105px; display: block; width: 615px; height: 75px; text-decoration: none; background: url("images/thumbs/transgress.jpg"); } a.thumb4:hover { background-position: 0 -75px; } .displace { position: absolute; left: -5000px; } /* * thumb5+++++++++++++++++++++++++++++++++++ */ a.thumb5{ position: absolute; top:465px; left:105px; display: block; width: 615px; height: 75px; text-decoration: none; background: url("images/thumbs/curls.jpg"); } a.thumb5:hover { background-position: 0 -75px; } .displace { position: absolute; left: -5000px; } /* * thumb6+++++++++++++++++++++++++++++++++++ */ a.thumb6{ position: absolute; top:555px; left:105px; display: block; width: 615px; height: 75px; text-decoration: none; background: url("images/thumbs/city_sleeps.jpg"); } a.thumb6:hover { background-position: 0 -75px; } .displace { position: absolute; left: -5000px; } /* * thumb7+++++++++++++++++++++++++++++++++++ */ a.thumb7{ position: absolute; top:645px; left:105px; display: block; width: 615px; height: 75px; text-decoration: none; background: url("images/thumbs/inner_turmoil.jpg"); } a.thumb7:hover { background-position: 0 -75px; } .displace { position: absolute; left: -5000px; } /* * thumb8+++++++++++++++++++++++++++++++++++ */ a.thumb8{ position: absolute; top:735px; left:105px; display: block; width: 615px; height: 75px; text-decoration: none; background: url("images/thumbs/transitions.jpg"); } a.thumb8:hover { background-position: 0 -75px; } .displace { position: absolute; left: -5000px; } /* * thumb9+++++++++++++++++++++++++++++++++++ */ a.thumb9{ position: absolute; top:825px; left:105px; display: block; width: 615px; height: 75px; text-decoration: none; background: url("images/thumbs/detritus.jpg"); } a.thumb9:hover { background-position: 0 -75px; } .displace { position: absolute; left: -5000px; } /* * thumb10+++++++++++++++++++++++++++++++++++ */ a.thumb10{ position: absolute; top:915px; left:105px; display: block; width: 615px; height: 75px; text-decoration: none; background: url("images/thumbs/emerald_city.jpg"); } a.thumb10:hover { background-position: 0 -75px; } .displace { position: absolute; left: -5000px; } Seems to be a recurring theme today. I'm trying to skin osCommerce to match the site. If you go into the front page of the store you'll see the problem. All content is correctly centered in FF, but not in IE. I tried putting a "wrapper" div around all the content (starts immediately after body tag and ends immediately before endbody tag), and set its margins to 0 auto, but no luck. Code: #wrapper { width: 760px; margin: 0 auto; } Any ideas? Hello, I recently constructed a web page that used z-index property's to stack some transparent PNG files on top of each other. This worked great for me, however there was one thing that bothered me. I couldn't properly center my content after the z-index property was used. I could only manually position the content using left and right x,y co-ordinates. Has anyone discovered a proper way for centering z-index content? -Ben Found lots of similar threads, but not exactly the same problem... Any ideas how I can get the main content to stay centered along with the background on my site: http://gumbald.co.uk It works fine in FF, but not in IE, so I'm guessing it's a CSS issue My CSS: Code: /*Default CSS file*/ /*Formats <html> tag*/ html { height: 100%; overflow: -moz-scrollbars-vertical; background-color: #BBF; } * html #wrap { height: 100%; } /*Formats links to set colors, actions*/ #wrap a:link { color: #0054A6; text-decoration: none; } #wrap a:visited { color: #0054A6; text-decoration: none; } #wrap a:hover { color: #828282; text-decoration: none; } #wrap a:active { color: #000000; text-decoration: none; } /*Formats <body> tag*/ body { font: 65% 'trebuchet ms', arial, helvetica, sans-serif; min-height: 100%; width: 640px; margin: auto; padding: 0; background-color: #FFFFFF; border: 0px solid red; } /*Formats <h1> tag*/ h1 { font: 300% 'trebuchet ms', Arial, Helvetica, sans-serif; color: #00f; padding-top: 0px; margin: 0; } h2 { font: 130% 'trebuchet ms', Arial, Helvetica, sans-serif; padding-top: 6px; } /*Formats images, is class so can be reused on same page*/ .imgLeft { float: left; padding-right: 10px; padding-bottom: 0px; margin-top: 0px; } .imgRight { float: right; padding-left: 10px; padding-bottom: 0px; margin-top: 0px; } /*Wraps all Divs Up*/ #wrap { position: relative; min-height: 100%; width: 640px; margin: auto; background: top left repeat-y; } /*Deals with head navigation bar*/ #headwrap { } #logo { padding-left: 0px; text-indent: 10px; width: 100%; height: 42px; background: #BBF repeat center; text-align: left; } #navbar { text-indent: 10px; padding-left: 0px; width: 100%; font: 110% 'trebuchet ms', Arial, Helvetica, sans-serif; margin: auto; height: 16px; padding-top: 2px; padding-right: 0px; color: #000; text-align: left; background: #DCDCDC repeat-x; border-bottom: 1px solid #ccc; } #navbar li { display: inline; padding-right: 10px; margin: 0; } #navbar ul { padding: 0; margin: 0; } /*Deals with side navigation bar*/ #sidenavbar { float: left; width: 100px; margin-top: 0px; text-align: center; background: #DCDCDC; } /*Deals with main page content*/ #mainwrap { padding-bottom: 0px; } #mainwrap:after { display: block; clear: both; } #content { position: relative; margin-left: 6px; margin-right: 6px; padding: 0 10px; text-align: justify; } /*Deals with the footer*/ #footwrap { clear: both; height: 68px; } #footer { position: absolute; bottom: 0; height: 40px; background: #0054A6 repeat center; width: 100%; color: #FFF; text-align: center; margin: 0 auto; } #footnavbar { position: absolute; bottom: 40px; font: .95em 'trebuchet ms', Arial, Helvetica, sans-serif; width: 100%; height: 28px; padding-top: 8px; color: #000; text-align: center; background: #DCDCDC repeat-x; border-top: 1px solid #ccc; } #footnavbar li { display: inline; padding-right: 10px; margin: 0; } #footnavbar ul { padding: 0; margin: 0; } Hey everyone. I have a parent div that I write to using javascripts innerHTML. It works fine for text and <p>'s and stuff, but if I fill it with other div's it doesn't grow accordingly... For example this would work... <div id="parentDiv"> <p>this parentDiv div would grow and grow as i add more stuff</p> </div> This next example doesn't seem to work.... <div id="parentDiv"> <div id="childDiv"> <p>why won't parentDiv grow as its childDiv grows!!?!?!?</p> </div> </div> Should this work? Thoughts? i have a base page that i use for a multi-page site, but i'd like to be able to insert more and more content, and have the page size accordingly. i think the problem is that the content is technically floating...or something, it's a cold fusion search result in a cart. i don't know, i might be asking for a miracle here- if you have an idea, let me know. Hi, Can anyone recommend how best to how to dynamically constrain amount of Text/Content in a DIV area that can vary in size?? That is, say you have: (a) a content (DIV) area on your view that can expand/contract depending upon browser size ( i.e. when someone is re-sizing the browser window) and (b) dynamic text/content that is to be displayed, based upon user input - e.g. image a defined area/size for several user comments for example. Users can create their own comments, but you only want them to be able to take up a given amount of screen resource, and then perhaps have a "...more" link at the bottom if they go over. How can I best setup this up? e.g. (1) How to setup the layout/CSS so that if more text / content is present in the DIV area that can be displayed that the DIV area doesn't expand due to the extra content the user put forward, and/or (2) Do I need to also complete this by programming what content comes out? E.g. in Ruby on Rails say then the question would be how to calculate how much text/content can fit in the current size of the DIV (noting browser re-sizing) so that you get the chance to put the "...more" link at the bottom? Hopefully this approach isn't required. Any other suggestions welcome that address what I'm trying to do are welcome, which is really offering a area for display of user feedback where each piece of feedback has a maximum area it can take on the main screen only, and also that browser re-sizing is possible. Tks Greg When content exceeds the window size, the fixed footer covers it. The center div has a min-width, the right div covers it when the window is resized to smaller than the min. (Also, center div drops in IE). I have googled these issues and searched the archives. I've tried many different techniques for getting these things in order, and this is the closest I've gotten so far. What I want: 1.A footer that sticks to the bottom of the viewport if there is not enough content AND stays below the container when the container is longer than the viewport. 2. The center div to be liquid with a min-fixed width and the right div to move along the edge of the center div and not cover it when viewport is sized smaller than the center div's min width. Here is a simplified version of the HTML (none of the extra divs that are used to make rounded corners) 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=iso-8859-1" /> <title>Troubleshooting</title> <link rel="stylesheet" href="layout8.css" type="text/css" /> <link rel="stylesheet" href="round.css" type="text/css" /> </head> <body> <div id="header"> <div id="masthead"></div> <div id="topnav"><div class="searchbar">Search</div> <div class="homebar"><span>Home </span></div></div> </div> <div id="container"> <div id="left"></div> <div id="right"></div> <div id="content"></div> </div> <div class="clear"> </div> </div> <div id="footer"></div> </body> </html> I think there's too much CSS to post here, but everything can be found at: www. observera. com/troubleshootingpage/index. htm CSS @ layout.css and round.css I appreciate any help you can offer Em Hi there, I'm completely new to CSS. I'm trying to do this more than one hour but can't get it right. Code: <font color='white'><font size='1' face=verdana size=1> I couldn't find the equivalent of this in CSS This is my last experiment but it doesn't seem to work either Code: fontstyle { color : #FFFFFF; font-family : verdana ; font-size :1;} Thanks Hi guys, I have a small problem which is driving me crazy. I have a main container with two containers inside named left and right. I want a border on the main container, but i do not know the height of the main container as this will depend on the content in 'left' and 'right'. So what should I set the height of the main container to? I've tried 100% but this does not work and if I omit the geight property the main container does not show up. Any ideas? Thanks in advance, Rob. As soon as I add this code for the rule, the apple on left side drops below the rule. It belongs in the upper left corner. #body #rule { margin-top: 100px; align: center; spartaumc.com/contact_us2.html spartaumc.com/SpryAssets/sparta3.css So when using Netscape 7.2 & Opera 7.5 and MSIE 6.0, How do you get a simple tag like body { font-size:small; } to be equal in all browsers? Setting IE Text Size to Medium, and Opera's Zoom to 100% (both defaults) and Netscape 7.2 to 120% (not the default) is one way, but is there a CSS way? By the way, the child element hack "body>div {property}" wasn't working no matter what I tried, by not working I mean to say Netscape never would read it or apply it. It appeared to be that Opera & IE need to read the same value while Netscape needs to apply a larger size to be equal to IE's and Opera's rendering. B I could see this as potentially being really easy to do or really hard to do. I'm hoping for the former. Suppose I have 3 divs, A, B, C and that I want the total width of A + B + C to equal the width of the screen. Suppose also that I want them to be inline. How can I have B to be a fixed width while A and C expand depending on the screen width (such that the width of A = the width of C)? I've been trying for almost a week now to sort out the problem in this coding but I just can't establish it I've tried removing the apostrophes from the id's, altering the ' marks into every possible variant I've been able to find, and I startedrebuilding it piecemeal but after the first 4 worked I copied it in in blocks of 3 and it then failed. I'm reserving the completely singular addition of each new field until after I've had someone who knows the language look at it and help. Really stuck My code is too long to post here so I've left it visible here webjam.com/thewarlords/help It works flawlessly with only the first 3. Even if I fill the entire table with them. It's only when I introduce the whole terms in bulk it fails. Is there an upper limit to the amount of fields allowed? I am currently having to deal with a mystery padding at the bottom of each of my im_container tags... everything is set to 0px, and oddly enough... it looks GREAT in IE (ugghh... i can't believe i just said that)... it doesnt however look good in firefox... whats up... here is the XHTML followed by the CSS.. Code: <div class="im_left"> <div class="im_container"> <div class="im_logo"><img src="/images/im_icq.gif" alt="Contact Via ICQ" /></div> <div class="im_info"> 164149536 </div> <div class="clear"></div> </div> <div class="im_container"> <div class="im_logo"><img src="/images/im_aim.gif" alt="Contact Via AIM" /></div> <div class="im_info"> Incomplete Gamer </div> <div class="clear"></div> </div> </div> Code: .im_left {float:left; width:270px;} .im_container { margin:0 0 0 30px !important; border:1px solid #900; } .im_container a:link, .im_container a:visited, .im_container a:active, .im_container a:hover {color:#FFF;} .im_logo { margin:0px 0 0 0; float:left; width:30px; margin:0px; padding:0px; } .im_logo img {border:0px; margin:0px; padding:0px;} .im_info { font-size:12px; font-family:Verdana, Arial, Helvetica, sans-serif; margin:0 0 0 5px; text-align:justify; width:200px; float:left; } .im_title { text-align:center; font-weight:bold; } Hi there, I have a content glider script, but I have added it to a wrapper with a background image. The css is using a white background colour so when a new layer is glided up, it covers the one underneath it. However, I want the background to be transparent to show the background image underneath.... If I remove the white background, they layers become transparent and overlay each other, so you can see all text in the layers on top of each other making it impossible to read. Is there anyway I can make it so it has a transparent background, but so it will not show the content under the new slide? This is my CSS: PHP Code: .glidecontentwrapper{ position: relative; /* Do not change this value */ height: 230px; /* Set height to be able to contain height of largest content shown*/ overflow: hidden; } /* Total wrapper width: 350px+5px+5px=360px Or width of wrapper div itself plus any left and right CSS border and padding Adjust related containers below according to comments */ .glidecontent{ /*style for each glide content DIV within wrapper.*/ position: absolute; /* Do not change this value */ background: white; visibility: hidden; width: 330px; } /* Total glidecontent width: 330px+10px+10px=350px Or width of wrapper div itself (not counting wrapper border/padding) */ .glidecontenttoggler{ /*style for DIV used to contain toggler links. */ width: 360px; margin-top: 6px; text-align: center; /*How to align pagination links: "left", "center", or "right" background: white; /*always declare an explicit background color for fade effect to properly render in IE*/ } Any help would be great! Thanks. |