使用视频作为背景时(HTML/CSS),导航栏不会延伸到网页的 100%

问题描述 投票:0回答:1

最近我遇到了一个似乎无法解决的问题;导航栏没有到达屏幕的左端,只能到达右端。仅当我尝试将视频作为网页背景时才出现此问题。

这是 HTML:

<!DOCTYPE html>
    <head>
        <link rel="stylesheet" href="style.css" />
        <script src="main.js"></script>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <video autoplay muted loop id="myVideo">
            <source src="media/background.mp4" type="video/mp4">
        </video>
        <div class="content" width="100%">
            <nav>
                <div class="logo">wonder〇</div>
                <div class="nav-items">
                    <a href="/"><span>about</span></a>
                    <a href="/"><span>contact</span></a>
                    <a href="../login/login.html"><span>login</span></a>
                </div>
            </nav>
            <section class="title">
                <div class="title-container">
                    <div class="column-left">
                        <h1>wondersphere</h1>
                        <p>explore interactive and playful virtual museums.</p>
                        <button class="button"><span>get started</span></button>
                    </div>
                    <div class="column-right">
                            <img src="media/title_img.png" alt="" class="title-image" id="titleImage"/>
                    </div>
                </div>
            </section>
        </div>
    </body>
</html>

CSS:

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
}

#myVideo {
    position: fixed;
    right: 0;
    bottom: 0;
    min-width: 100%;
    min-height: 100%;
  }

.content {
    position: fixed;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.5);
    color: #f1f1f1;
    width: 100vw;
    height: 100vh;
    padding: 20px;
    box-sizing: border-box;
}

nav {
    height: 80px;
    background: #29282e;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0rem calc((100vw - 1300px) / 2);
    user-select: none;
    position: fixed;
    top: 0;
    width: 100%;
}

body {
    margin: 0;
    padding: 0;
}

.logo {
    color: #b4b4b4;
    font-size: 1.5rem;
    font-weight: bold;
    padding: 0 2rem;
    animation: ripple 2s linear infinite alternate;
}

@keyframes ripple {
    from {
        color: #b4b4b4;
    }
    to {
        color: #5f5f5f;
    }
}

nav a {
    text-decoration: none;
    color: #5f5f5f;
    padding: 0 1.5rem;
    transition: all 0.5s;
}

nav a span{
    cursor: pointer;
    display: inline-block;
    position: relative;
    transition: 0.5s;
}

nav a span:after {
    content: '\00bb';
    position: absolute;
    opacity: 0;
    top: 0;
    right: -20px;
    transition: 0.5s;
}

nav a:hover span {
    padding-right: 10px;
}

nav a:hover span:after {
    opacity: 1;
    right: 0;
}

.title {
    user-select: none;
}

.title-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    height: 95vh;
    padding: 3rem calc((100vw - 1300px) / 2);
}

.column-left {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    color: #b4b4b4;
    padding: 0rem 2rem;
}

.column-left h1 {
    margin-bottom: 1rem;
    font-size: 5rem;
}

.column-left p {
    margin-bottom: 2rem;
    font-size: 1.5rem;
    line-height: 1.5;
}

button {
    padding: 1rem 3rem;
    font-size: 1rem;
    border: none;
    color: #5f5f5f;
    background: none;
    cursor: pointer;
    border-radius: 50px;
    transition: all 0.5s;
}

.button {
    border-radius: 4px;
    border: none;
    color: #5f5f5f;
    text-align: center;
    font-size: 1.5rem;
    padding: 20px;
    width: 200px;
    transition: all 0.5s;
    cursor: pointer;
    margin: 5px;
}
  
.button span {
    cursor: pointer;
    display: inline-block;
    position: relative;
    transition: 0.5s;
}
  
.button span:after {
    content: '\00bb';
    position: absolute;
    opacity: 0;
    top: 0;
    right: -20px;
    transition: 0.5s;
}
  
.button:hover span {
    padding-right: 25px;
}
  
.button:hover span:after {
    opacity: 1;
    right: 0;
}

.column-right{
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0rem 2rem;
}

.title-image{
    width: 50%;
    transition: transform 0.7s ease-out;
}

@media screen and (max-width: 768px) {
    .title-container {
        grid-template-columns: 1fr;
    }
}

body::-webkit-scrollbar {
    display: none;
}

我尝试将填充设置为 0,记住这会将文本放在导航栏的开头和结尾,但没有成功。

html css web nav
1个回答
0
投票

您需要删除 .content:20px 中的填充

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
}

#myVideo {
    position: fixed;
    right: 0;
    bottom: 0;
    min-width: 100%;
    min-height: 100%;
  }

.content {
    position: fixed;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.5);
    color: #f1f1f1;
    width: 100vw;
    height: 100vh;
    /* padding: 20px; */
    box-sizing: border-box;
}

nav {
    height: 80px;
    background: #29282e;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0rem calc((100vw - 1300px) / 2);
    user-select: none;
    position: fixed;
    top: 0;
    min-width: 100%;
}

body {
    margin: 0;
    padding: 0;
}

.logo {
    color: #b4b4b4;
    font-size: 1.5rem;
    font-weight: bold;
    padding: 0 2rem;
    animation: ripple 2s linear infinite alternate;
}

@keyframes ripple {
    from {
        color: #b4b4b4;
    }
    to {
        color: #5f5f5f;
    }
}

nav a {
    text-decoration: none;
    color: #5f5f5f;
    padding: 0 1.5rem;
    transition: all 0.5s;
}

nav a span{
    cursor: pointer;
    display: inline-block;
    position: relative;
    transition: 0.5s;
}

nav a span:after {
    content: '\00bb';
    position: absolute;
    opacity: 0;
    top: 0;
    right: -20px;
    transition: 0.5s;
}

nav a:hover span {
    padding-right: 10px;
}

nav a:hover span:after {
    opacity: 1;
    right: 0;
}

.title {
    user-select: none;
}

.title-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    height: 95vh;
    padding: 3rem calc((100vw - 1300px) / 2);
}

.column-left {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    color: #b4b4b4;
    padding: 0rem 2rem;
}

.column-left h1 {
    margin-bottom: 1rem;
    font-size: 5rem;
}

.column-left p {
    margin-bottom: 2rem;
    font-size: 1.5rem;
    line-height: 1.5;
}

button {
    padding: 1rem 3rem;
    font-size: 1rem;
    border: none;
    color: #5f5f5f;
    background: none;
    cursor: pointer;
    border-radius: 50px;
    transition: all 0.5s;
}

.button {
    border-radius: 4px;
    border: none;
    color: #5f5f5f;
    text-align: center;
    font-size: 1.5rem;
    padding: 20px;
    width: 200px;
    transition: all 0.5s;
    cursor: pointer;
    margin: 5px;
}
  
.button span {
    cursor: pointer;
    display: inline-block;
    position: relative;
    transition: 0.5s;
}
  
.button span:after {
    content: '\00bb';
    position: absolute;
    opacity: 0;
    top: 0;
    right: -20px;
    transition: 0.5s;
}
  
.button:hover span {
    padding-right: 25px;
}
  
.button:hover span:after {
    opacity: 1;
    right: 0;
}

.column-right{
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0rem 2rem;
}

.title-image{
    width: 50%;
    transition: transform 0.7s ease-out;
}

@media screen and (max-width: 768px) {
    .title-container {
        grid-template-columns: 1fr;
    }
}

body::-webkit-scrollbar {
    display: none;
}
    <video autoplay muted loop id="myVideo">
        <source src="media/background.mp4" type="video/mp4">
    </video>
    <div class="content" width="100%">
        <nav>
            <div class="logo">wonder〇</div>
            <div class="nav-items">
                <a href="/"><span>about</span></a>
                <a href="/"><span>contact</span></a>
                <a href="../login/login.html"><span>login</span></a>
            </div>
        </nav>
        <section class="title">
            <div class="title-container">
                <div class="column-left">
                    <h1>wondersphere</h1>
                    <p>explore interactive and playful virtual museums.</p>
                    <button class="button"><span>get started</span></button>
                </div>
                <div class="column-right">
                        <img src="https://picsum.photos/seed/picsum/200/300" alt="" class="title-image" id="titleImage"/>
                </div>
            </div>
        </section>
    </div>

© www.soinside.com 2019 - 2024. All rights reserved.