I have a problem with positioning logo and title divs. Logo works fine but the title div doesn’t position where exactly I want. Its positioned becomes relevant to logo instead of header content div.
Thanks in advance
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style>
*
{
margin:0px;
padding:0px;
}
#header_wrap
{
float: left;
width: 100%;
height: 150px;
background: #dddddd;
}
#header_content
{
width: 850px;
height: 150px;
margin: 0 auto 0;
background: #cccccc;
}
#logo
{
width: 50px;
height: 50px;
background: #ffffff;
position: relative;
left: 10px;
top: 50px;
}
#title
{
width: 100px;
height: 50px;
background: #ffffff;
position: relative;
left: 100px;
top: 10px;
}
</style>
</head>
<body>
<div id="header_wrap">
<div id="header_content">
<div id="logo">LOGO</div>
<div id="title">TITLE</div>
</div>
</div>
</body>
</html>
position:relative;will change the position of an element with respect to its original position:You want to use
position:absolutein order to change the position of an element with respect to the next parent which position isn’tstatic:Keep in mind that this will remove your elements of the content flow, so you might need to apply a height on
#header_content.See also: