Results 1 to 3 of 3

Thread: IE hack Problem

  1. #1
    Join Date
    Feb 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default IE hack Problem

    hi,

    I had a question in my Interview.

    "write a css for an element(image, text...) and the top margin for that element should be 20px in firefox and 50px in IE...hack it!"

    I could not answer it!@#$%.

    but i am interested to know the answer for it, can someone help me.

    Thank you in advance!!!

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Check the following source code

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!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" xml:lang="en" lang="en">
    	<head>
    		<title> </title>
    		<style type="text/css">
    		.ie{
    			margin-top: 20px;
    			border: 1px solid blue;
    			width: 200px;
    			height: 200px;
    		}		
    		</style>
    		<!--[if IE]>    
    		<style type="text/css">
    		.ie{
    			margin-top: 50px;
    			border: 1px dotted red;
    			width: 200px;
    			height: 200px;
    		}		
    		</style>
    		<![endif]-->
    		<script type="text/javascript">
    		
    		</script>
    	</head>
    	<body>
    		
    		<div class="ie"> </div>
    		
    	</body>
    </html>
    The highlighted section will be considered only by IE. In this case you have a IE specific CSS rule which will be considered only by IE. To identify the differences I've mentioned different border color for FF and IE

  3. #3
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Codeexploiter's solution works fine. Another possibility (if you don't worry about validation and don't mind evil code)
    Code:
    <style type="text/css">
    .someclass{margin-top: 20px;_margin-top:50px}		
    </style>
    ---
    This works because non-IE doesn't interpret the underscored part.
    Arie Molendijk
    Last edited by molendijk; 03-26-2008 at 12:48 PM. Reason: Correction

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
  •