Results 1 to 5 of 5

Thread: This simple test case doesn't work in Safari?

  1. #1
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default This simple test case doesn't work in Safari?

    Code:
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
    
    <style type="text/css">
    
    * {
    	margin: 0;
    	padding: 0;
    }
    
    html, body {
    	width: 100%;
    	height: 100%;
    }
    
    #container {
    	width: 100%;
    	height: 100%;
    	background-color: #CCCCCC;
    }
    
    #box {
    	width: 300px;
    	height: 300px;
    	margin: auto;
    	position: relative;
    	top: 50%;
    	background-color: #999999;
    }
    
    </style>
    
    </head>
    
    <body>
    
    <div id="container">
    	<div id="box"></div>
    </div>
    
    </body>
    </html>
    Does what it should in IE6 and FF2, but not in Safari? Or I'm doing it wrong? According to the w3c validators the html and css is valid, but #box doesn't change its vertical position in Safari.

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    It's the relative positioning. Try switching it to absolute. It should work the same in Fx and IE, but it'll also work in Safari.

    Example:
    Code:
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
        
    <style type="text/css">    
        * {
    		margin: 0;
    		padding: 0;
    	}
    
    	html, body {
    		width: 100%;
    		height: 100%;
    	}
    	
        #container {
    		position: relative;
    		width: 100%;
    		height: 100%;
    		background-color: #CCCCCC;
    	}
          
        #box {
    		position:absolute;
    		top :50%;
    		width: 300px;
    		height: 300px;
    		background-color: #999999;
    	}
    </style>
          
    </head>
    <body>
        
    <div id="container">
    	<div id="box"></div>
    </div>
      
    </body>
    </html>

  3. The Following User Says Thank You to Medyman For This Useful Post:

    jlizarraga (07-28-2008)

  4. #3
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    Thanks!

  5. #4
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    Just for clarification: The relative positioning in this case *should* work, right? As in, Safari is misbehaving here?

  6. #5
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Quote Originally Posted by jlizarraga View Post
    Just for clarification: The relative positioning in this case *should* work, right? As in, Safari is misbehaving here?
    Yeah, I would say so. I've never encountered this particular problem, so I can't comment on why it's happening. I remember running into a relative positioning bug in Safari several years ago, but that's been fixed and different than this.

  7. The Following User Says Thank You to Medyman For This Useful Post:

    jlizarraga (07-29-2008)

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
  •