当我尝试在我的“内容” div上应用translate3d(150px,0px,0px);
时,页面顶部会出现一个空白块。我不知道如何解决。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<style>
html, body {
margin: 0;
height: 100%;
}
#side-panel {
color: white;
width: 150px;
height: 100%;
background: #1BA39C;
position: absolute;
top: 0;
left: 0;
transition: all .2s ease-out;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
li {
margin: 0px;
padding: 10px;
}
li:hover {
background-color: red;
}
#nav-bar {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 40px;
background: black;
}
.hide {
transform: translate3d(-150px,0,0);
}
.bodyhide {
transform: translate3d(0,0,0);
}
.show {
transform: translate3d(0,0,0);
}
.bodyshow {
transform: translate3d(150px,0px,0px);
}
#content {
transition: all .2s ease-out;
}
#subcontent {
position: relative;
top: 50px;
}
</style>
<div id="side-panel" class="hide">
<ul>
<li>
<a href='#'>Uno</a>
</li>
<li>
<a href='#'>Dos</a>
</li>
<li>
<a href='#'>Three</a>
</li>
<li>
<a href='#'>Cuatro</a>
</li>
<li>
<a href='#'>Cinco</a>
</li>
</ul>
</div>
<div id='content'>
<div id='nav-bar'>
<button id="panel-button">Panel</button>
</div>
<div id='subcontent'>
<p>Content</p>
</div>
</div>
<script type='text/javascript'>
var panel = document.getElementById("side-panel");
var button = document.getElementById("panel-button");
var myContent = document.getElementById("content");
panel.onclick = function () {
panel.className = "hide";
myContent.className = "bodyhide";
};
button.onclick = function () {
panel.className = "show";
myContent.className = "bodyshow";
};
</script>
</body>
这里的codepen http://codepen.io/sbaglieri/pen/LERQXy
最佳答案
不是添加空格的翻译,而是position:fixed
上的#nav-bar
。
解决此问题的一种方法是将overflow: hidden
添加到#content
关于html - CSS转换将顶部的空白块翻译,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27662730/