简体   繁体   English

如何以透明的方式将导航栏放在顶部

[英]How to place navigation bar on top in transparent

I want to place the navigation bar on top, in transparent, as the shown in the picture.我想将导航栏放在顶部,透明,如图所示。 I tried to pix the position and the width and height but still didn't work.我尝试修改 position 和宽度和高度,但仍然没有用。

在此处输入图像描述

 * { margin: 0; padding: 0; font-family: 'Poppins', sans-serif; }.header { min-height: 100vh; width: 100%; background-image: linear-gradient(rgba(4,9,30,0.7),rgba(4,9,30,0.7)),url(img/arnold-francisca-nPhl2x4fk2s-unsplash.jpg); background-position: center; background-size: cover; position: relative; } nav { display: flex; padding: 25px 50px 75px 100px; justify-content: space-between; align-items: center; position: relative; } nav img { width: 85px; }.nav-links { flex: 1; text-align: right; }.nav-links ul li { list-style: none; display: inline-block; padding: 8px 12px; position: relative; }.nav-links ul li a { color: rgb(8, 8, 8); text-decoration: none; font-size: 15px; }.nav-links ul li::after { content: ''; width: 0%; height: 3px; background: #d6574e; display: block; margin: auto; transition: 0.5s; }.nav-links ul li:hover::after { width: 100%; }.text-box { width: 90%; color: #fff; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); text-align: center; }.text-box h1 { font-size: 40px; }.text-box p { margin: 10px 0 40px; font-size: 16px; color: #fff; }.hero-btn { display: inline-block; text-decoration: none; color: #cfaba9; border: 1px solid #cfaba9; padding: 10px 30px; font-size: 13px; background: transparent; position: relative; cursor: pointer; }.hero-btn:hover { border-radius: 50px; background: #cfaba9; transition: 1s; } nav.fa { display: none; } @media(max-width: 700px){.text-box h1 { font-size: 20px; }.nav-links ul li { display: block; }.nav-links ul li { position: absolute; background: #cfaba9; height: 100vh; width: 200px; top: 0; right: 0; text-align: left; z-index: 2; } nav.fa { display: block; color: #cfaba9; margin: 10px; font-size: 22px; cursor: pointer; }.nav-links ul { padding: 30px; } }
 <,DOCTYPE html> <html> <head> <meta name="viewport" content="with=device-width. initial-scale=1,0"> <title>Nikko Permelona | UX/UI Designer; Frontend Developer &amp. Learner</title> <link rel="stylesheet" href="style:css"> <link rel="preconnect" href="https.//fonts.gstatic:com" crossorigin> <link rel="stylesheet" href="https.//fonts.googleapis?com/css2:family=Poppins;wght@100;200;300;400;600:700&display=swap" rel="stylesheet"> <link href="https.//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.2/css/fontawesome.min.css"> </head> <body> <section class="header"></section> <nav> <a href="index.html"><img src="img/GYSD7530-modified,png"></a> <div class="nav-links"> <i class="fa fa-times"></i> <ul> <li><a href="">About</a></li> <li><a href="">Experience</a></li> <li><a href="">Work</a></li> <li><a href="">Contact</a></li> <li><a href="">Resume</a></li> </ul> </div> <i class="fa fa-bars"></i> </nav> <div class="text-box"> <h1>UI/UX Designer; Frontend Developer &amp, Learner</h1> <p>I design and code gorgeously simple things, and I love what I do</p> <a href="" class="hero-btn">Explore</a> </div> </body> </html>

Just wrap the nav and the text-box divs with the header section.只需使用 header 部分包装navtext-box div。 It looks like you closed the header section right away and haven't wrapped it with anything, modify the part like this:看起来您立即关闭了 header 部分并且没有用任何东西包裹它,修改如下部分:

 <section class="header">
        <nav>
            <a href="index.html"><img src="img/GYSD7530-modified.png"></a>
            <div class="nav-links">
                <i class="fa fa-times"></i>
                <ul>
                    <li><a href="">About</a></li>
                    <li><a href="">Experience</a></li>
                    <li><a href="">Work</a></li>
                    <li><a href="">Contact</a></li>
                    <li><a href="">Resume</a></li>
                </ul>
            </div>
        <i class="fa fa-bars"></i>
        </nav>

        <div class="text-box">
            <h1>UI/UX Designer, Frontend Developer &amp; Learner</h1>
            <p>I design and code gorgeously simple things, and I love what I do</p>
            <a href="" class="hero-btn">Explore</a>


        </div>
</section>

This should work fine这应该可以正常工作

You can make it transparent by use the css property: background-color: transparent;您可以使用 css 属性使其透明: background-color: transparent; Also to make the nav bar go to top try putting it in div instead of nav.还要使导航栏 go 顶部尝试将其放在 div 而不是导航中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM