Web Design and Web Development Forum

  1. #1
    Join Date
    Jul 2005
    Location
    Cardiff
    Age
    25
    Posts
    266
    Rep Power
    7
  2. Diagmato is on a distinguished road
  3. percentage width divs

    Im having alot of trouble with two <div>'s, and css.

    This is what i want.

    The left div (menu, and future doo-hickeys) is set to be 120 pixels in width:

    Code:
    div.m_left_divide{
    		float:left;
    		margin-left:0px;
    		margin-right:0px;
    		border:1px solid;
    		border-color:#000000;
    		height:100%;
    		width:120px;
    		background-color:#404040;
    		}
    This does as expected, but the main content area just wont respect the width of the left div. I want it to be 100% width (100% of the available space) with the left-hand div as it is.

    The content's css code:

    Code:
    div.m_main{
    		display:inline;
    		float:left;
    		margin:0px;
    		border:1px solid;
    		border-color:#000000;
    		height:100%;
    		width:100%;
    		background-color:#404040;
    		}
    How can i get it to display like in the image? As a general rule, it should display like a table, with <td width="120"> and the second <td width="100%"> (obviously without using a table).

    Thanks in advance.
    It's Me
    if(!$success){$try++;}
    else if($success >= 100%){unset($try);}
    Reply With Quote Reply With Quote
  4. #2
    Join Date
    Sep 2005
    Location
    Perth, Western Australia
    Posts
    417
    Rep Power
    7
  5. _jameshales is on a distinguished road
  6. Re: percentage width divs

    Well the problem is probably that, the DIV is told to be 100% in width and it looks for the width of its parent, which here is probably the screen, and sets its width to that, right? So the DIV stretches out of the screen and looks ugly. Well you want then to set the width of the DIV to 100%, minus the 120 of the side thing, so that it doesn't go outside of the page area. Well mixing percentages and pixels in CSS is horrible. Definately do-able, but horrible.

    Use something called RelativeLayers. It is a Javascript reliant library, with which you can create Layers (DIVs) that have mixed percentages/pixels, where you could, say, set the width of a layer to have width "100%-120px", with no problems. It's excellent and it's cross-browser, working in all/most popular browsers. It'll take a while to get used to, but it is rewarding, allowing you to position layers exactly how you want them.

    _jameshales
    Reply With Quote Reply With Quote
  7. #3
    Join Date
    Dec 2004
    Posts
    562
    Rep Power
    8
  8. eddmun is on a distinguished road
  9. Re: percentage width divs

    or more simply, you could set the margin-left of the main content area to something about 120px.

    edit: there needs to be a float in there somewhere as well - most probably for the navigation doo-hickey.
    Reply With Quote Reply With Quote
  10. #4
    4fingers's Avatar
    Join Date
    Aug 2005
    Location
    UK, Scotland
    Age
    25
    Posts
    850
    Rep Power
    7
  11. 4fingers is on a distinguished road
  12. Re: percentage width divs

    Yeah as eddmun says you need a margin-left in their and you can set the width of main to auto. So you should have something like this:
    HTML Code:
    <style type="text/css">
    <!--
    div.m_left_divide{
    		position:absolute;
    		margin-left:0px;
    		margin-right:0px;
    		border:1px solid;
    		border-color:#000000;
    		height:100px;
    		width:120px;
    		background-color:#404040;
    }
    div.m_main{
    		margin:0px;
    		margin-left:125px;
    		border:1px solid;
    		border-color:#000000;
    		height:100px;
    		width:auto;
    		background-color:#404040;
    }
    -->
    </style>

    The four finger rule: There is no middle finger.
    Reply With Quote Reply With Quote
  13. #5
    Join Date
    Jul 2005
    Location
    Cardiff
    Age
    25
    Posts
    266
    Rep Power
    7
  14. Diagmato is on a distinguished road
  15. Re: percentage width divs

    Thanks - that did it. The position:absolute on the left bar stopped the main section from going underneath the left bar.
    It's Me
    if(!$success){$try++;}
    else if($success >= 100%){unset($try);}
    Reply With Quote Reply With Quote

Similar Threads

  1. Percentage Help
    By Luke in forum PHP Scripting
    Replies: 8
    Last Post: 09-27-2005, 05:43 PM
  2. Yay! DIVS! :D
    By Conor in forum Site Reviews & Site Management
    Replies: 13
    Last Post: 09-26-2005, 01:33 PM
  3. Auto Fit width for "Frame"
    By medya in forum HTML/CSS Coding
    Replies: 12
    Last Post: 06-14-2005, 05:19 PM