我正在构建一个以视频为背景的网站。我希望所有 div 都居中且响应迅速,这就是我使用宽度和高度 100% 的原因。然后我有一个覆盖 div,它使用 jquery 在单击时淡入和淡出。我的问题是,在这个 div 淡入之后,我似乎无法在它周围获得均匀的边距。我想要 margin 的 div 的 ID 为“信息”。
我的 html 看起来像这样:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="description" content=""/>
<meta name="keywords"content=""/>
<title></title>
<link href="css/main.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn").click(function(){
$("#info").fadeToggle("slow");
});
});
</script>
</head>
<header>
<div id="nav">
<p><a id="btn" href="#">+</a></p>
</div>
</header>
<body>
<div id="container">
<div id="info">
</div>
</div>
</body>
<video id="video_background" src="vid/147000037.mp4" autoplay>
</html>
和我的CSS:
* {
margin: 0;
padding: 0;
}
body {
font-family: "HelveticaNeue-UltraLight","HelveticaNeue-Light","Helvetica Neue",Helvetica,Arial,sans-serif;
}
header {
z-index: 999;
display: block;
height: auto;
width: 100%;
position: fixed;
}
header a {
text-decoration: none;
font-size: 1.8em;
color: #000000;
}
#nav {
position: relative;
float: right;
top: 15px;
right: 20px;
color: #000000;
}
#container {
height: 100%;
width: 100%;
display: block;
}
#video_background {
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: -1000;
}
#info {
height: 100%;
width: 100%;
background: rgba(255,255,255,0.97);
z-index: 900;
display: none;
position: fixed;
margin: 10px;
vertical-align: center;
}
最佳答案
由于您的信息框具有固定的定位,您可以在您的 css 中省略高度/宽度和边距,并使用偏移量创建一个具有良好边距的响应式容器。只需将您的 #info
css 更改为以下内容:
#info {
/* omit height & width */
background: #bada55; /* Just because white on white is tough to see */
z-index: 900;
display: none;
position: fixed;
/* omit margin and use according offsets */
top:15px;left:15px;right:15px;bottom:15px;
vertical-align: center;
}
查看working here .
关于html - 宽度为 100% 高度为 100% 的 div 上的边距位于另一个宽度为 100% 高度为 100% 的 div 内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15966570/