1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Ho to align elements that have different margin and padding

Discussion in 'CSS' started by Webed4it, Nov 13, 2010.

  1. #1
    The site I am developing uses a header div without any margin, border or padding but the content div has padding to create a border. This creates a problem because the right edge of the content div shifts outwards and is no longer aligned with the header.

    I cant simply change the width because it needs to be able to adjust when the window is resized (ie. using % not px). I tried using negative margins but could not get it to work.

    How can I solve this problem? Is there a way of specifying a width as a percentage minus x amount of pixels?

    Any help appreciated.
     
    Webed4it, Nov 13, 2010 IP
  2. radiant_luv

    radiant_luv Peon

    Messages:
    1,327
    Likes Received:
    34
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Which browser you faced this issue? I think it's the box model issue.

    I don't think so, however you can specify browser specific CSS properties.
     
    radiant_luv, Nov 13, 2010 IP
  3. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #3
    If you are using a proper doctype, there are no "box model issues" thought IE has plenty of bugs to mess with your head.

    No, there is no way to do percentags minus pixels.

    Without a link (preferred) or the complete markup, this is complete guesswork.
     
    drhowarddrfine, Nov 13, 2010 IP
  4. Webed4it

    Webed4it Peon

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Webed4it, Nov 13, 2010 IP
  5. radiant_luv

    radiant_luv Peon

    Messages:
    1,327
    Likes Received:
    34
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Offcourse, markup is horrible and there is an effort to fix the markup with css.

    Anyways, to fix the issue in YOUR WAY, you might do the following chages to your css,
    
    div#container {
    padding:15px; <-- [COLOR="red"]step 1: remove[/COLOR] -->
    }
    #sidebar{
    margin-left:-269px; <-- [COLOR="red"]change to 269px [/COLOR]-->
    margin-top:15px; <-- [COLOR="red"]add[/COLOR] -->
    margin-bottom:15px; <-- [COLOR="red"]add[/COLOR] -->
    }
    .padder{
    margin-right:268px; <-- [COLOR="red"]change to[/COLOR] -->
    }
    
    Code (markup):
     
    radiant_luv, Nov 13, 2010 IP