SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with height

    Hy, I have a problem, when I using height attribute in % it's not working, working when I use in px, I want to use height attribute in %, please someone help.


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Width and Height </title>
    <meta http-equiv="Content-Type"
    content="text/html; charset=utf-8"/>

    <style >
    html{background-color:whitesmoke;}

    p#a {width: 15%; height: 50%;
    background-color: white; color: red; border-style: solid;
    border-color: red; border-width : 2;}


    p#b{background-color:white;color:blue;border-style:solid;
    border-width:2;border-color:blue;height:200px;width:25%;}

    </style>
    </head>
    <body>
    <img src="images/system.png" width="128" height="128"/>
    <p id="a">Blue</p>
    <p id="b">Green</p>
    <p>Red</p>
    </body>
    </html>

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,208
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Hi stanke. Welcome to the forums.

    The problem with % height is that it needs to be measured in relation to something. The element will ask itself "50% of what?" Unless the parent has a set height, there's no basic on which to set a height. Setting heights is rarely a good idea anyhow.

  3. #3
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you

  4. #4
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,379
    Mentioned
    180 Post(s)
    Tagged
    6 Thread(s)
    Read the CSS faq on 100% height for a better understanding of percentage height

    As Ralph mentioned apart from a few cases you don't really want a height on containers that hold fluid content anyway.


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
  •