CSS - Sidebar Alignment Question
I would like to have a sidebar that vertically stretches to the height of its wrapper div. The sidebar contains two divs (a menu and a graphic) one of which is aligned to the top of the sidebar and one of which is aligned to the bottom. Thus when the sidebar stretches vertically, the space in between the menu and the graphic stretches.
I currently have a floated sidebar with a fixed width and relative postion. That sidebar is in a wrapper div that is also relatively positioned. There is a menu and a graphic (#mascot) inside of the sidebar. My current CSS only allows the sidebar to be vertically as big as the two items in it. Here is my CSS: Code: #wrapper { padding:0px; margin:5px auto 10px auto; border:solid 1px white; border-collapse:collapse; width: 800px; height:100%; position:relative; } #sidebar { margin:0px; padding:0px; width:220px; float:left; background:url(_images/team/bg_nav.jpg); position:relative; } #sidebar #menu { margin:0px; padding:0px; border:solid 1px #000; } #sidebar #mascot { margin:0px auto; padding:10px; text-align:left; background:url(_images/team/bg_mascot.jpg); font-size:10px; font-weight:normal; font-family:Arial, Helvetica, sans-serif; color:#000; text-align:center; border:solid 1px #000; } #mainContent { margin:0 2px 0 222px; background:#FFF; padding: 10px; } #footer { margin:0px; padding:0px; width:100%; background:url(_images/team/bg_footer.jpg); font-size:10px; font-weight:normal; color:#FFF; text-align:center; } I would really appreciate any help as I am relatively new to CSS. If the code is confusing I'd be happy to expound on anything. Thans in advance, Brian Similar TutorialsHi, I have made myself some ugly css code (just got started so this is my first try) that gives me a floating sidebar on my right side. This sort of works for IE6 (that most of my friends use) and I don't even dare to think about the look of it in another browser... So I would greatly appreciate some advice regarding improvements of the following code... Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <style type="text/css"> <!-- @media screen { html {overflow:hidden;} body {height:100%; overflow:auto; margin:0; padding:0; color: white; background-color: #333;} #container {position:fixed; margin-top:30px; margin-right:auto; margin-bottom:30px; margin-left:auto; width: 1000px; padding:10px; background-color: black; border: 1px solid white;} #header {position:fixed; margin-top: 0px; margin-right: 99px; margin-bottom: 10px; margin-left: 99px; height:60px; padding:0px; background-color:red; border: 1px solid white;} #sidebar {position:relative; width:178px; height:150px; left:10px; top:0px; padding:5px; background-color:blue; border: 1px solid white;} #intro {float:left; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; height:150px; width:788px; padding:5px; background-color:green; border: 1px solid white;} #content {margin-top: 10px; margin-right: 200px; margin-bottom: 10px; margin-left: 0px; padding:5px; background-color:green; border: 1px solid white;} #navbar {margin-top: 0px; margin-right: 99px; margin-bottom: 0px; margin-left: 99px; height:75px; padding:0px; background-color: red; border: 1px solid white;} } //--> </style> </head> <body> <div id="container"> <div id="header">A NICE HEADER</div> <div id="intro">A USEFUL AREA FOR SECTION INTRODUCTION </div> <div id="sidebar">TEST1<br>TEST2<br>TEST3</div> <div id="content"><b>lot's of nasty things...</b> <br><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br><br> </div> <div id="navbar">MY GLORIOUS NAVIGATION BAR</div> </div> </body> regards /twinkle Hello and thanks for your patience. I have a page here that is having a positioning problem for "sidebar2". I can't seem to get it to stick to that right side of the page in a fixed position. Code: @charset "UTF-8"; * { margin: 0px; padding: 0px; } body { text-align: center; font-family: Arial, Helvetica, sans-serif; font-size: 0.8em; color: #32240C; line-height: 1.5em; } a:link { color:#C42617; } a:hover { color: #687ABB; } a:visited { color:#C42617; } a:active { color: #687ABB; } h2 { font-size: 1.2em; line-height: 2.3em; color: #34260b; border-left-width: thin; border-left-style: double; border-left-color: #34260b; text-indent: 10px; background-repeat: no-repeat; } #clear { clear: both; } #welcome { color: #325084; float: left; width: 590px; text-align: left; padding: 15px; border: thin solid #D0DAEF; background-color: #FFF; margin-left: 25px; margin-right: 5px; } #welcome h2 { padding-left: 2px; } #welcome p { padding-left: 2px; } input { width: 185px; } /* reset width for non-text inputs */ input.radio, input.checkbox, input.submit, input.dropdown { width:auto; } /* display labels next to form elements add a class for when you want them to stack */ label { float: left; margin-right: 1em; } label.top { display: block; float: none; } .sidebar2 { position:absolute; top:182px; right: 150px; text-align:left; width: 255px; padding-top: 0px; padding-right: 0; padding-bottom: 10px; padding-left: 10px; margin-top: 0px; } .sidebarheader { color:#D75500; padding-bottom: 5px; font-weight: bold; font-style: italic; font-size: 16px; } ul { list-style: none; margin: 0; padding: 0; } img { border: none; } /*- Menu 3--------------------------- */ #menu3 { width: 250px; border-style: solid solid none solid; border-color: #BCD2E6; border-size: 1px; border-width: 1px; margin-top: 0px; margin-right: 10px; margin-bottom: 10px; margin-left: 0px; font-size: 12px; } #menu3 li a { height: 32px; voice-family: "\"}\""; voice-family: inherit; height: 24px; text-decoration: none; } #menu3 li a:link, #menu3 li a:visited { color: #325084; display: block; background: url(menu3.gif); padding: 8px 0 0 10px; } #menu3 li a:hover { color: #627EB7; background: url(menu3.gif) 0 -32px; padding: 8px 0 0 10px; } #affiliates { color: #325084; float: left; width: 580px; text-align: left; margin-left: 25px; margin-right: 15px; } #affiliates table td { padding: 15px; } Can you tell me how format that div? Hi Guys, I'm trying to get a messaging app done and I need the CSS polished up. I understand CSS enough to hack my way through it, but for some reason I can't get the following done. Here's what I'm trying to create. This will be placed within an existing div that is 550px wide. I see 5 total divs that need to be created. The containing div, which is the thick border around the entire image. The profile pic div the name div the timestamp div the message div The containing div can't be height restricted. The profile pic div, name div, and timestamp div need to stay at the top. The message div will need to grow (height-wise) div.view_message_block { width: 550px; (or 100% since the containing div is already set to 550px?) margin: .5em .5em .5em .5em; display: inline; } div.view_message_profile_pic { width: 75px; display: inline; float: left; } div.view_message_sender_name { width: 80%; display: inline; float: left; } div.view_message_date { width: 20%; display: inline; } div.view_message_body { width: 80%; display: inline; } -------------------------------------------------------- Any help or guidance will be appreciated! Don't want it done for me, but I'm not sure where to go from here. I want some text aligned left, then some text aligned center, then some more text aligned right all on the same line. Should I use tables, divs, or is there a better way? Thanks Ok ive never really used this effect on any of my designs but i would like to. How do i make a <td> background color change on mouse over with css?? and also how would i align an image to the bottom right or bottom left part of a paragraph, i allready know how to do it to the top right and top left. thanks in advance. its not so much of a problem because i have "thought" of a remedy (at the end of the post) but i was looking for perhaps a more css'esque solution? if you go here http://www.zahra-zahra.com/fullpage.html you will see menus in the middle somewhere and you will see when the lis go on the second line they are mismatched.. is there a way to match them up precisely? now the solution which i was thinking was is that to have four arrays and then put them in four divs and then place them side by side. btw: the menu will be stored in database I'm trying to have a sidebar to the right of my page content that extends the entire height of the container it is in. Code: .sidebar { padding: 0px; margin: 0px; width: 150px; height: 100%; color: #999999; background: #ffffff; float: right; border-top: none; border-left: 1px solid #cccccc; border-bottom: none; border-right: none; } This is the code I am currently using, but it is only as tall as the contents of the div. I need the border on the left to extend the length of the container it is in. Any ideas? Thanks, Scott I am working on a site in CSS (first time! Yay!) I am having one problem: there is a sidebar, and I have used spacer images to make the coloring go to the very bottom of the page (the links stop above that). HOWEVER: this is for my screen size, and I am worried that when people view it with a different screen/window size, they will have scroll bars, even though there is no content at the bottom. Is there any attribute that will make it just go right to the bottom? Thanx. I have three questions. 1. I saw some site which cut if there is a wide picture on side bars, like it just show the part which is on the sidebar box if its wider it cuts the extra part like this site if you see the first picture on the side bar its bigger but it cuts the extra part (-http://dot21.blogspot.com/-) , i want to know how to do it. 2. When some people add backgrounds they write background-repeat:no-repeat whats the function of that code??? and what can i write instead of no-repeat?? 3. whats the function of this code (background-position:bottom left) ??? If you couldnt answer some i hope you answer the ones you know. I'm a bit of a CSS newbie but I try. How do you get the sidebars' height to synchronize with the height of your content? I tried height=100% but it doesn't seem to work. If I put a lot of text in my content, it stretches down but the sidebars remain the same height, making the layout looking ugly. I don't want to have to press enter in my sidebars to match the content's height all the time! Here's my code: <style type="text/css"> #container { width: 100%; border: 1px solid gray; margin: 0px auto; } #banner { padding: 0px; background-color: #CDC8F1; } #content { padding: 5px; background-color: #FFFFFF; } #sidebar-a { float: left; margin: 0; padding: 0px; background-color: rgb(235, 235, 235); height: 100%; } #sidebar-b { float: right; margin: 0; padding: 0px; background-color: rgb(235, 235, 235); height: 100%; } #footer { clear: both; padding: 5px; background-color: rgb(213, 219, 225); } body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } </style> Hello, this is my first time posting here. I am having a problem with a CSS sidebar. You can view the page at this URL: http://approg.msu.edu/david/ccsac/index2.htm. For the life of me, I cannot get the sidebar to automatically extend to the length of the page. Obviously, it's not much of an issue at the URL I listed, but it makes a bigger difference when there is a lot of content on the page. I'm sure the solution is simple, I just need to be pointed in the right direction. Thanks. I know this probably has a really simple answer but how do I make it so the sidebar is on the right side of the content box on a WordPress theme? Here is what it looks like right now: http://reptilenewsstation.1sthoster.com/ The sidebar is below the content box and I want it to be on the right side of the content box. I know the theme sucks right now but this is my first WordPress theme and I want to set everything up in the correct places before I start getting into really styling it. i have created a new model for a 3 column layout, (left sidebar, main content, right sidebar) i used yui 3.0 index.php page as an example to float the main column right. this is designed to put the main column to static so that it is liquid, with a min width. im not working with a liquid layout however, so some adjustments are needing to be made. my site is 950 pixels wide. my sidebars are about 175 pixels each, when used. i have 2 classes that i append to the main column style depending on wether a left sidebar will be used or not. so when i set the #mainColumn for class .marginForLeftNav then it will accomodate for the left nav bar to pop up into place. if no left sidebar, then i use #mainColumn . marginForNoLeftNav class. The problem i am having is trying to accomodate the right sidebar, which will always be used. my requirements a 1) that the side bar html code falls below the main column code on the html page. so essentially i need to leave room in teh mainColumn for these columns to pop up into place. 2) that the styles used to float the left sidebar, and the main column are left in tact if possible. heres some code Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- #wrapper{ /* Wraps everything. Glues header, centralContainer, and footer together */ margin: auto; width: 950px; text-align: left; } #header { margin: 0; position: relative; background-color: #666; } #centralContainer { /* Glues left and right columns, and main area together */ zoom: 1; } #mainColumnWrapper { margin-left: -195px; overflow: hidden; float: right; } #mainColumn { margin-left: 195px; background-color: #999; position: relative; width: 560px; } #mainColumn .marginForLeftNav { } #mainColumn .marginForNoLeftNav { left: 0px; width: 755px; margin-right: 195px; } #leftColumn { float: left; width: 175px; position: relative; margin: 0; padding: 0; background-color: #CCC; } #rightColumn { width: 175px; margin-left: 775px; background-color: #CCC; position: relative; } #footer { color: #666666; font-size: 80%; border-top: 1px solid #333333; clear: both; padding-top: 10px; background-color: #FFF; } body { background-color: #333; } --> </style> </head> <body> <div id="wrapper"> <div id="header">header</div><!-- end header --> <div id="centralContainer"> <div id="mainColumnWrapper"> <div class="marginForLeftNav" id="mainColumn" > <p>main column, with class narginForLeftNav</p> <p> </p> <p> </p> <p>test</p> </div><!--end <div id="mainColumn" class="marginForLeftNav"> --> </div><!--end <div id="mainColumnWrapper"> --> <div id="leftColumn">left column area</div> <div id="rightColumn">right column area</div><!-- end rightColumn div --> </div><!-- end centralContainer --> <div id="footer">footer</div><!-- end footer --> </div><!-- end wrapper --> </body> </html> ive adjsuted the background colors to help see what is going on this is as close as i have gotten it so far. NOTICE, how the main column overflows behind the right sidebar, which makes the content in the right sidebar begin AFTER the bottom of the main column. this is obviously the main problem. I need the main column to obey the right sidebar, depending on wether theres a left sidebar or not. Hi all, At http://www.bartlett-family.net/chrisbartlett/blog2/ I have recently changed the entire layout and replaced it all with new images, BG, etc. In IE... On the right, the sidebar and BLOG searchform are all a little too far to the right. I've been playing with it all for a while, but can't seem to move it to the left. I basically just need to shift the entire righthand contents about 10 or 20 px to the left, but I need to avoid that also changing the righthanded content on all the other pages. Actually, in FF it is correct, except that the BLOG searchform bar needs to com over about 10-20px to the left. Other than that, it's perfect. I need to make IE look like that! CSS file is at http://www.bartlett-family.net/chrisbartlett/main.css I'd appreciate any help. Thank you! Chris Hello everyone. I am working in wordpress trying to make a web site. I am pretty new to wordpress and i have basic CSS and HTML knowledge so i need some help with this. The website: Code: http://sitesuperhostdemo.com/m2/ 1. The #sidebar-1-wrap. The problem i am having is the sidebar. As you can see on the page the sidebar (#sidebar-1-wrap) is positioned under the content but i would want it to stand beside the content (#home-content). 2.The #content-sidebar-wrap. I didnt add this container it is built into wordpress but the problem is that anything i add in wordpress -> pages -> Home page is for some reason placed inside the #content-sidebar-wrap but i have no idea why. The #content-sidebar-wrap is streching my page down because it contains the sidebar but starts at the top of the default wordpress content and i am clueless as to how i can change it so it doesent include all the content i place on the page. I would like it to only contain #sidebar-1-wrap and if i am correct i assume i can then place the sidebar next to the content and stop the div from extending my page. 3. The sidebar position. I can for example set the following code to the #sidebar-1-wrap: Code: .home_page #sidebar-1-wrap { position: relative; top: -615px; left: 40px; } but there must be a better way. Also doing this doesent change the #content-sidebar-wrap. It still extends the page down as if the sidebar is still under the content. This would maybe work if i knew how to change the content so it isnt inside #content-sidebar-wrap but i see no way of doing it. Someone help please before i blow my brains out. If anyone needs clarification on anything lmk and ill clarify. Here's the main site: http: // anomalyrecords . net / index . html Here's the sto http: // anomalyrecords . net / catalog I am using a Zencart embedded template to wrap the main site design around Zencart.. This is working perfectly with a small remaining issue.. I am trying to synchronize the content placement of the sidebar items between Zen Cart and the rest of the site pages.. There is an ever so slight "shift" of the sidebar elements when you toggle bewteen the site pages and the store.. I've done a lot of tweaking and I'm fairly close, but I am at a COMPLETE loss how to put this to bed once and for all. I am hoping one of the CSS gurus here will see what I am clearly missing and guide me back to the light.. Greetings! This is my first time with using css and I'm going out of my mind trying to fix a floating sidebar. As you can see from the included jpeg, I want the sidebar and main content areas to float flush with the navigation bar. But for some reason, my right sidebar keeps getting pushed down. Any thoughts would be appreciated. Thanks! Devon picture of what it should look like:themorphememan.com/personalstuff/website-design.jpg code:themorphememan.com/personalstuff/index.html Hi all, noob here. I am trying something pretty simple but just cant get it to work. For my site, I have a main content area and two right sidebars. I am trying to decrease the width of the the content area and widen the sidebars to fill the extra space created, say 50px. I have come unstuck trying to get it done though. Below is the relevant part of the css: Code: /* CONTENT layout */ #content { float: left; width: 100%; padding-bottom: 2em; } .sidebar-double #content, .sidebar-left #content { margin-left: -221px; } .sidebar-double #content, .sidebar-right #content { margin-right: -271px; } .sidebar-right-double #content { margin-right: -448px; } /* Add blanks left and right for the sidebars to fill */ .sidebar-double #squeeze, .sidebar-left #squeeze { margin-left: 221px; } .sidebar-double #squeeze, .sidebar-right #squeeze { margin-right: 271px; } .sidebar-right-double #squeeze { margin-right: 448px; } /* Add whitespace to content area */ #squeeze { padding: 1em 0 1.5em; overflow: hidden; } .sidebar-double #squeeze, .sidebar-left #squeeze { padding-left: 2em; } .rightbar #squeeze { padding-right: 2em; } /* SIDEBAR layout */ #sidebar-wrapper .sidebar { float: left; z-index: 2; position: relative; } #sidebar-left { width: 221px; } #sidebar-right-sec { width: 200px; padding: 1.2em 0; } #sidebar-right { width: 248px; padding: 1.2em 0; } .rightbar .top-corners { right: -8px; top: -3px; padding-right: 8px; position: relative; min-height: 12px; } .rightbar .bottom-corners { right: 0; bottom: -4px; position: relative; min-height: 7px; } I have tried changing the content or 'squeeze' margins as its called and then just widening the sidebars but it just doesnt work. If anyone can help it would be great, thanks! I've been trying various fixes with my template, so that the grey background color in the sidebar, extends beyond the content to the bottom of the page. Alas... nothing is working. Here's my code: Code: #l_sidebar { color: #cccccc; background-color: #3a3a3a; width: 160px; float: left; float: left; margin-top: 0; margin-bottom: 20px; padding: 0 15px 15px 15px; } #l_sidebar p{ margin: 0px; line-height: 16px; padding: 0px 0px 5px 0px; } #l_sidebar h2 { color: #ffbfea; font-size: 18px; font-family: Verdana, Helvetica, Arial, Sans-Serif; font-weight: bold; list-style: none; padding: 10px 0px 10px 0px; margin: 0px; } #l_sidebar ul { list-style: none; margin: 0px; padding: 0px 0px 20px 0px; } #l_sidebar li { list-style: none; margin: 0px; padding: 0px; } #l_sidebar ul li { list-style: none; margin: 0px; padding: 6px 0px 5px 0px; } #l_sidebar ul li a { color: #c04080; text-decoration: none; } #l_sidebar ul li a:hover { color: #c04080; text-decoration: underline; } #r_sidebar { color: #c04080; background-color: #3a3a3a; width: 160px; float: right; position:relative; margin-top: 0; margin-bottom: 20px; padding: 0 15px 15px 15px; } #r_sidebar p{ margin: 0px; line-height: 16px; padding: 5px 0px 10px 0px; } #r_sidebar h2 { color: #ffbfea; font-size: 18px; font-family: Verdana, Helvetica, Arial, Sans-Serif; font-weight: bold; list-style: none; padding: 10px 0px 10px 0px; margin: 0px; } #r_sidebar ul { list-style: none; margin: 0px; padding: 0px 0px 20px 0px; } #r_sidebar li { list-style: none; margin: 0px; padding: 0px; } #r_sidebar ul li { list-style: none; margin: 0px; padding: 6px 0px 5px 0px; } #r_sidebar ul li a { color: #c04080; text-decoration: none; } #r_sidebar ul li a:hover { color: #c04080; text-decoration: underline; } Hello, I'm developing an intranet forum system with a design similar to Google Groups i.e. a sidebar with links to each message in the current thread, and a main content area to display the actual messages. Each area, i.e. the sidebar and the main content area, is a DIV. I have set the sidebar to width:25% and the main area left:25%, width:75%. My problem comes when I want each area to scroll (the main area vertically, and the sidebar horizontally). My plan is to use overflow:auto; this works fine with the main content area, but with the sidebar the text wraps around onto a new line if it overflows the DIV. This appears to be because the text is "hitting" the other DIV, i.e. the main content area, forcing it onto a new line. So can I do this using DIVs or do I have to resort to frames (I hope not, frames are SO messy and long-winded compared to DIVs....) Thanks, Nick |