Results 1 to 4 of 4

Thread: problem with divs

  1. #1
    Join Date
    Jun 2008
    Posts
    192
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default problem with divs

    Please have a look at the following html:
    Code:
    <html>
    <head>
    </head>
    <body style="width: 100%;">
    <table style="width: 100%;" border=1><tr><td>
    <div style="width 50%; background-color: red; float: left;">left</div><div style="width: 50%; background-color: blue; float: left;">right</div>
    </td></tr></table>
    </body>
    </html>
    When I run this, I get a red div with the word "left" in it that's only about an inch long, and I get the blue div right after it at about 50% of the page.

    Why is the red div not 50% of the page?
    Last edited by Beverleyh; 03-03-2015 at 08:44 AM. Reason: formatting

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    You've missed a colon in the first/left div inline style;
    Code:
    <html>
     <head>
     </head>
     <body style="width: 100%;">
     <table style="width: 100%;" border=1><tr><td>
     <div style="width: 50%; background-color: red; float: left;">left</div><div style="width: 50%; background-color: blue; float: left;">right</div>
     </td></tr></table>
     </body>
     </html>
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,920
    Thanks
    2
    Thanked 267 Times in 262 Posts

    Default

    Hi there gib65,

    also note that, further to what Beverleyh has just pointed out, the parent element of an element which
    has a percentage dimension value, in this case it is the td element, must always have a width value set.

    Fifty percent of nothing is nothing.

    coothead

  4. #4
    Join Date
    Jun 2008
    Posts
    192
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Beverleyh View Post
    You've missed a colon in the first/left div inline style;
    Code:
    <html>
     <head>
     </head>
     <body style="width: 100%;">
     <table style="width: 100%;" border=1><tr><td>
     <div style="width: 50%; background-color: red; float: left;">left</div><div style="width: 50%; background-color: blue; float: left;">right</div>
     </td></tr></table>
     </body>
     </html>
    D'Oh!

Similar Threads

  1. problem in background of DIVs....
    By gurmeet in forum CSS
    Replies: 1
    Last Post: 02-17-2009, 05:47 PM
  2. divs going under divs problem
    By *Warrior* in forum CSS
    Replies: 4
    Last Post: 07-24-2008, 11:01 PM
  3. Problem with divs and css in IE
    By nomaC in forum CSS
    Replies: 0
    Last Post: 09-22-2007, 08:39 AM
  4. divs problem
    By remp in forum CSS
    Replies: 1
    Last Post: 08-13-2007, 12:18 AM
  5. Ack! now I have a new problem with my divs!
    By lord_havoc in forum CSS
    Replies: 6
    Last Post: 07-13-2007, 02:22 PM

Bookmarks

Posting Permissions

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