标题基本上说明了一切。
我有一个带有徽标的导航栏,我正在尝试获取它,因此,当单击页面时,它会重定向“主页”并滚动回到页面顶部。我是html和CSS的新手,但是了解锚点的工作原理,我的其他导航栏锚点链接工作正常,我似乎无法弄清楚徽标。
谢谢!
/*
=================
Navbar
=================
*/
#home {
position: sticky;
top: 0;
z-index: 2;
}
.menu {
background-color: #fffffff6;
width: 100%;
padding: 10px 64px;
box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.15);
}
.links {
list-style: none;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.links img {
max-width: 7rem;
cursor: pointer;
margin-right: auto;
/* This pushes the logo to the left side of the page */
}
.links li {
padding: 15px 0;
cursor: pointer;
}
.links li.items {
position: relative;
width: auto;
margin: 0 25px;
text-align: center;
order: 3;
}
/* Navbar Under Bar */
.links li.items .nav-words:after {
position: absolute;
content: '';
left: 0;
bottom: 5px;
height: 1.5px;
width: 100%;
background: var(--c-primary2);
opacity: 0;
transition: all 0.2s linear;
}
.links li.items .nav-words:hover:after {
opacity: 1;
bottom: 8px;
}
.links li a {
font-weight: 400;
color: var(--h-text);
font-size: 1rem;
letter-spacing: .05rem;
text-decoration: none;
transition: .4s;
}
.links button {
width: 7.6rem;
height: 2.4rem;
background: var(--main-gradient);
border: 1px solid #e4e4e4;
border-radius: 35px;
transition: all 0.2s ease 0s;
cursor: pointer;
outline: none;
}
.links button a {
color: var(--white);
}
.links button:hover {
box-shadow: 0px 12px 10px -10px rgba(0, 0, 0, 0.3)
}
.links li .nav-words:hover {
color: var(--c-primary2);
}
.links li.ham-btn {
display: none;
}
.links li.ham-btn.hide i:before {
content: '\f00d';
}
<!-- Navbar -->
<section id="home">
<header class="menu">
<ul class="links">
<!-- Logo -->
<a href="#home"><img class="logo" src="img/central-gardens-logo.png" alt="logo"></a>
<!-- Words -->
<li class="items"><a class="nav-words" href="#about">About</a></li>
<li class="items"><a class="nav-words" href="#services">Services</a></li>
<li class="items"><a class="nav-words" href="#amenities">Amenities</a></li>
<li class="items"><a class="nav-words" href="#career">Careers</a></li>
<li class="items"><a class="nav-words" href="faq.html" target="_blank">FAQ</a></li>
<!-- Button -->
<li class="items">
<button>
<a href="#contact">Contact</a>
</button>
</li>
<!-- Hamburger Button -->
<li class="ham-btn">
<a class="nav-words" href="#">
<i class="fas fa-bars"></i>
</a>
</li>
</ul>
</header>
</section>
答案 0 :(得分:0)
通过仅添加“#”作为链接,您应该可以转到页面顶部,而无需添加#home
<!-- Logo -->
<a href="#"><img class="logo" src="img/central-gardens-logo.png" alt="logo"></a>