Search code examples
htmlcsscenterliquid-layout

Center liquid layout


I can't see where is problem, but .topbar isn't centered as it should be... Distance from left and right should be equal.

http://jsfiddle.net/P4TpQ/

This is my code:

<!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">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>asd</title>
</head>
<body>
<div class="wrapper">
  <div class="topbar">asd</div>
</div>
</body>
</html>


* {
    margin:0;
    padding:0;
}

body {
    background:#000;
    font:14px Arial, Helvetica, sans-serif;
    background-color:#FFF;
    background-repeat:repeat;
}
.wrapper {
    width:90%;
    min-widht:200px;
    margin:0 auto;
}
.wrapper * {
    float:left;
}
.topbar {
    width:inherit;
    height:50px;
    background:#000;
}
​

Solution

  • You are inheriting width:90% - either set it to 100% explicitly or do not float wrapper descendants: http://jsfiddle.net/P4TpQ/3/

    Also: floating all wrapper descendants has a pretty good potential to bite you later on. If absolutely needed, try a direct child selector like .wrapper>*