gpt4 book ai didi

javascript - html标签和正文之间的奇怪空白

转载 作者:太空宇宙 更新时间:2023-11-03 23:37:34 25 4
gpt4 key购买 nike

我试图获得一个全屏图像背景,其中心有一个可滚动的 div,所以我写了这段代码:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bio</title>
<link href="../css/layout-base.css" rel="stylesheet">
<script type="text/javascript" src="../jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(window).ready(function(){
var background = $('#background');
var scrollable = $('#scrollable-container');
var halfWhite = $('#halfWhite');
var halfBlack = $('#halfBlack');
/* calcolo dimensione finestra */
var maxWidth = $(window).width();
var maxHeight = $(window).height();

/* settaggio dimensioni immagine sfondo */
background.css("height",maxHeight);
background.css("width",maxWidth);

scrollable.css("height",maxHeight);

/* settaggio dimensioni riempimento sfondo */
halfWhite.css("height",maxHeight);
halfWhite.css("width",maxWidth/2);
halfBlack.css("height",maxHeight);
halfBlack.css("width",maxWidth/2);
});
</script>
</head>
<body>
<div id="background">
<div id="halfWhite"></div>
<div id="halfBlack"></div>
<div id="scrollable-container">
<div class="content">
<a href="#" class="menu" id="home" target="_self"><img src="../media/index/bio1.png"/></a>
<a href="#" class="menu" id="events" target="_self"><img src="../media/index/events2.png"/></a>
<a href="#" class="menu" id="gallery" target="_self"><img src="../media/index/gallery3.png"/></a>
<a href="#" class="menu" id="disco" target="_self"><img src="../media/index/disco4.png"/></a>
</div><!--div content -->
</div>
</div><!-- div background -->
</body>
</html>

与相关的CSS:

body{
overflow:hidden;
margin:0!important;
}
#background{
background-image:url(../media/index/back.png);
background-size:contain;
background-position:center;
background-repeat:no-repeat;
}
#halfWhite{
position:relative;
background-color: white;
z-index: -10;
float: left;
}
#halfBlack{
position:relative;
background-color: black;
z-index: -10;
float: right;
}
#scrollable-container{margin-left: 15%;margin-right: 15%;background-color:rgba(0,0,0,0.00)}
.content{
margin-top:1%;
height:100%;
position: relative;
padding-left: 5%;
padding-right: 5%;
box-shadow: -10px 2px 15px #dedede,10px -2px 15px #dedede;
-moz-box-shadow:-10px 2px 15px #dedede,10px -2px 15px #dedede;
-webkit-box-shadow:-10px 2px 15px #dedede,10px -2px 15px #dedede;
background-color:rgba(255,255,255,0.8);
}
.menu{width:15%}
.menu img{width:100%}
#home{position:absolute;top:0px;left:0px;}
#events{position:absolute;top:0px;right:0px;}
#gallery{position:absolute;bottom:0px;left:0px;}
#disco{position:absolute;bottom:0px;right:0px;}

结果看起来不错,但我注意到 html 标记和正文之间有一个奇怪的空白区域...我该如何避免这种行为?它的原因可能是什么?不幸的是,我对网络开发还很陌生,所以我什至不知道这是否是获得这种布局的正确方法。有没有人有一些提示?

最佳答案

我评论中提到的边距问题 collapsing margin

http://www.w3.org/TR/CSS2/box.html#collapsing-margins

您可以从 .content 中删除 margin top 并将 padding-top 添加到容器 #scrollable-container

我不确定这是不是你想做的,但我认为是

关于javascript - html标签和正文之间的奇怪空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23664623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com