CSS - Fixed Background Images In Elements, Not Body
Hi everyone, this is my first post and I hope it's easily resolved.
I'm new to CSS and working through CSS - The Missing Manual while slowly overhauling an old table-based web journal on the side. I'm trying to do the following: Left - navbar (~200px) Center - journal postings (~600px) Right - fixed image (~200px) // I want this to always be in sight I've gotten the first two nailed down nicely, but I'm having a really hard time with getting the fixed image to work. In extreme shorthand, the code relationship looks like this: <body> <nav-journal-image-wrapper width=1000> <nav-journal-wrapper width=800> <nav width=200> <journal width=600> </njw> </njiw> With the extra 200px of width in the final wrapper, I've been able to get the background image to be fixed and show nicely to the right of my navbar and journal post by making it the same 1000px in width. If the window is stretched, everything stays where it belongs - you just see more body background color. The problem is, when the window is condensed the final wrapper - despite having a set width - also is squeezed and my background image recedes under the journals. What I don't understand is why my navbar and journals seem impervious to small windows, but the wrapper around them with the background image is not? My code validates, and the relevant parts of the CSS start now: Code: <style type="text/css"> body { background-color:#333; } /* without this wrapper, the background in #nav-post-portrait-wrapper aligns with the screen right, not the wrapper's right */ #final-wrapper { background-color:red; width: 1034px; margin: 0 auto 0 auto; padding: 0; } /* this gives me an extra 200px on the right to show the fixed background image */ #nav-post-portrait-wrapper { margin: 0; padding: 0; width: 1034px; /* sets the max but doesn't seem to be preventing collapse */ background-color: white; background-image: url(CSS-TESTING/background-portrait-2.png); /* the image is also 1034px wide - I want this wrapper's width to be frozen! */ background-repeat: no-repeat; background-position: top; background-attachment:fixed; } /* this groups the navbar and postings together */ #nav-and-post-wrapper { background-color:#0F0; margin: 0; padding: 0; width: 828px; /* prevents collapse */ } /* begin nav sidebar CSS code */ #mainNav-wrapper { float: left; top: 0; margin: 0; padding: 0; height: 312px; width: 210px; } ul#mainNav { list-style: none; margin: 0; padding: 0; text-decoration: none; width: 200px; border-left: 2px solid #930; border-top: 2px solid #930; border-right: 2px solid #930; } ul li { width: 200px; margin: 0; padding: 0; height: 60px; border-bottom: 2px solid; border-bottom-color:#930; } /* end nav sidebar CSS code */ /* begin journal post CSS code */ #post-wrapper { margin-left: 214px; } .post { background-color:#6F9; border: 2px solid #930; width: 600px; height: auto; margin: 20px 0 0 0; padding: 0; } /* end journal post CSS code */ </style> <body bgcolor="#FFFFFF"> <div id="final-wrapper"> <div id="nav-post-portrait-wrapper"> <div id="nav-and-post-wrapper"> <div id="mainNav-wrapper"> <ul id="mainNav"> <li><a href="aboutme.htm" id="nav-about-me"></a></li> <li><a href="journalmain.htm" id="nav-journal-main"></a></li> <li><a href="beverageguide.htm" id="nav-beverage-guide"></a></li> <li><a href="guestbook/index.php" id="nav-graffiti"></a></li> <li><a href="contact.htm" id="nav-contact"></a></li> </ul> </div> <div id="post-wrapper"> <div class="post"> la la la </div> <!-- closes post div class --> <div class="post"> la la la </div> <!-- closes post div class --> <div class="post"> la la la </div> <!-- closes post div class --> <div class="post"> la la la </div> <!-- closes post div class --> <div class="post"> la la la </div> <!-- closes post div class --> </div> <!-- closes post-wrapper div id --> </div> <!-- closes nav-and-post-wrapper div id --> </div> <!-- closes nav-post-portrait-wrapper div id --> </div> <!-- closes final-wrapper div id --> </body> Thank you very much! Similar TutorialsHello DevShed CSS Help Forum, I have a wierd problem (seems I have a knack for that ) with a design I'm working on. When you first go to this page there is some disruption around the two floated columns in the background image that is assigned to the body tag: (Right now the page is only working in non-IE browsers, but I don't know any developers that regularly use IE anyways...LOL) http://www.spidersend.com/new_site/newsite4/test6.html However if you refresh the page or click to another tab and then back to that page it corrects itself. Once I remove the sidebar and the float property from the css on the main content area the issue is gone so it has to be something to do with that. Has anybody experienced this before? I just find it odd that it doesn't stay messed up, but corrects itself, even if you refresh and clear the cache. Confusing and wierd. Any ideas? Theories? Any and all ideas are much appreciated. Here is the CSS: Code: body { background-color: #FFFFFF; padding: 0px; margin: 0px; font-family: "arial"; background-image: url('images/bottom_slice.png'); background-repeat: repeat-x; background-position: bottom center; } div#header { background-image: url('images/header_slice3.png'); background-repeat: repeat-x; height: 198px; width: 100%; } div#header-content { width: 680px; margin: 0px auto; } div#top-navigation { width: 680px; margin: 0px auto; position: relative; bottom: 16px; color: #FFFFFF; font-family: "arial"; font-size: 16px; padding: 0px; } div#content { width: 850px; float: left; } div#content-header { background-image: url('images/content_bg_top.png'); width: 850px; height: 30px; } div#content-footer { background-image: url('images/content_bg_bottom.png'); width:850px; height: 32px; } div#content-area { background-image: url('images/content_bg_slice.png'); padding-left: 18px; padding-right: 18px; } div#adbar { width: 157px; float: right; } div#adbar-header { background-image: url('images/sidebar_top.png'); width: 157px; height: 30px; } div#adbar-footer { background-image: url('images/sidebar_bottom.png'); width: 157px; height: 26px; } div#adbar-area { background-image: url('images/sidebar_slice.png'); padding-left: 5px; padding-right: 5px; } div#sidebar { float: right; clear: both; position: relative; right: 10px; background-color: #d2e7f0; width: 300px; -moz-border-radius: 5px; padding: 5px; margin-left: 15px; color: #0c577a; } div#sidebar2 { float: right; clear: both; position: relative; right: 10px; background-color: #d2e7f0; width: 300px; -moz-border-radius: 5px; padding: 5px; margin-left: 15px; margin-top: 20px; color: #0c577a; } div#content-wrapper { width: 1007px; margin: 0px auto; } Hullo, I have an issue here that I have been trying to find a solution for for the past week, but I suppose I don't really know what exactly to look for. I want to make a background that consists of different horizontal color strips. The reason I do not want to use an image and repeat it is because the strips are different in height. I want them to shrink/expand vertically keeping their proportion to each other ( instead of repeating vertically) in case the screen used to view the website is smaller/ bigger than mine. I tried creating different elements using <div id="name"> and assigning a background color and define a percentage for the height, however this doesn't work because the element has to have text inside it to expand according to it. I do not want to assign fixed heights because as I said I want them to expand and shrink proportionally. If you know a way to do this even if it is not CSS please let me know. All help is appreciated. Thanks. I have two problems. First issue is that I cant seem to get a background image to repeat in IE when it works fine in FF. I tried to reproduce the bug on another server using the same exact CSS and to my shock, the background repeat rule works fine. So, it doesnt work on my server at home with a much more complicated stylesheet (albiet the reference to the background image and repeat rule are exactly the same .. and simple) .. but when I port the same stylesheet to another server with simpler markup, boom, it works fine. Cant wrap my head around this one. Is there a commonly known IE bug/problem with background image/CSS/background-repeat rules? My site that does not work through IE shows the image once .. and thats it. No repeating like tell it to. My other issue (if youre still interested) is a problem with the CSS command: Code: table { empty-cells: show; } which does not work at all. As you can see on this page in IE, (http://www.doublethinkdesigns.com/development/ ) ive specified the rule, but lo and behold, the cells are still missing. Can someone kindly lend me some perspective perhaps? Thank you much in advance. Does such a thing exist... what I mean is that div {background-imageimage.png);background-attachment:fixed;} would work in IE (like it does in mozz) Does anyone know of any hacks/workarounds/techniques to get this to work in the brilliant IE? Cheers Hello, I'm new here and in desperate need of your help. What I'm trying to accomplish is this: http:// i29.tinypic.com/259inue.jpg There are two problems. 1) How do I place two sidebars next to each other? 2) How do I keep the header and the sidebars fixed, and the content the only element that you can scroll in? Any hints would be greatly appreciated! Sorry about my Engish, I'm afraid it's not very good. I would like to have a header on my page with my logo in the top left corner, and a cloud image going the rest of the way across the top. I set up the cloud image as a background, but wanted the logo to be clickable so it is set up in the html as an image. The problem is that I want the image to be fixed in the corner so that when the visitor scrolls, it stays at the top. It looks good in Firefox and in Chrome, but in IE it is a few pixels offset from the corner and I have no idea how to fix it. See what I mean he felixairservices.com Here is my css for the logo: Code: body { background:#6699BB url('sky.jpg') no-repeat top right fixed; background-size: 90% 228px contain; } img.logo { position:fixed; top:0px; left:0px; margin:0; padding:0; border-style:none; } And here is the html I am using to display it: Code: <a class="logo" href="index.html" border="0"><img class="logo" src="Logo.jpg" valign="top" align="left" border="0"></a><br> Any help would be appreciated. I'm just a simple AC contractor trying to build a decent web page for my business. I'm working on a site with a div element with a fixed position, some 800 pixels from the left. The site is optimized for 1024x768. However, if a user with a resolution of 800x600 views the page, this div element will be missing, and the user won't be able to scroll over to see it. Is there some way I can get around this? One idea would be to align the div on the right instead of the left, but I don't want a lot of whitespace between my content (on the left) and my div (on the right). I was hoping that I could specify a parent element with a relative position, and that position: fixed would reference the position of the parent element, but that only seems to work when the child div element is position:absolute, not position:fixed. Thanks for any insight. Hi, I have been puzzle for a while now working out how to do this. I have two fixed height divs which I want to appear on the same line (inline). However to maintain the fixed height they cannot be set as display: inline; (Well that works in IE but not in Firefox). Anyway I find out that setting one div to float left and the other to float right with another div with clear:both works fine. However when it comes to setting the position of the flash elements I want in each div element it works now in Firefox but not in IE. I currently have: <div id="diva"> <object id="face1" width="320" height="110"> <param name="face1" value="face1.swf"> <embed src="face1.swf" width="320" height="110"> </embed> </object> </div> <div id="divb"> <object id="face2" width="320" height="110"> <param name="face2" value="face2.swf"> <embed src="face2.swf" width="320" height="110"> </embed> </object> </div> <div id="clear"></div> With the relavent css: #div1 { background-image : url(images/bg1.gif); width: 381px; height: 346px; float: left; text-align : center; vertical-align : bottom; } #div2 { background-image : url(images/bg2.gif); width: 381px; height: 346px; float: right; text-align: center; vertical-align : bottom; } #clear { clear: both; } img { border: 0px; } #face1{ padding-top: 220px; left: 30px; } #face2{ position: relative; top: 220px; left: 10px; } Effectively what I want is: Where the divs are on the same line and are fixed height (as they have a background) and then each swf element releatively positioned inside the div...which will work in Firefox and IE! Thank you for your time. Hi! Is it possible to align vertically block elements in a fixed-height (unknown) container? If not, this is a serious shortcoming of the css model of placing objects on the screen. Thanks! Hi all, I would like to be able to have the body background change when moving from page to page. Is it possible, without javascript. Code: body { margin: 0px; padding: 5px 0px 5px 0px; background: url(blue2.jpg) fixed; } { Specifically the surrounding blue2.jpg that frames the page. page link css link Thanks. I haven't succeed in getting the Javascript's DOM to tell me what the body's background color is... Here's the code I got Code: mybody = document.getElementsByTagName("body"); alert(mybody.getAttribute("background-color")); //alert(mybody.style.backgroundColor); Nice references I looked up from are http://www.mozilla.org/docs/dom/technote/tn-dom-table/ http://www.sitepoint.com/print/rough-guide-dom http://www.mozilla.org/docs/dom/domref/dom_style_ref.html http://developer.apple.com/internet/webcontent/dom2ii.html i have a problem dynamically setting the html background color when i initially set it with css. if i have a javascript function: function changeColor() { document.bgColor = '#FFFF00'; } and call it when i click a button the background color changes like you'd expect. but if i initialize the background color like this: body{background-color: #FF0000;} and then later call my javascript function to change the background color like before, it doesn't do anything. what's going on here? and how can i initialize the background color and still be able to dynamically change it? thanks My problem is that I need to get the Body Background color that is in a css file using php to then introduce this color to an applet. My CSS file has: BODY { FONT-SIZE: 12px; COLOR: #6699ff; BACKGROUND-COLOR: #ffffff; SCROLLBAR-FACE-COLOR: #FFFFFF; SCROLLBAR-HIGHLIGHT-COLOR: #CC6699; SCROLLBAR-SHADOW-COLOR: #CC6699; SCROLLBAR-3DLIGHT-COLOR: #CC6699; SCROLLBAR-ARROW-COLOR: #CC6699; SCROLLBAR-TRACK-COLOR: #FFFFFFF; SCROLLBAR-DARKSHADOW-COLOR: #CC6699; FONT-FAMILY: "Times", serif; } But I use different CSS so very time I change the file I need to know in the php page what BACKGROUND-COLOR it has. Hello, I had a site exactly how I wanted to and messed up a css file. I am almost back to where I was but I am having an issue with the background image of the body element. Please look at this layout - Client Website . Notice how the hardwood floor does not go all the down? I have the image sized to 1500 pixels high and yesterday I did not have this issue. Also, when I outline elements in FF I see the body element seems to fall short. Any help would be appreciated. Tom #bg-one { background: white url(some.png); } #bg-two { background: white url(someother.png); } =========== ... </head> <body id=bg-one"> ... ... </head> <body id=bg-two"> Hi there, I am trying to place a fixed backgroung image to a div, which is to be position to the bottom right of the screen. The code I have so far: Code: body#fixed { background-image: url(../images/fixed-bg.png); background-position: bottom right; background-repeat: no-repeat; background-attachment: fixed; } using <div id="fixed"></div> However it doesn't seem to work. I can't add the bg image to the body style as I already have another background image specified for the entire document. Any ideas? Hey folks... I'm working on a site that uses CSS, and the PHP "switch" statement, to pull pages into a main div on the index page. I put a background image into the main ".content" div, which should remain fixed while the content (brought in by the switch), scrolls over it. When I wrote the image in, FF did this by default, whereas in IE, the image would scroll with the text... so I put in the "background-attachment:fixed" code in, and now it works fine in IE, but FF has suddenly developed a problem with it.. the image is off-center, so only part of it shows, leaving huge white spaces where it should be covered. You can look at the site here. I've attached the code for the index page as a word document. Hope this is OK, I figured it would be better than sticking all the code on here! Anyone have any ideas what I'm doing wrong? BW. x How to keep bg fixed with top header non moving refer http://vedasprojects.com/ I want to keep the top header fixed At present when i scroll the page , the top header moves ... I dont want the header to move ... please help Hey Guys. I'm working on a tumblr theme at current and they have what is called a audio post, which ad's a flash movie that plays a sound. I'm having trouble as I've got a fixed header that the posts go under as the user scrolls the page, which works fine with youtube videos. However the audio post is going ontop of my banner/logo. Code: #banner { width:637px; height:150px; margin-left:10px; background-color:#141414; background-repeat: no-repeat; position:fixed; z-index:1000; } .logo { margin-top:40px; z-index:1000; position:fixed; } .audio_player { z-index:-1000; position:static; } Code: <span id="audio_player_11436410709"> <div class="audio_player"> <embed type="application/x-shockwave-flash" src="http://assets.tumblr.com/swf/audio_player_black.swf?audio_file=http://www.tumblr.com/audio_file/11436410709/tumblr_lt297nLjGa1r4fuce&color=FFFFFF" height="27" width="207" quality="best"></div></span> The embed is dynamically generated by tumblr so there is no way I can change it from embed. Has anyone else had this problem or know a solution? As Z-index seems to be getting ignored :S Hey All, It's been a while, and my CSS knowledge is a bit rusty (not that it was ever all that;-). Anyway... Working on a custom wordpress admin write panel, I have a table with dynamic classes in a helper.css for indicating row status(includes .myclass tr:hover), which works great everywhere EXCEPT in our old friend IE6. Turns out that the wordpress "global.css" for admin panels defines the following: Code: html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi g, cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt ,dd, ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td { margin:0;padding:0;border:0;outline:0;background:transparent;} where, though I can't remember how I stumbled onto it, upon removing "background:transparent;" in wp admins global.css everything is hunky dory in IE6 too -- ok, not the tr :hover{ because IE6 only supports :hover on <a>s. but at least the row classes are displayed with no other discernible impact on this or any other admin pages in IE6 or any other browser. Of course, I don't want to go changing wordpress core code just to scratch my little itch, but I was hoping someone might suggest a means of overriding the background:transparent in wp admins global.css either in my own helper.css or in the on the page itself? |