【发布时间】:2020-04-17 22:05:34
【问题描述】:
我正在尝试将我的菜单水平放置在移动版本上:
但是,当我将值修改为:
.left-side(白色): 宽度:100% 高度:40vh
和
.menu(右侧黑色): 宽度:100%; 高度:60vh;
但是当我这样做时,菜单会中断。右侧菜单位于顶部。
我已经看到,如果我将导航的高度更改为 100%,它会起作用。但是当我回到桌面版本时,当使用元素检查器时,菜单一直在顶部(图层)(我无法选择文本)。我尝试使用 z-index 并没有。我认为导航应该是 height: 80px in desktop and 100vh 但我不知道。
这里的代码笔:https://codepen.io/ZeR0ByTe/pen/KKdzmJV?editors=0100
<nav id="navbar">
<div id="left-side" class="left-side">
<div class="profile">
<img class="picture" src="img/foto.jpg" alt="">
</div>
</div>
<div id="menu" class="menu">
<a href="#">Home</a>
<a href="#">Education</a>
<a href="#">Experience</a>
<a href="#">Languages</a>
<a href="#">Skills</a>
<a href="#">Portfolio</a>
<a href="#">References</a>
<a href="#">Contact me</a>
</div>
<div class="containerIconMobile">
<div id="toggle" class="iconMobile">
</div>
</div>
</nav>
<header>
<div class="overlay"></div>
<div class="header-content">
<div class="content">
<h1 class="main-title">Diego J. <span>Franchina</span></h1>
<h2 class="second-title">Web <span>Designer</span> / Web <span>Developer</span></h2>
</div>
<div class="social-icons">
<i class="social-icon fa fa-facebook-official fa-2x" aria-hidden="true"></i>
<i class="social-icon fa fa-instagram fa-2x" aria-hidden="true"></i>
<i class="social-icon fa fa-linkedin fa-2x" aria-hidden="true"></i>
<i class="social-icon fa fa-github fa-2x" aria-hidden="true"></i>
</div>
</div>
</header>
<main>
<div class="container">
<div class="title-section">
<h2>EDUCATION</h2>
<hr class="line-titles">
</div>
<div class="container-education">
<div class="education-schools">
<h3 class="item-school">Instituto Superior Argentino de Computación</h3>
<h4 class="item-title-school">Analista de Sistemas</h4>
<p class="item-description-school">Legalizado y Certificado en el Ministerio de Relaciones Exteriores para poder trabajar en el Exterior.</p>
<hr class="line-separator">
</div>
<div class="education-years">
<p class="item-description-school">2009 - 2012</p>
</div>
<hr class="line-separator">
</div>
<div class="container-education">
<div class="education-schools">
<h3 class="item-school">Nuestra Sra. del Buen y Perpetuo Socorro</h3>
<h4 class="item-title-school">Bachillerato</h4>
<p class="item-description-school">Perito Mercantil.</p>
<hr class="line-separator">
</div>
<div class="education-years">
2009 - 2012
</div>
</div>
</div>
<div class="container">
<div class="title-section">
<h2>EDUCATION</h2>
<hr class="line-titles">
</div>
<div class="container-education">
<div class="education-schools">
<h3 class="item-school">Instituto Superior Argentino de Computación</h3>
<h4 class="item-title-school">Analista de Sistemas</h4>
<p class="item-description-school">Legalizado y Certificado en el Ministerio de Relaciones Exteriores para poder trabajar en el Exterior.</p>
<hr class="line-separator">
</div>
<div class="education-years">
<p class="item-description-school">2009 - 2012</p>
</div>
<hr class="line-separator">
</div>
<div class="container-education">
<div class="education-schools">
<h3 class="item-school">Nuestra Sra. del Buen y Perpetuo Socorro</h3>
<h4 class="item-title-school">Bachillerato</h4>
<p class="item-description-school">Perito Mercantil.</p>
<hr class="line-separator">
</div>
<div class="education-years">
2009 - 2012
</div>
</div>
</div>
<div class="container">
<div class="title-section">
<h2>EDUCATION</h2>
<hr class="line-titles">
</div>
<div class="container-education">
<div class="education-schools">
<h3 class="item-school">Instituto Superior Argentino de Computación</h3>
<h4 class="item-title-school">Analista de Sistemas</h4>
<p class="item-description-school">Legalizado y Certificado en el Ministerio de Relaciones Exteriores para poder trabajar en el Exterior.</p>
<hr class="line-separator">
</div>
<div class="education-years">
<p class="item-description-school">2009 - 2012</p>
</div>
<hr class="line-separator">
</div>
<div class="container-education">
<div class="education-schools">
<h3 class="item-school">Nuestra Sra. del Buen y Perpetuo Socorro</h3>
<h4 class="item-title-school">Bachillerato</h4>
<p class="item-description-school">Perito Mercantil.</p>
<hr class="line-separator">
</div>
<div class="education-years">
2009 - 2012
</div>
</div>
</div>
</main>
CSS
$grey: #222222;
$secondTitle: #999999;
$pink: #fd5c63;
$white: #ffffff;
$black: #000000;
$primary-color: #ffc20e;
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Lato", sans-serif;
}
html {
overflow-x: hidden;
}
span {
color: $primary-color;
font-weight: bolder;
}
body {
color: $white;
width: 100%;
background-color: $grey;
}
header {
width: 100%;
height: 100vh;
position: relative;
background: url(../img/wall2.jpg);
background-position: center;
background-size: cover;
.overlay {
background-color: rgba(0, 0, 0, 0.7);
width: 100%;
height: 100%;
position: absolute;
top: 0;
z-index: 0;
}
.header-content {
width: 40%;
height: 100vh;
position: absolute;
display: flex;
flex-direction: column;
justify-content: center;
padding: 50px;
text-align: center;
z-index: 1;
.main-title {
font-size: 54px;
font-weight: bold;
text-shadow: 4px 4px 2px rgba(0, 0, 0, 0.7);
}
.second-title {
text-shadow: 4px 4px 2px rgba(0, 0, 0, 0.7);
padding: 20px;
}
.social-icons {
display: flex;
justify-content: space-between;
padding: 10px;
.social-icon {
text-shadow: 4px 4px 2px rgba(0, 0, 0, 0.7);
padding: 10px;
transition: 1s ease;
&:hover {
color: $primary-color;
}
}
}
}
}
nav {
display: flex;
width: 100%;
height: 80px;
color: $black;
position: fixed;
top: 0;
z-index: 4;
.left-side {
width: 40%;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: rgba(119, 116, 116, 0.95);
position: absolute;
left: -100%;
transition: 1s ease;
z-index: 5;
&.left-effect {
left: 0 !important;
}
.profile {
.picture {
border-radius: 50%;
width: 200px;
height: 200px;
object-fit: cover;
border: 5px solid $primary-color;
}
}
}
.menu {
position: absolute;
right: -100%;
width: 60%;
height: 100vh;
background-color: rgba(0, 0, 0, 0.6);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
transition: 1s ease;
&.right-effect {
right: 0;
}
a {
display: flex;
flex-direction: column;
text-decoration: none;
color: #999999;
font-size: 24px;
font-weight: bolder;
letter-spacing: 5px;
padding: 10px 0;
transition: 1s;
text-transform: uppercase;
&:hover {
color: $primary-color;
}
}
}
.containerIconMobile {
position: absolute;
top: 30px;
right: 30px;
.iconMobile {
width: 30px;
height: 30px;
position: relative;
cursor: pointer;
&:before {
content: '';
position: absolute;
top: 7px;
width: 100%;
height: 2px;
background-color: $white;
transition: 1s ease;
}
&:after {
content: '';
position: absolute;
bottom: 7px;
width: 100%;
height: 2px;
background-color: $white;
transition: 1s ease;
}
&.active {
&:before {
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(45deg);
}
&:after {
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(-45deg);
}
}
}
}
}
main {
.container {
width: 98%;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
z-index: 4;
.title-section {
text-align: center;
font-size: 24px;
margin: 20px;
}
.line-titles {
border: 3px solid #ffc20e;
width: 25%;
margin: 10px auto;
}
}
.container-education {
width: 70%;
display: flex;
justify-content: center;
align-items: center;
}
.education-schools {
width: 70%;
margin-bottom: 30px;
.item-school {
font-size: 24px;
}
.item-title-school {
font-size: 22px;
color: #999999;
}
.item-description-school {
font-size: 20px;
margin: 10px 0;
}
.line-separator {
border: 3px solid #999999;
width: 25%;
margin: 30px auto 0 auto;
}
}
.education-years {
width: 30%;
font-size: 20px;
text-align: right;
}
}
@media (max-width: 480px) {
body {
header {
.header-content {
width: 100%;
.main-title {
font-size: 35px;
}
.second-title {
font-size: 18px;
}
}
}
nav {
.left-side {
top: 0;
background-color: rgba(119, 116, 116, .9);
z-index: 2;
.profile {
.picture {
width: 120px;
height: 120px;
}
}
}
.menu {
z-index: 2;
background-color: rgba(0, 0, 0, 0.9);
right: -100% !important;
// bottom: -825%;
&.right-effect {
right: 0 !important;
}
a {
font-size: 18px;
}
}
.containerIconMobile {
z-index: 4;
.iconMobile {
&:before {
background-color: $white;
}
&:after {
background-color: $white;
}
}
}
}
main {
.container-education {
width: 90%;
flex-direction: column;
}
}
}
}
JS
const toggle = document.getElementById("toggle");
const leftSide = document.getElementById("left-side");
const navbar = document.getElementById("navbar");
const menu = document.getElementById("menu");
toggle.addEventListener("click", () =>{
// navbar.classList.toggle("active")
toggle.classList.toggle("active");
leftSide.classList.toggle("left-effect");
menu.classList.toggle("right-effect");;
})
希望有人可以帮助并理解我的帖子。如果没有,我会尝试更具体的
谢谢
【问题讨论】:
-
感谢您的建议@AymanMorsy,这是我与 SASS 的第一个项目。我读过嵌套选择器是正确的形式。我在这里读到:sass-lang.com/documentation/syntax,在 SCSS 中就像我的帖子。现在我很困惑。谢谢
标签: javascript html css