Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    116
    Thanks
    19
    Thanked 1 Time in 1 Post

    Wrong image location in div

    Dear Sir,

    I have following codes

    Code:
    <html> <style type="text/css"> #d1	{float:left;	width:200px;height:200px;	background-color:e3eeff;		margin:20px 20px 20px 20px;	padding:20px 20px 20px 20px;	text-align:center;	vertical-align:middle;	letter-spacing:10pt;} .bg	{width:100%;height:100%;position:absolute;z-index:-1;}  </style>  <body> <div id="d1"><img class="bg" src="dream.jpg" width=100 height=100%><h2>Hello world</h2></div> </body> </html><html>
    
    <style type="text/css">
    
    #d1	{float:left;
    	width:200px;height:200px;
    	background-color:e3eeff;	
    	margin:20px 20px 20px 20px;
    	padding:20px 20px 20px 20px;
    	text-align:center;
    	vertical-align:middle;
    	letter-spacing:10pt;}
    
    .bg	{width:100%;height:100%;position:absolute;z-index:-1;}
    
    
    </style>
    
    
    <body>
    
    <div id="d1"><img class="bg" src="dream.jpg" width=100 height=100%><h2>Hello world</h2></div>
    
    </body>
    
    </html>
    I want to know
    Why background image goes outside of div?

    I want result shown in attached file



    Please help
    Attached Thumbnails Attached Thumbnails Wrong image location in div-aaa.jpg  
    Last edited by tqmd1; 11-09-2011 at 08:39 AM. Reason: correction

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,746
    Thanks
    22
    Thanked 1,838 Times in 1,822 Posts
    Hello tqmd1,
    Both those examples have several errors the validator can help you find. See the links in my signature line about validation.

    Try it like this once -
    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>Untitled Document</title>
    <style type="text/css">
    #d1 {
    	height: 200px;
    	width: 200px;
    	float: left;
    	margin: 20px;
    	padding: 20px;
    	background: #e3eeff url(http://www.codingforums.com/attachment.php?attachmentid=10470&d=1320824327);
    	text-align: center;
    }
    </style>
    </head>
    <body>
        <div id="d1">
        	<h2>some text</h2>
        </div>
    </body>
    </html>
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad


  •  

    Posting Permissions

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