我在css中给了float:left属性。但它没有得到应用。这导致我的完整布局出现问题。 为什么浮子没有被应用?任何人都可以解释一下。我怎样才能解决这个问题?谢谢。
function openNav() {
document.getElementsByClassName('sidenav')[0].style.width = '20vw';
document.getElementsByClassName('sidenav-fix-closebtn')[0].style.visibility = 'visible';
document.getElementsByClassName('sidenav-fix-open-btn')[0].style.visibility = 'hidden';
}
function closeNav() {
document.getElementsByClassName('sidenav')[0].style.width = 0
document.getElementsByClassName('sidenav-fix-closebtn')[0].style.visibility = 'hidden';
document.getElementsByClassName('sidenav-fix-open-btn')[0].style.visibility = 'visible';
}
.sidenav-fix {
float: left !important;
background-color: #EAEAEA;
height: 100%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
transition: 0.5s;
min-width: 50px;
display: block;
}
.sidenav-fix span {
font-size: 40px;
cursor: pointer;
text-align: center;
}
.sidenav-fix-open-btn {
text-align: center;
}
.sidenav-fix-text {
opacity: 1;
transform: translateY(50vh) rotate(-90deg);
white-space: nowrap;
}
.sidenav-fix-close-box {
font-size: 36px;
text-align: center;
position: fixed;
bottom: 0;
}
.sidenav-fix-closebtn {
color: #818181;
text-decoration: none;
visibility: hidden;
}
.sidenav {
height: 100%;
z-index: 1;
top: 0;
width: 0;
background-color: #EAEAEA;
overflow-x: hidden;
transition: 0.5s;
padding-top: 30vh;
float: left;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s;
}
.sidenav a:hover {
color: #000000;
transition: 0.5s;
}
<body>
<div class="">
<div class="sidenav-fix ">
<div class="sidenav-fix-open-btn">
<span onclick="openNav()">☰ </span>
</div>
<p class="sidenav-fix-text">ABCD</p>
<div class="sidenav-fix-close-box">
<a href="javascript:void(0)" class="sidenav-fix-closebtn" onclick="closeNav()">×</a>
</div>
</div>
<div class="sidenav">
<a href="#">HOME</a>
<a href="#">PROJECTS</a>
<a href="#">PEOPLE</a>
<a href="#">CONTACT</a>
</div>
</div>
</body>
答案 0 :(得分:1)
您有position:fixed
和top:0
- 这会覆盖float
属性;