absolute positioning

Discussion in 'CSS' started by jj1, Jul 27, 2009.

  1. #1
    PLEASE can anyone help with a CSS query.

    In my masthead I want to use absolute positioning to position different images and menu options ABSOLUTELY within the MASTHEAD rather than within the BODY - at the moment things are positioned absolutely within the body not within the masthead.

    I've tried setting a div container which is relatively positioned (div id="mastheadsection") to act as a parent for all the images, but they still end up being positioned absolutely for the body rather than the masthead.
    My code is:
    My css code is:
    Would be grateful for any help - I've read quite a bit and don't know where I'm going wrong.
     
    jj1, Jul 27, 2009 IP
  2. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can remove the coords from mastheadsection. You can relatively position someone and you don't need to state coords; the default is 0, 0 anyway.

    *edit there are two problems: There is no space between your class and your alt attribute in the last two images, and you're using the wrong selector in the CSS.

    class="imgattractive"alt=""... adding in a space may help, as most browsers rely on the spaces as much as the "" to determine where one attribute ends and another starts.

    Second, you are using a class selector (.mastheadsection) when the HTML is using an id. There is no element on your page who matches
    .mastheadsection

    you need
    #mastheadsection

    Third, you can simplify your CSS:

    
    #mastheadsection {
    position:relative;
    width: 950px;
    height: 500px; 
    }
    #mastheadsection img {
      position: absolute;
    }
    .imglogo { /*this isn't even necessarily needed since 0, 0 is the default*/
    top:0px;
    left:0px;
    }
    .imgattractive {
    top:100px;
    left:110px;
    }
    .imgseo {
    top:130px;
    left:200px;
    } 
    
    Code (markup):
    btw if these images are showing text, that is the text you must set in your alt=""

    Such as
    class="imglogo" alt="Joe's Garage"
    you don't need to say "logo of joe's garage" though. Just know if someone visits your page and the images don't load for whatever reason, that there is text saying the same thing the images are saying.
     
    Stomme poes, Jul 27, 2009 IP
    jj1 likes this.
  3. jj1

    jj1 Active Member

    Messages:
    892
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Many thanks Stomme poes - I've been trying to hack my way into css for a while now, but your explanation has just clarified a few things for me. And the code is now working too!! I've added a big plus to your reputation!!
     
    jj1, Jul 27, 2009 IP