Results 1 to 9 of 9

Thread: [RESOLVED] div tags and css

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Resolved [RESOLVED] div tags and css

    How can i make a div tag eg.'left-menu' the same size as the container eg.'content'. I am unable to fix height of the 'left-menu' tag as the 'content' tag needs to change as content is added on seperate pages.

    I've tried auto, but that only seems to make it as big as the list of links, were i would like the height to equal that of the containing div tag.

    I've also tried inherit but it seems to inherit 'auto' as its value rather than the actual height of the container.

    I dont have the code with me at the moment as im at work, but if needed i will post it when i finish.

    thanks
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  2. #2
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    Re: div tags and css

    I know you can do it using JQuery. Not sure if this is an option for you though.
    I use it in an ASP.net Project for layout purpose.

    The code bellow for example would align Element1's top left corner with Container's top left corner and Element2's top right corner with Container's top right corner. Then Contaner's width is ajusted to fit Table1's width.

    Note that all elements are accessed by ID, so you need to set those element's ID in your HTML.

    Javascript Code:
    1. $(document).ready(function() {
    2.     $("#Element1").position({
    3.         my: "left top",
    4.         at: "left top",
    5.         of: $("#Container")
    6.     });
    7.     $("#Element2").position({
    8.         my: "right top",
    9.         at: "right top",
    10.         of: $("#Container")
    11.     });
    12.     $("#Container").width($("#Table1").width());
    13. });

    Hope this can help you.
    Alex
    .NET developer
    "No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)

    Things to consider before posting.
    Don't forget to rate the posts if they helped and mark thread as resolved when they are.


    .Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
    My fresh new blog : writingthecode, even if I don't post much.

    System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: div tags and css

    sorry, i should of stated im using html and css, thanks anyway
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  4. #4
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: div tags and css

    This is one of those unfortunate HTML/CSS things for which there is [currently] no "natural" solution; you'll have to fake it, and there are a few options:

    My usual choice is to wrap both divs in a containing div, and then to place a vertically-repeating background image on that parent div. This makes it appear as though the left div goes as far down as the content div.

    You can also use Javascript to equalize the div heights after the page is loaded (you've said you don't want Javascript, but if you change your mind, we can help).

    Or you could use a table, since <td> cells in a single row are always stretched to equivalent height. You might incur some scorn if you choose this option though, as using tables for layout is bad practice.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: div tags and css

    I'll try the repeating image first when i get home in an hour, if i cant get it to work ill try the javascript option. I was wondering if in css you could put something like left-menu:height = container:height like u can in vb6.

    Would using javascript bloat my page and affect my seo rating, or is the code you've provided all i need.


    i found this link, which ill try as well
    http://www.tutwow.com/tips/quick-tip-css-100-height/
    Last edited by chris1990; Dec 13th, 2010 at 05:30 PM.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  6. #6
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: div tags and css

    I was wondering if in css you could put something like left-menu:height = container:height like u can in vb6.
    No, that won't work; CSS can't do dynamic assignment (aside from an inadvisable IE-only method). If you choose to give your elements a static height though, you can set them both to that height.

    On using Javascript - will it bloat your page? Not by a significant amount. Will it affect your SEO rating? Not really; making changes to content via Javascript may negatively effect a page's SEO, but what you're changing is appearance.

    You'll also want to keep in mind that users can disable Javascript (though it is rare for the average user to do so), and that it doesn't take effect until the page is fully loaded (if you have a large, slow-loading page, you'll have to wait for the JS change).

    As for the code, the Javascript that stlaural posted seems inappropriate; what you want is to simply equalize the heights of the two elements:
    Code:
    <script type="text/javascript">
    <!--
    window.onload = function(){
      document.getElementById('left-nav').style.height = document.getElementById('content').offsetHeight +'px';
    }
    //-->
    </script>
    This is assuming that your left nav div has an ID of "left-nav" and your content div has an ID of "content".

    i found this link, which ill try as well
    http://www.tutwow.com/tips/quick-tip-css-100-height/
    It could work, but if you look at the comments following the article, you'll see there's a problem with scrolling.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: div tags and css

    I went with your javascript (SambaNeko), it now leaves a gap on my other div tag, i tried adding a line to your code so it would work on both elements and still the same problem but on the leftnav div tag. I also tried to change the containing divs bg color but it still showed white.

    i thought it would be easier to show you than tell you my results
    http://car2000heywood.site11.com/about.html
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  8. #8
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: div tags and css

    You should change the script to...
    Code:
    <script type="text/javascript">
    <!--
    window.onload = function(){
      document.getElementById('contentleft').style.height = document.getElementById('contentright').offsetHeight +'px';
    }
    //-->
    </script>
    The 'fixedcontent' div contains the 'contenttop' div, so its height is equal to the height of 'contentright' plus the height of 'contenttop'. You only want to use the height of 'contentright'.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: [RESOLVED] div tags and css

    I tried figuring it out for about 2-3 hr's with no avail,

    thanks
    Last edited by chris1990; Dec 14th, 2010 at 07:54 AM.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width