我的网站顶级菜单遇到了一些麻烦:当我设置一个保证金顶部时,我div
中的一个正在移动身体的位置。
背景: 今天我决定对它实施基金会,并注意到他们将身体位置设置为相对的,没有什么大不了解一个小的可理解的问题。 我的顶级菜单由导航栏下方的2个主要div,导航栏和徽标组成。我的导航栏位置是绝对的,而徽标设置为相对位置,因此我网站的元素可以相对于我的徽标位置定位。
当我设置30px的上边距到我的header-logo
时会发生什么,并且你可以看到导航栏也从30px移动,因为事实上当我身体被移动了30px实际上只将它设置为header-logo
(我知道它因为页面可以向下滚动到这个精确的30px以弥补缺失体积的30px)
@charset "utf-8";
/* CSS Document */
body {
margin: 0;
padding: 0;
position: relative;
}
body.ftp li#current-ftp,
body.projects li#current-projects,
body.contact li#current-contact {
text-shadow: 0 0 1px #666;
}
#navbar-header {
position: absolute;
top: 0;
right: 0;
left: 0;
margin: 0;
padding: 0;
}
#navbar-header #menu-left {
float: left;
display: inline-block;
margin-left: 20px;
font-family: 'Comfortaa', cursive;
font-size: 16px;
line-height: 1;
color: #3F3F3F;
}
#navbar-header #menu-right {
float: right;
display: inline-block;
margin-right: 20px;
font-family: 'Comfortaa', cursive;
font-size: 16px;
line-height: 1;
color: #3F3F3F;
}
#navbar-header ul {
display: inline-block;
list-style-type: none;
margin: 5px 0 0 0;
padding: 0;
vertical-align: top;
font-size: 16px;
line-height: 1;
}
#navbar-header ul.icon li {
display: inline-block;
padding: 2px;
margin: 0;
vertical-align: top;
}
#navbar-header ul.txt li {
font-family: 'Comfortaa', cursive;
font-size: 16px;
color: #3F3F3F;
display: inline-block;
margin: 0;
padding: 8px 0 0 0;
}
#navbar-header ul.txt li a {
font-family: 'Comfortaa', cursive;
font-size: 16px;
color: #3F3F3F;
text-decoration: none;
margin: 0;
padding: 8px;
}
#navbar-header ul.txt a:hover {
text-shadow: 0 0 1px #666;
}
#navbar-header #login-menu, #navbar-header #panel-menu {
position: absolute;
top: 0;
right: 0;
margin: 0;
padding: 0;
}
#navbar-header #login-bubble {
font-family: 'Open Sans', sans-serif;
z-index: 5;
visibility: hidden;
color: #AAAAAA;
position: absolute;
right: 10px;
top: 50px;
width: 250px;
height: 130px;
padding: 0 15px 0 15px;
background: #FFF;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
border: #CCC solid 1px;
-moz-box-shadow:0 0 8px 0 #DDD;
-webkit-box-shadow:0 0 8px 0 #DDD;
box-shadow:0 0 8px 0 #DDD;
}
#navbar-header #login-bubble:after {
content: '';
position: absolute;
border-style: solid;
border-width: 0 10px 10px;
border-color: #FFF transparent;
display: block;
width: 0;
z-index: 1;
top: -10px;
left: 214px;
}
#navbar-header #login-bubble:before {
content: '';
position: absolute;
border-style: solid;
border-width: 0 11px 11px;
border-color: #DDD transparent;
display: block;
width: 0;
z-index: 0;
top: -12px;
left: 213px;
}
#login-username, #login-password {
margin-bottom: 15px;
}
#navbar-header .username-icon {
position: absolute;
display: block;
color: darken(#EDEDED, 10%);
left: 23px;
top: 15px;
font-size: 20px;
line-height: normal;
}
#navbar-header .password-icon {
position: absolute;
display: block;
color: darken(#EDEDED, 10%);
left: 25px;
top: 62px;
font-size: 20px;
line-height: normal;
}
#navbar-header input#txt_username, #navbar-header input#txt_password {
font-family: inherit;
box-sizing:border-box;
border-radius: 3px;
font-size: 14px;
height: 30px;
line-height: 30px;
width: 100%;
margin: 15px 0 0 0;
padding: 0 8px 0 30px ;
display: block;
background-color : #f7f7f7;
border: 1px solid #CCC;
transition: 0.3s ease-out;
-webkit-transition: 0.3s ease-out;
-moz-transition: 0.3s ease-out;
color: #333;
}
#navbar-header input#txt_username:-webkit-autofill, #navbar-header input#txt_password:-webkit-autofill,
#navbar-header input#txt_username:-webkit-autofill:hover, #navbar-header input#txt_password:-webkit-autofill:hover,
#navbar-header input#txt_username:-webkit-autofill:focus, #navbar-header input#txt_password:-webkit-autofill:focus {
-webkit-box-shadow: 0 0 0px 1000px #f7f7f7 inset;
-webkit-text-fill-color: #333;
}
#navbar-header input#txt_username:focus, #navbar-header input#txt_password:focus {
padding: 0 8px 0 10px ;
background-color : #f7f7f7;
border-color: #a6ba89;
outline: 0px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 2px rgba(109,157,78,.6);
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 2px rgba(109,157,78,.6);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 2px rgba(109,157,78,.6)
}
.placeholder {color: #aaa }
::-webkit-input-placeholder {color: #aaa}
:-moz-placeholder {color: #aaa}
#navbar-header #forgotten-pwd {
font-size: 13px;
font-family: inherit;
margin-top: 12px;
display: inline-block;
}
#navbar-header #forgotten-pwd a {
text-decoration: none;
color: #999;
}
#navbar-header #forgotten-pwd a:hover {
color: #f48a00;
}
#button-border {
width: 61px;
height: 30px;
border-bottom-left-radius: 32px;
border-bottom-right-radius: 32px;
border: 1px solid #CCC;
border-top: 0;
position: absolute;
right: 26px;
bottom: -30px;
-moz-box-shadow:0 0 8px 0 #DDD;
-webkit-box-shadow:0 0 8px 0 #DDD;
box-shadow:0 0 8px 0 #DDD;
}
#submit-button {
font-family: inherit;
z-index: 1000;
position: absolute;
top: 105px;
right: 34px;
}
#sub-login {
font-family: inherit;
width: 45px;
height: 45px;
display: block;
margin: 0 auto -15px auto;
background: #f7f7f7;
border-radius: 100%;
border: 1px solid #a6ba89;
color: #a6ba89;
font-size: 26px;
line-height: 26px;
cursor: pointer;
box-shadow: 0px 0px 0px 7px #FFF;
transition: 0.3s ease-out;
}
#sub-login:hover, #sub-login:focus {
background: #a6ba89;
color: #f7f7f7;
outline: 0;
}
#navbar-header #panel-bubble {
z-index: 5;
visibility: hidden;
color: #AAAAAA;
position: absolute;
right: 10px;
top: 50px;
width: 220px;
height: 250px;
padding: 0px;
background: #FFF;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
border: #CCC solid 1px;
-moz-box-shadow:0 0 8px 0 #CCC;
-webkit-box-shadow:0 0 8px 0 #DDD;
box-shadow:0 0 8px 0 #DDD;
}
#navbar-header #panel-bubble:after {
content: '';
position: absolute;
border-style: solid;
border-width: 0 10px 10px;
border-color: #FFF transparent;
display: block;
width: 0;
z-index: 1;
top: -10px;
left: 145px;
}
#navbar-header #panel-bubble:before {
content: '';
position: absolute;
border-style: solid;
border-width: 0 11px 11px;
border-color: #DDD transparent;
display: block;
width: 0;
z-index: 0;
top: -12px;
left: 144px;
}
#panel-more {
border-top: 1px solid #EEE;
position: absolute;
bottom: 0px;
right: 0px;
left: 0px;
height: 30px;
witdth: 100%;
background-color: #F7F7F7;
font: 16px Candara;
text-align: center;
vertical-align: middle;
color: #909090;
padding-top: 3px;
}
#header-logo {
position: relative;
width: 333px;
margin: 30px auto 60px auto;
}

<?php
// start session & handle logout
session_start();
if(isset($_GET["logout"]) && $_GET["logout"] == 1){
session_destroy();
session_start();
if(isset($_SERVER['HTTP_REFERER'])) {
header('Location: '.$_SERVER['HTTP_REFERER']);
} else {
header('Location: /index.php');
}
exit;
}
?>
<nav id="navbar-header">
<div id="menu-left">
<ul class="txt">
<?php if (isset($_SESSION['simple_auth']) && $_SESSION['simple_auth'] == true && $_SESSION['simple_auth']['username'] != 'guest'):?>
<li><?php echo "welcome, " . $_SESSION['simple_auth']['username'] . " !"; ?></li>
<?php else:?>
<li>not logged in</li>
<?php endif;?>
</ul>
</div>
<div id="menu-right">
<ul class="txt">
<li id="current-ftp"><a href="/ftp">ftp</a></li>
<li id="current-projects"><a href="/projects">projects</a></li>
<li id="current-contact"><a href="/contact">contact</a></li>
</ul>
<ul class="icon">
<li id="menu-panel">
<a href="#"><img src="/style/img/icon_panel.jpg" width="30" height="30" alt="" name="icon_panel"
onmouseover="icon_panel.src='/style/img/icon_panel_hover.jpg'"
onmouseout="icon_panel.src='/style/img/icon_panel.jpg'" /></a>
</li>
<?php if (isset($_SESSION['simple_auth']) && $_SESSION['simple_auth'] == true && $_SESSION['simple_auth']['username'] != 'guest'):?>
<li id="menu-logout">
<a href="?logout=1"><img src="/style/img/logout.jpg" width="30" height="30" alt="" name="logout"
onmouseover="logout.src='/style/img/logout_hover.jpg'"
onmouseout="logout.src='/style/img/logout.jpg'" /></a>
</li>
<?php else:?>
<li id="menu-login">
<a href="#"><img src="/style/img/login.jpg" width="30" height="30" alt="" name="login"
onmouseover="login.src='/style/img/login_hover.jpg'"
onmouseout="login.src='/style/img/login.jpg'" /></a>
</li>
<?php endif;?>
</ul>
</div>
<div id="login-menu">
<div id="login-bubble">
<form method="post" action="/ftp/index.php?login=1" autocomplete="false">
<span id="login-username">
<input type="text" name="username" id="txt_username" placeholder="username" required="" value="" />
<span class="username-icon"><i class="fa fa-user"></i></span>
</span>
<span id="login-password">
<input type="password" name="password" id="txt_password" placeholder="password" required="" />
<span class="password-icon"><i class="fa fa-lock"></i></span>
</span>
<span id="forgotten-pwd">
<a href=""><span>Forgotten Password ?</span></a>
</span>
<span id="submit-button">
<input type="hidden" name="redirect" value="<?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>" />
<button type="submit" name="submit" id="sub-login"><i id="submit"class="fa fa-long-arrow-right"></i></button>
</span>
<span id="button-border"></span>
</form>
</div>
</div>
<div id="panel-menu">
<div id="panel-bubble">
<span id="panel-more">More</span>
</div>
</div>
</nav>
<div id="header-logo">
<a href="/"><img src="/style/img/apatikgg_logo.png" width="331" height="96" alt=""/></a>
</div>
&#13;
更奇怪的是,似乎我可以通过将这行代码添加到我的身体css:border: 1px solid red;
来解决这个问题,是的,如果我为我的身体设置边框,一切都如此预计,见这里:
@charset "utf-8";
/* CSS Document */
body {
margin: 0;
padding: 0;
position: relative;
border: 1px solid red;
}
body.ftp li#current-ftp,
body.projects li#current-projects,
body.contact li#current-contact {
text-shadow: 0 0 1px #666;
}
#navbar-header {
position: absolute;
top: 0;
right: 0;
left: 0;
margin: 0;
padding: 0;
}
#navbar-header #menu-left {
float: left;
display: inline-block;
margin-left: 20px;
font-family: 'Comfortaa', cursive;
font-size: 16px;
line-height: 1;
color: #3F3F3F;
}
#navbar-header #menu-right {
float: right;
display: inline-block;
margin-right: 20px;
font-family: 'Comfortaa', cursive;
font-size: 16px;
line-height: 1;
color: #3F3F3F;
}
#navbar-header ul {
display: inline-block;
list-style-type: none;
margin: 5px 0 0 0;
padding: 0;
vertical-align: top;
font-size: 16px;
line-height: 1;
}
#navbar-header ul.icon li {
display: inline-block;
padding: 2px;
margin: 0;
vertical-align: top;
}
#navbar-header ul.txt li {
font-family: 'Comfortaa', cursive;
font-size: 16px;
color: #3F3F3F;
display: inline-block;
margin: 0;
padding: 8px 0 0 0;
}
#navbar-header ul.txt li a {
font-family: 'Comfortaa', cursive;
font-size: 16px;
color: #3F3F3F;
text-decoration: none;
margin: 0;
padding: 8px;
}
#navbar-header ul.txt a:hover {
text-shadow: 0 0 1px #666;
}
#navbar-header #login-menu, #navbar-header #panel-menu {
position: absolute;
top: 0;
right: 0;
margin: 0;
padding: 0;
}
#navbar-header #login-bubble {
font-family: 'Open Sans', sans-serif;
z-index: 5;
visibility: hidden;
color: #AAAAAA;
position: absolute;
right: 10px;
top: 50px;
width: 250px;
height: 130px;
padding: 0 15px 0 15px;
background: #FFF;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
border: #CCC solid 1px;
-moz-box-shadow:0 0 8px 0 #DDD;
-webkit-box-shadow:0 0 8px 0 #DDD;
box-shadow:0 0 8px 0 #DDD;
}
#navbar-header #login-bubble:after {
content: '';
position: absolute;
border-style: solid;
border-width: 0 10px 10px;
border-color: #FFF transparent;
display: block;
width: 0;
z-index: 1;
top: -10px;
left: 214px;
}
#navbar-header #login-bubble:before {
content: '';
position: absolute;
border-style: solid;
border-width: 0 11px 11px;
border-color: #DDD transparent;
display: block;
width: 0;
z-index: 0;
top: -12px;
left: 213px;
}
#login-username, #login-password {
margin-bottom: 15px;
}
#navbar-header .username-icon {
position: absolute;
display: block;
color: darken(#EDEDED, 10%);
left: 23px;
top: 15px;
font-size: 20px;
line-height: normal;
}
#navbar-header .password-icon {
position: absolute;
display: block;
color: darken(#EDEDED, 10%);
left: 25px;
top: 62px;
font-size: 20px;
line-height: normal;
}
#navbar-header input#txt_username, #navbar-header input#txt_password {
font-family: inherit;
box-sizing:border-box;
border-radius: 3px;
font-size: 14px;
height: 30px;
line-height: 30px;
width: 100%;
margin: 15px 0 0 0;
padding: 0 8px 0 30px ;
display: block;
background-color : #f7f7f7;
border: 1px solid #CCC;
transition: 0.3s ease-out;
-webkit-transition: 0.3s ease-out;
-moz-transition: 0.3s ease-out;
color: #333;
}
#navbar-header input#txt_username:-webkit-autofill, #navbar-header input#txt_password:-webkit-autofill,
#navbar-header input#txt_username:-webkit-autofill:hover, #navbar-header input#txt_password:-webkit-autofill:hover,
#navbar-header input#txt_username:-webkit-autofill:focus, #navbar-header input#txt_password:-webkit-autofill:focus {
-webkit-box-shadow: 0 0 0px 1000px #f7f7f7 inset;
-webkit-text-fill-color: #333;
}
#navbar-header input#txt_username:focus, #navbar-header input#txt_password:focus {
padding: 0 8px 0 10px ;
background-color : #f7f7f7;
border-color: #a6ba89;
outline: 0px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 2px rgba(109,157,78,.6);
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 2px rgba(109,157,78,.6);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 2px rgba(109,157,78,.6)
}
.placeholder {color: #aaa }
::-webkit-input-placeholder {color: #aaa}
:-moz-placeholder {color: #aaa}
#navbar-header #forgotten-pwd {
font-size: 13px;
font-family: inherit;
margin-top: 12px;
display: inline-block;
}
#navbar-header #forgotten-pwd a {
text-decoration: none;
color: #999;
}
#navbar-header #forgotten-pwd a:hover {
color: #f48a00;
}
#button-border {
width: 61px;
height: 30px;
border-bottom-left-radius: 32px;
border-bottom-right-radius: 32px;
border: 1px solid #CCC;
border-top: 0;
position: absolute;
right: 26px;
bottom: -30px;
-moz-box-shadow:0 0 8px 0 #DDD;
-webkit-box-shadow:0 0 8px 0 #DDD;
box-shadow:0 0 8px 0 #DDD;
}
#submit-button {
font-family: inherit;
z-index: 1000;
position: absolute;
top: 105px;
right: 34px;
}
#sub-login {
font-family: inherit;
width: 45px;
height: 45px;
display: block;
margin: 0 auto -15px auto;
background: #f7f7f7;
border-radius: 100%;
border: 1px solid #a6ba89;
color: #a6ba89;
font-size: 26px;
line-height: 26px;
cursor: pointer;
box-shadow: 0px 0px 0px 7px #FFF;
transition: 0.3s ease-out;
}
#sub-login:hover, #sub-login:focus {
background: #a6ba89;
color: #f7f7f7;
outline: 0;
}
#navbar-header #panel-bubble {
z-index: 5;
visibility: hidden;
color: #AAAAAA;
position: absolute;
right: 10px;
top: 50px;
width: 220px;
height: 250px;
padding: 0px;
background: #FFF;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
border: #CCC solid 1px;
-moz-box-shadow:0 0 8px 0 #CCC;
-webkit-box-shadow:0 0 8px 0 #DDD;
box-shadow:0 0 8px 0 #DDD;
}
#navbar-header #panel-bubble:after {
content: '';
position: absolute;
border-style: solid;
border-width: 0 10px 10px;
border-color: #FFF transparent;
display: block;
width: 0;
z-index: 1;
top: -10px;
left: 145px;
}
#navbar-header #panel-bubble:before {
content: '';
position: absolute;
border-style: solid;
border-width: 0 11px 11px;
border-color: #DDD transparent;
display: block;
width: 0;
z-index: 0;
top: -12px;
left: 144px;
}
#panel-more {
border-top: 1px solid #EEE;
position: absolute;
bottom: 0px;
right: 0px;
left: 0px;
height: 30px;
witdth: 100%;
background-color: #F7F7F7;
font: 16px Candara;
text-align: center;
vertical-align: middle;
color: #909090;
padding-top: 3px;
}
#header-logo {
position: relative;
width: 333px;
margin: 30px auto 60px auto;
}
&#13;
<?php
// start session & handle logout
session_start();
if(isset($_GET["logout"]) && $_GET["logout"] == 1){
session_destroy();
session_start();
if(isset($_SERVER['HTTP_REFERER'])) {
header('Location: '.$_SERVER['HTTP_REFERER']);
} else {
header('Location: /index.php');
}
exit;
}
?>
<nav id="navbar-header">
<div id="menu-left">
<ul class="txt">
<?php if (isset($_SESSION['simple_auth']) && $_SESSION['simple_auth'] == true && $_SESSION['simple_auth']['username'] != 'guest'):?>
<li><?php echo "welcome, " . $_SESSION['simple_auth']['username'] . " !"; ?></li>
<?php else:?>
<li>not logged in</li>
<?php endif;?>
</ul>
</div>
<div id="menu-right">
<ul class="txt">
<li id="current-ftp"><a href="/ftp">ftp</a></li>
<li id="current-projects"><a href="/projects">projects</a></li>
<li id="current-contact"><a href="/contact">contact</a></li>
</ul>
<ul class="icon">
<li id="menu-panel">
<a href="#"><img src="/style/img/icon_panel.jpg" width="30" height="30" alt="" name="icon_panel"
onmouseover="icon_panel.src='/style/img/icon_panel_hover.jpg'"
onmouseout="icon_panel.src='/style/img/icon_panel.jpg'" /></a>
</li>
<?php if (isset($_SESSION['simple_auth']) && $_SESSION['simple_auth'] == true && $_SESSION['simple_auth']['username'] != 'guest'):?>
<li id="menu-logout">
<a href="?logout=1"><img src="/style/img/logout.jpg" width="30" height="30" alt="" name="logout"
onmouseover="logout.src='/style/img/logout_hover.jpg'"
onmouseout="logout.src='/style/img/logout.jpg'" /></a>
</li>
<?php else:?>
<li id="menu-login">
<a href="#"><img src="/style/img/login.jpg" width="30" height="30" alt="" name="login"
onmouseover="login.src='/style/img/login_hover.jpg'"
onmouseout="login.src='/style/img/login.jpg'" /></a>
</li>
<?php endif;?>
</ul>
</div>
<div id="login-menu">
<div id="login-bubble">
<form method="post" action="/ftp/index.php?login=1" autocomplete="false">
<span id="login-username">
<input type="text" name="username" id="txt_username" placeholder="username" required="" value="" />
<span class="username-icon"><i class="fa fa-user"></i></span>
</span>
<span id="login-password">
<input type="password" name="password" id="txt_password" placeholder="password" required="" />
<span class="password-icon"><i class="fa fa-lock"></i></span>
</span>
<span id="forgotten-pwd">
<a href=""><span>Forgotten Password ?</span></a>
</span>
<span id="submit-button">
<input type="hidden" name="redirect" value="<?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>" />
<button type="submit" name="submit" id="sub-login"><i id="submit"class="fa fa-long-arrow-right"></i></button>
</span>
<span id="button-border"></span>
</form>
</div>
</div>
<div id="panel-menu">
<div id="panel-bubble">
<span id="panel-more">More</span>
</div>
</div>
</nav>
<div id="header-logo">
<a href="/"><img src="/style/img/apatikgg_logo.png" width="331" height="96" alt=""/></a>
</div>
&#13;
如果我没有为此header-logo
设置保证金,则身体不会移动。
此时我更痴迷于理解这里发生了什么,而不是解决它,它没有意义,也许它会对你有用吗?
我的代码肯定有问题,特别是边界问题解决了我无法解释的问题。
我还会问一个相关的问题:为什么基金会将身体的位置设定为亲戚?我在网络开发方面相当新,到目前为止总是使用默认的静态位置,所以我想知道它的优点是什么?
无论如何,感谢阅读本文,任何帮助都会非常感激,我希望我已经足够准确,即使这很难描述,我的网站也在本地
谢谢!
-Apatik