CSS - Centering Elements And Keeping Them Above Others
I am trying to have an element that will float above the others on the page and also be centered. When I make the position absolute, it will float above the others, but won't center (dynamically with window resize) and if I make the position auto, it will center but not float above the others. Here is the style:
Code: .main { position:auto; margin: 0px auto; text-align: center; width: 800px; background-color:red; z-index:1; } Thank you Similar TutorialsThe Website in Question I just started to remake my portfolio site from scratch, and since I'm a crappy coder, I ran into a brick wall right away. It was easy horizontally and vertically centering the tan rectangle, but for the life of me I can't get the green sliding panel where I want it, and have it otherwise horizontally and vertically centered at all times. How I want it: Example I think the problem may be a conflict between the javascript that enables the sliding function of the green panel and the CSS trying to center it. The javascript demands absolute positioning of the two divs (the part that says "PORTFOLIO" and the part that slides right), because that's what tells the sliding panel where to slide and expand to. However, the CSS demands relative positioning, in order to position the panel a percentage down the page, and half its height in pixels back up again, as well as the horizontal alignment. Below is the source code for the site. At the moment, the sliding panel (its code is shown in blue) is set to be in the top left corner of the site, but it obviously isn't. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <head> <title></title> <style type='text/css'> body, html { height:100%; } #container{ height:100%; text-align: center; } #panel { width: 700px; height: 500px; position:relative; top:50%; margin-top:-257px; left:50%; margin-left:-350px; } body { background-image: url(bg3.gif); } </style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <div id="container"> <div id="panel"><img src="work.png"></div> </div> <script type="text/javascript" src="Animation.js"></script> <div style="position:relative; width:350px; height:520px; top:0px; left:0px;"> <div id="exampleHeader" style="position:absolute; width:50px; height:500px; top:0; left:0px; background:#298b12; text-align:center; color:#FFFFFF; -moz-border-radius-topleft: 25px; -webkit-border-top-left-radius: 25px; -moz-border-radius-bottomleft: 25px; -webkit-border-bottom-left-radius: 25px;" onclick="runAnimation(animationObject, this)"> <img src="pf.png"> </div> <div id="examplePanel" style="position:absolute; width:0px; height:500px; top:0px; left:50px; background:#ac926d; background-image: url(pbg.gif); background-position:right top; overflow:hidden; -moz-border-radius-topright: 25px; -webkit-border-top-right-radius: 25px; -moz-border-radius-bottomright: 25px; -webkit-border-bottom-right-radius: 25px;" align="center" overflow:hidden;"> Content </div> </div> <script type="text/javascript"> var animationObject = new AnimationObject('examplePanel'); animationObject.AddFrame(new AnimationFrame(50, 0, 210, 500, 400)); function runAnimation(animation, header) { if(header.check) { animation.RunBackward(); header.check = false; } else { animation.RunForward(); header.check = true; } } </script> </body> </HTML> I just can't seem to get my code to work. Can anybody offer any help to solve this problem? I'd really appreciate it. Nevermind: solved Good evening, I'm trying to center a horizontal menu on a website, and I can't seem to get the right code tags in the write places. I'd like to get the links on the menu to center on the page, and perhaps to display in a consistent width text box. My menu bar is 900px, and there are 10 links, so for instance I would like to reduce these boxes containing the links to a consistent 90px. Any thoughts? website - http://www.squadron282.com CSS Code: Code: .nav2 {clear: both; margin: 0px; padding: 0px; font-family: verdana, arial, sans serif; font-size: 1.0em;} .nav2 ul {float: left; width: 900px; margin: 0px; padding: 0px; border-top: solid 1px rgb(54,83,151); border-bottom: solid 1px rgb(54,83,151); background-color: rgb(127,162,202); font-weight: bold; white-space:nowrap} .nav2 li {display: inline; list-style: none; margin: 0px; padding: 0px;} .nav2 li a {display: block; float: left; margin: 0px 0px 0px 0px; padding: 5px 10px 5px 10px; border-right: solid 1px rgb(54,83,151); color: rgb(255,255,255); text-transform: uppercase; text-decoration: none; font-size: 100%;} .nav2 a:hover, .nav2 a.selected {color: rgb(50,50,50); text-decoration: none;} .buffer {clear: both; width: 900px; height: 30px; margin: 0px; padding: 0px; background-color: rgb(255,255,255);} HTML Code: Code: <div class="nav2"> <ul> <li><a href="index.html">Home</a></li> <li><a href="missions.html" class="selected">CAP Missions</a></li> <li><a href="sqinfo.html">Squadron Info</a></li> <li><a href="commanderscorner.html">Commander's Corner</a></li> <li><a href="resources.html">Member Resources</a></li> <li><a href="pics.html">Photo Gallery</a></li> <li><a href="contact.html">Contact Us</a></li> <li><a href="sitemap.html">Sitemap</a></li> </ul> </div> How do I align menu elements of my menu? In Mozilla the elements are leaning conpletely to the left of the screen and doing somewhat what they're supposed to do in internet explorer. To put it simply I'd just like to have the same style class used to center the menu items in both Mozilla and Internet explorer. Heres the html page : Code: <html> <head> <link rel="stylesheet" type="text/css" href="style.css" title="thisstyle CSS"></head><body> <style> body { background-color: limegreen; <font FACE="Lucida Console"> } </style> </head> <body> <div id="menu"> <ul align="center"> <li><a href="users/register.php">Join</a></li> <li><a href="users/Log_in.php">Login</a></li> <li><a href="users/help/tour.html" >Tour</a></li> <li><a href="users/contact.php">Contact</a></li> </ul> </div> </body></html> Heres the css style sheet : Code: #menu { clear: both; margin: 30; padding: 0 40px 0 0; background: url(menu.jpg) repeat-y center top; font: bold 12px/26px Lucida Console; height: 26px; background: #006633; } #menu ul { float: left; list-style: none; margin-top:0; padding: 0; margin-right:0; padding: 0; margin-bottom:0; padding: 0; margin-left:90; padding: 0; } #menu ul li { display: inline; } #menu ul li a { display: inline; float: left; padding-top: 0px; padding-right: 28px; padding-bottom: 0px; padding-left:8px; color: gold; text-decoration: none; } #menu ul li a:hover { background-color: #ffff33; color: #006633; } #menu ul li#current a { background-color: #eee; color: #333; } Thanks Hello all, I'm having a bit of trouble with a list of relative, floated <li> elements, each containing a single absolutely positioned div that appears on hover. I'm using the :hover pseudo-class currently but I will use JavaScript for IE6 once it displays correctly. The code is below. The problem is that the <div> appears on top of it's parent element but behind all other elements. Code: #wrapper-body ul.staff-list{ list-style-type:none; padding-top:10px; position:relative; } #wrapper-body ul.staff-list-team{ width:313px; padding-top:0; padding-bottom:15px; margin-bottom:20px; border-bottom:1px solid #d7e3a9; } #wrapper-body ul.staff-list li{ float:left; width:230px; position:relative; padding:8px 0 8px 15px; z-index:1; } #wrapper-body ul.staff-list-team li{ width:151px; padding-left:0; padding-left:5px; } #wrapper-body ul.staff-list-team li.right{ padding-left:5px; } #wrapper-body ul.staff-list-clerks li{ float:none; width:310px; padding-left:5px; } #wrapper-body ul li.highlight{ background-color:#f4f6ec; } #wrapper-body ul.staff-list li p{ padding:0 0 9px 0; margin-left:91px; } #wrapper-body ul.staff-list li small{ padding:0 0 5px 0; margin-left:91px; } #wrapper-body ul.staff-list-clerks li span{ color:#A6302B; display:block; float:left; } #wrapper-body ul.staff-list-clerks li span.clerk-name{ width:140px; } #wrapper-body ul.staff-list-clerks li span.clerk-phone{ width:120px; background:url(../img/structure/clerks-phone.gif) 0 2px no-repeat; padding-left:23px; } #wrapper-body ul.staff-list-clerks li a.clerk-email{ display:block; float:left; height:16px; width:16px; background:url(../img/structure/clerks-mail.gif) 0 3px no-repeat; } #wrapper-body ul.staff-list li div.staff-list-detail{ display:none; background:url(../img/structure/staff-list-bottom.gif) left bottom repeat-x; padding-bottom:3px; margin-top:-15px; left:4px; z-index:10; top:15px; position:absolute; } #wrapper-body ul.staff-list li div.staff-list-detail a{ background:url(../img/structure/staff-list-bullet.gif) no-repeat 0 4px; padding-left:8px; } #wrapper-body ul.staff-list li:hover div.staff-list-detail{ display:block; } An image of what is happening below: Thanks for reading! I have a set of background images that work well in giving the impression that there is a solid page on screen. However, as you can see here , once I start introducing structure it falls apart and I'd really () like to know why. (The CSS validates OK and I've given temporary borders to the divs to help show where on the screen they should appear). Hi the I wonder if there is a way to keep spiders away from certain sections of my web pages? For example, keep them away from the nav_bar, but index the rest of the html page? Someone told me it could be done by CSS but I've tried to search for it without any luck. Any suggestions would be greatly appreciated. Sincerely, Ponch Hi How do I get a <div> to stay at the bottom, constantly, even if a layer above it gets resized so that its longer than the page in the browser. I have one <div> and then the footer <div> but the upper <div> gets resized to about 1000px and over laps the footer <div>, how do I get the footer <div> to keep at the bottom ? Hi, I have started to get to grips with CSS but I am currently just playing - I have not designed any serious pages but am about to. I wondered if it is possible (I am sure it is but I cannot work out how) to use a h1 tag in the middle of a paragraph <p> without making it start a new line. Does anyone know of a method to force the text within the h1 tag to just flow within the sentance? For example if the above block was a paragraph the word CSS on the first line could be included within a h1 tag but it would remain on the line as it currently is (however in this case it would be forced to appear as capital letters, but I can take care of that part myself). Thanks for your time Hi, I have a container with a border that works fine , but when I float 4 elements that are in a row, the container shrinks, and they are outside the container. How can I align four boxes, and keep them in the container? here's the example: http://www.caillouette.com/alpha-dream/ thanks I'm having problems with keeping the border of an div tight in against the div's content. At the following URL http://alphaworks.co.uk/problems/box/ I want the next and prev divs to be a little larger than the text inside them and then the outer prev_next div should be a little bigger than the two divs inside it but not stretching to the width of the page as it does now. Can someone show me the error of my ways? Thanks, Geoff I am working on aligning a pricelist with product and price. The procuct is on the left, and the price should align to the right on the same line. When I try to use float: right in the div for the price it jumps down a line, if I use text-align right in a relative devision it also jumps doen a line. I also tried adding align:right to the b tag. Any ideas how to get this done? I am trying to avoid tables. Thanks Hello, I'm stumped on how to float an image to the left, and still keep it in the flow of the document. Here is an example off my head. Code: #container { border: 1px solid #000; } img.floatleft { float:left; } div { display: inline; } <div id='container'> <img src='myimage.jpg' class='floatleft'> <div>text</div><br> <div>text</div><br> <div> <div id='container'> <img src='myimage.jpg' class='floatleft'> <div>text</div><br> <div>text</div><br> <div> The image will exceed the bounds of 'container' if the image is larger than the text is tall. How can I get around this? Thanks again for the help. webg <div>text</div> I believe this has been asked before, but I'm unsure what search terms to use... Basic one column CSS layout. How to keep the footer at the bottom of the window even when content doesn't reach that far? I'm trying to have the contact information for a site to always appear in a right div next to the main content div. I would like it to always appear in the top right of the div, no matter how much the user scrolls down. This way, the information is always visible. I tried experimenting with background images in certain divs, but Firefox (but not IE) was having trouble displaying it the way I wanted. I've seen it in action before, so I'll post a URL if i can find where. I have this problem making this menu and I have multible <h1></h1> on each title of the of stuff. It seems that the text gets bigger and bigger then when its to big then the text in the <h1> goes back smaller. Is there a way to fix this? Here is my code. Code: h1 { font-family: cursive, sans serif; font-weight: normal; font-size: 200%; font-style: cursive;} EDIT:The strange thing is that I know of this wird effect only happens in IE. Thank you, sorry to be a bother but I do want to have a good first impression on my site that I am working for Ernies Bar & Grill at my town. What I need to do is align a series of icons to the center, but there are a few complications, they must continue to be centered with any combination of 4-5 different(same sized) icons. For example icon 3 and 4, when displayed must be centered together, and at the same time, if icon 1 and 5 are being displayed they must also be centered correctly. First of all they are appearing on 2 seperate lines, and I seem to be unable to put them on the same line without using float:left on one. But I can't just float:left image one to put them on the same line, as image one may not be displayed in the next instance(with a different combination of images). And I don't think I can set a width on the div and center it because there will not be the same number of icons displayed in each instance(could be 1-5, 14x14 icons). My guess is that some % values can make this work but I'm just not sure how. I was going to post an illustration of what I mean but I guess it's blocked... Any help would be greatly appreciated. Thanks. Hi, I've just reworked my site, and I'm having trouble keeping the footer at the bottom of the page. my site stylesheet (see div#footer) Any ideas? I've tried setting body min-height (and height for ie) to 100% and setting position:absolute; bottom:0px; but that didn't work. Greetings, My example page is located here. As you can see I'm having issues on the bottom of the page. I believe I know what is causing the issue, just not how to fix it. I need it only to work in IE and at a resolution of 1024x768 and higher. I have the footer outside of the other wrappers which are set to 100% height. But wrapper_04, which does not include the header, seems to be extending past the footer the same height as the header because it is trying to be the same height as the other parent wrapper elements? Any thoughts on how I can fix this using just CSS? I do have some js which sets the height of the content_wrapper so the background image extends the full height (yellow line image on the right of the page), but it should not be affecting the rest of the page. Thanks in advance for any assistance! I am not an expert on developing websites, but I've been able to get our site up and running without much challenge. I used a menu I found on www.dynamicdrive.com that allowed you to have our menu in a horizontal or verticle layout. We don't use frames in our site but we wanted a frames-type look. So we use the menu in the vertical layout. What I'd like to do is find a way to keep the menu on the screen as people scroll down. I've seen other websites do this and have looked at a couple that were recommended from a previous post, but I can't figure out how to make it work propertly. Our website is www.indyartistgroup.com. If someone could take a look at the site and suggest some ideas on how to make the menu on the left hand side stay on screen no matter how low you scroll I would appreciate it. I'm out of options at this point. Thanks for the help. John |