部分未显示在下方

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

我对编码相对较新,并尝试用 HTML 和 CSS 创建我的 WordPress 主页,这是我的主页 https://danieljmanning.co.uk

我已经添加了导航栏和主页,但每次我尝试在此英雄部分下方添加一个部分时,它都会显示在页面顶部而不是英雄部分下方。

我希望我的信息部分显示在英雄横幅容器下方,与我在 https://danieljmanning.co.uk 上的主页相同

这是我的 HTML 代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>danieljmanning - WordPress Web Designer</title>
    <link rel="stylesheet" href="style.css">
    <meta name="description" content="Daniel Manning's Web Design, SEO optimisation and blog writing services. 
    Do you want to rank #1? Get In Touch Today!">
    <style>
        h1,h2,h3,h4,h5,h6,p{
            color: #fff;
        }
    </style>
</head>
    
<div class="container">
    <nav>
        <img src="/images/danieljmanning_logo.png" class="logo" alt="logo">
        <ul>
            <li><a href="#" aria-label="danieljmanning's home page"></a>Home</li>
            <li><a href="#" aria-label="More about who Daniel Manning is and more about his experience 
                in web design and SEO Optimisation"></a>About</li>
            <li><a href="#" aria-label="Daniel Manning's Portfolio Page"></a>Portfolio</li>
            <li><a href="#" aria-label="Web Design, SEO Optimisation and Monthly Support Services 
                with pricing and detail"></a>Services</li>
            <li><a href="#" aria-label="Blog Listing Page"></a>Blog</li>
        </ul>
        <button class="btn">Apply Now</button>
    </nav>

    <div class="content">
        <h1>DANIELJMANNING</h1>
        <h2>AFFORDABLE WORDPRESS WEB DESIGN</h3>
            <p>I am Daniel J Manning <span class="p-home">here to help you earn more</span> for your business with a 
                website! <span class="p-home">Scroll Down to See My Work.</span></p>
            <button class="portfolio-btn">PORTFOLIO</button>
            <button class="apply-btn">APPLY</button>
    </div>
</div>
<section class="info">
    <h1>Earn more with a website</h1>
    <p>Having a website gives you a forefront, a place where visitors can find you, giving them the opportunity to come 
        to your business.</p>
</section>
</body>
</html>

这是我的 CSS 代码:

*{
    margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
    box-sizing: border-box; /*FindOutWhatthismeans*/
}

.container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100vh;
    background-color: black;
    background-size: cover;
    background-position: center;
    overflow: hidden;
    z-index: -100;
}

nav{
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
    border-bottom: 0.1px solid #303030;
}

.logo{
    width: 20%;
    cursor: pointer;
    padding-left: 40px;
    padding-top: 0px;
}

nav ul{
    list-style: none;
    width: 100%;
    text-align: right;
    padding-right: 20px;
}

nav ul li{
    display: inline-block;
    margin: 10px 20px;
    font-size: 16px;
    cursor: pointer;
}

nav ul li a{
    color: #fff;
    text-decoration: none;
}

.btn{
    display: flex;
    width: 190px;
    height: 55px;
    padding-top: 17px;
    padding-bottom: 17px;
    padding-left: 40px;
    padding-right: 40px;
    border: 0;
    outline: 0;
    border-radius: 0px;
    background: #fff;
    color: black;
    font-weight: 500;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.content{
    margin-top: 22%;
    color: #fff;
    max-width: 1000px;
    margin-left: 10%;
    height: 100vh;
}

.content h1{
    display: block;
    width: 100%;
    border-bottom: 1px solid #fff;
}

.content h2{
    padding-top: 20px;
    padding-bottom: 20px;
    color: rgb(47, 193, 255);
    font-size: 18px;
}

.content p{
    padding-bottom: 40px;
}

.p-home{
    font-weight: bold;
}

.home-btn{
    display: flex;
    width: 180px;
    height: 50px;
    padding-top: 17px;
    padding-bottom: 17px;
    padding-left: 40px;
    padding-right: 40px;
    border: 0;
    outline: 0;
    border-radius: 0px;
    background: #fff;
    color: black;
    font-weight: 500;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.portfolio-btn{
    display: inline-block;
    width: 180px;
    height: 50px;
    padding-top: 17px;
    padding-bottom: 17px;
    padding-left: 40px;
    padding-right: 40px;
    border: 1px;
    outline: 1px;
    border-radius: 0px;
    background: transparent;
    color: #fff;
    font-weight: 500;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    border-top: 1px solid #fff;
    border-bottom: 1px solid #fff;
    border-left: 1px solid #fff;
    border-right: 1px solid #fff;
    
}

.apply-btn{
    display: inline-block;
    width: 180px;
    height: 50px;
    padding-top: 17px;
    padding-bottom: 17px;
    padding-left: 40px;
    padding-right: 40px;
    border: 0;
    outline: 0;
    border-radius: 0px;
    background: transparent;
    color: #fff;
    font-weight: 500;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.info{
    margin-top: 100px;
}
html css sections
1个回答
0
投票

如果我答对了你的问题。问题是您已将

position: fixed;
添加到 container 中,因此这将导致相对于视口固定/固定 container 类,因此 info div 将位于 container div 下方。

我已修复您的代码如下:

  1. 我已经从 .container 类中删除了定位属性。
  2. 我添加了
    display: flex;
    align-items: center;
    来保持原来的布局(你可以根据需要进行更改)。
  3. 我已将
    background-color: black;
    添加到导航中,因为它已移至 .container div 之外(我认为您真的不需要将它放在容器 div 中)。
  4. 我已经修复了一些 HTML 标签问题(有些标签没有正确关闭,请检查标签是否按照您想要的方式关闭)。

我建议阅读有关职位的 MDN 文档:

位置文档

* {
        margin: 0;
        padding: 0;
        font-family: "Poppins", sans-serif;
        box-sizing: border-box;
        /*FindOutWhatthismeans*/
      }

      .container {
        width: 100%;
        position: relative;
        min-height: 100vh;
        background-color: black;
        background-size: cover;
        background-position: center;
        overflow: hidden;
        
        
        /* newly added to center the content */
        display: flex;
        align-items: center;
      }

      nav {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: white;
        border-bottom: 0.1px solid #303030;
        
        /* newly added since the nav was moved outside the container classs */
        background-color: black; 
      }

      .logo {
        width: 20%;
        cursor: pointer;
        padding-left: 40px;
        padding-top: 0px;
      }

      nav ul {
        list-style: none;
        width: 100%;
        text-align: right;
        padding-right: 20px;
      }

      nav ul li {
        display: inline-block;
        margin: 10px 20px;
        font-size: 16px;
        cursor: pointer;
      }

      nav ul li a {
        color: #fff;
        text-decoration: none;
      }

      .btn {
        display: flex;
        width: 190px;
        height: 55px;
        padding-top: 17px;
        padding-bottom: 17px;
        padding-left: 40px;
        padding-right: 40px;
        border: 0;
        outline: 0;
        border-radius: 0px;
        background: #fff;
        color: black;
        font-weight: 500;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        font-size: 14px;
      }

      .content {
        color: #fff;
        max-width: 1000px;
        margin-left: 10%;
      }

      .content h1 {
        display: block;
        width: 100%;
        border-bottom: 1px solid #fff;
      }

      .content h2 {
        padding-top: 20px;
        padding-bottom: 20px;
        color: rgb(47, 193, 255);
        font-size: 18px;
      }

      .content p {
        padding-bottom: 40px;
      }

      .p-home {
        font-weight: bold;
      }

      .home-btn {
        display: flex;
        width: 180px;
        height: 50px;
        padding-top: 17px;
        padding-bottom: 17px;
        padding-left: 40px;
        padding-right: 40px;
        border: 0;
        outline: 0;
        border-radius: 0px;
        background: #fff;
        color: black;
        font-weight: 500;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        font-size: 14px;
      }

      .portfolio-btn {
        display: inline-block;
        width: 180px;
        height: 50px;
        padding-top: 17px;
        padding-bottom: 17px;
        padding-left: 40px;
        padding-right: 40px;
        border: 1px;
        outline: 1px;
        border-radius: 0px;
        background: transparent;
        color: #fff;
        font-weight: 500;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        border-top: 1px solid #fff;
        border-bottom: 1px solid #fff;
        border-left: 1px solid #fff;
        border-right: 1px solid #fff;
      }

      .apply-btn {
        display: inline-block;
        width: 180px;
        height: 50px;
        padding-top: 17px;
        padding-bottom: 17px;
        padding-left: 40px;
        padding-right: 40px;
        border: 0;
        outline: 0;
        border-radius: 0px;
        background: transparent;
        color: #fff;
        font-weight: 500;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        font-size: 14px;
      }

      .info {
        margin-top: 100px;
      }
<nav>
  <img src="/images/danieljmanning_logo.png" class="logo" alt="logo">
  <ul>
    <li>
      <a href="#" aria-label="danieljmanning's home page"></a>Home</li>
    <li>
      <a href="#" aria-label="More about who Daniel Manning is and more about his experience 
                    in web design and SEO Optimisation"></a>About</li>
    <li>
      <a href="#" aria-label="Daniel Manning's Portfolio Page"></a>Portfolio</li>
    <li>
      <a href="#" aria-label="Web Design, SEO Optimisation and Monthly Support Services 
                    with pricing and detail"></a>Services</li>
    <li>
      <a href="#" aria-label="Blog Listing Page"></a>Blog</li>
  </ul>
  <button class="btn">Apply Now</button>
</nav>

<div class="container">
  <div class="content">
    <h1>DANIELJMANNING</h1>
    <h2>AFFORDABLE WORDPRESS WEB DESIGN</h3>
      <p>I am Daniel J Manning <span class="p-home">here to help you earn more</span> for your business with a website! <span class="p-home">Scroll Down to See My Work.</span></p>
      <button class="portfolio-btn">PORTFOLIO</button>
      <button class="apply-btn">APPLY</button>
  </div>
</div>

<section class="info">
  <h1>Earn more with a website</h1>
  <p>Having a website gives you a forefront, a place where visitors can find you, giving them the opportunity to come to your business.</p>
</section>

<h1>a website</h1>
<p>Having a website gives you a forefront, a place where visitors can find you, giving them the opportunity to come to your business.</p>
</section>

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