在div中移动div?

时间:2013-04-14 08:11:43

标签: css

嗨,我基本上想要向下移动我的topBar div内的logo div但是当我使用填充或边距时,它会移动整个顶部栏或徽标重复自己(是的,我尝试过背景 - 重复:不重复)

<!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>Untitled Document</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>

<body lang="en">
<div class="alert">Do you want advertsing space? Contact us: <b>advertising@chattrd.com</b></div>
<div class="topBar">
<div id="logo">
<p>chattrd</p>
</div>
</div>
</body>
</html>

body {
    background: #F7F7F7;
    font-family:Tahoma, Geneva, sans-serif;
    margin: 0;
    padding: 0;
}
.alert {
    font-size: 10px;
    color: #FFF;
    background: #1f1f1f;
    height: 14px;
    padding-left: 10px;
    font-family: Arial;
}
.topBar {
    background: #0C3;
    height: 40px;
}
#logo {
    background-image:url(../images/logo.png);
    height: 26px;
    width: 121px;
    overflow: hidden;
    display: block;
    text-indent:-999px;
}

1 个答案:

答案 0 :(得分:0)

它的行为方式是您将图像用作背景。如果你想继续这种方法,最简单的方法就是在#logo-div之前放置另一个div,如下所示:

<body lang="en">
<div class="alert">Do you want advertsing space? Contact us: <b>advertising@chattrd.com</b></div>
<div class="topBar">
<div id="spaceDiv"></div>
<div id="logo"></div>
</div>
</body>

spaceDiv的高度可用于使用以下CSS移动#logo-div:

#spaceDiv{
    height:6px;
}