html - CSS - 对齐固定导航栏下方的内容

标签 html css navbar fixed

我正在尝试学习响应式 CSS 但在一些基本的 css 设计上遇到困难。我已经创建了一个固定的导航栏,您可以在下面的代码中看到。但我面临的问题是我无法正确对齐其下方的内容。内容被导航栏重叠。你能建议一个适当的 CSS 修复而不是像添加具有固定高度的空 div 那样的解决方法吗?这是代码:

  *{
        box-sizing: border-box;
    }
    
    body{
        margin:0px;
        padding: 0px;
        background-color: darkgrey;
    }
    
    .title-bar{
        position:fixed;
        margin-top:0px;
        z-index: 100;
        opacity: 1;
        background-color:white;
        width: 100%;
        height: 100px;
        border-bottom: solid 4px dodgerblue;
    }
    
    .page-container{
        padding: 0px;
    }
    
    .menu-options{
        list-style-type:none;
    }
    
    .menu-options li{
        display: inline;
        padding: 10px;
    }
    
    .menu-options li:hover{
        background-color: deepskyblue;
    }
    
    .menu-options li a{
        color: black;
        text-decoration:none;
    }
    
    .clear20{
        height: 40px;
        clear: both;
    }
    
    .clear10{
        height: 20px;
        clear: both;
    }
    
    .display-bar-1{
        background-color: deepskyblue;
        height: 200px;
        padding:40px;
        position: relative;
    }
    
    html {
        font-family: "Lucida Sans", sans-serif;
    }
    
    .caps {
        text-transform: uppercase;
    }
    
    .register_button{
        text-align:center;
        padding-top:20px;
        padding-bottom:10px;
        width: 200px;
        height: 70px;
        border: solid 3px white;
        font-style:bold;
        font-size:14pt;
    
    }
    
    .register_button:hover{
        background-color:navajowhite;
        color: white;
        cursor:pointer;
        border-color: black;
    }
<!DOCTYPE html>
    <html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        <link href="responsive.css" rel="stylesheet">
    </head>
    
    <body>
        <div class="page-container">
    
            <div class="title-bar">
                <table width="100%">
                    <tr>
                        <td><h1> Multirater Surveys </h1></td>
                        <td>
                            <ul class="menu-options">
                                <li> <a href="#"> Home </a></li>
                                <li> <a href="#"> How It Works </a></li>
                                <li> <a href="#"> Features </a></li>
                                <li> <a href="#"> Surveys </a></li>
                                <li> <a href="#"> Plans and Pricings </a></li>
                                <li> <a href="#"> Webinars </a></li>
                                <li> <a href="#"> Blog </a></li>
                            </ul>
                        </td>
                    </tr>
                </table>
            </div>
    
    
            <div class="display-bar-1">
                <div class="row">
                    <div class="" style="width:60%;float:left;font-style:bold;font-size:22pt;color:white;padding:10px;">
                        World Class Service <br>
                        More Than 100 Clients
                    </div>
                    <div class="" style="padding:15px;float:left;width:40%;">
                        <div class="register_button" id="register"> <a style="text-decoration:none;color:black;" href="#"> Register Now </a> </div>
                    </div>
                </div>
            </div>
    
            <div class="display-bar-2">
                <div>
                    <h1> Some random block of texts </h1>
                    <p> Hello world how are you ? what is going on? </p>
                </div>
            </div>
    
            <div class="display-bar-1">
                <div class="row">
                    <div class="" style="width:60%;float:left;font-style:bold;font-size:22pt;color:white;padding:10px;">
                        World Class Service <br>
                        More Than 100 Clients
                    </div>
                    <div class="" style="padding:15px;float:left;width:40%;">
                        <div class="register_button" id="register"> <a style="text-decoration:none;color:black;" href="#"> Register Now </a> </div>
                    </div>
                </div>
            </div>
    
            <div class="display-bar-2">
                <div>
                    <h1> Some random block of texts </h1>
                    <p> Hello world how are you ? what is going on? </p>
                </div>
            </div>
    
            <div class="display-bar-1">
                <div class="row">
                    <div class="" style="width:60%;float:left;font-style:bold;font-size:22pt;color:white;padding:10px;">
                        World Class Service <br>
                        More Than 100 Clients
                    </div>
                    <div class="" style="padding:15px;float:left;width:40%;">
                        <div class="register_button" id="register"> <a style="text-decoration:none;color:black;" href="#"> Register Now </a> </div>
                    </div>
                </div>
            </div>
    
            <div class="display-bar-2">
                <div>
                    <h1> Some random block of texts </h1>
                    <p> Hello world how are you ? what is going on? </p>
                </div>
            </div>
    
            <div class="display-bar-2">
                <div>
                    <h1> Some random block of texts </h1>
                    <p> Hello world how are you ? what is going on? </p>
                </div>
            </div>
        </div>
    
        <input type="text" class="caps"/>
    
        <script>
        window.onload = function(){
            document.getElementById("register").onclick = function(){
                window.location = "https://www.google.com";
            }
        }
        </script>
    </body>
    
    </html>

`responsive.html`

  

最佳答案

适当的方法是在您的 div 中添加 padding-top,与固定标题的高度相同的填充。

关于html - CSS - 对齐固定导航栏下方的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42547506/

相关文章:

javascript - 在特定像素处减慢/停止/暂停滚动

javascript - 将导航栏设置为仅在主页上淡入?

html - 如何垂直对齐此导航栏?

twitter-bootstrap - Bootstrap 导航栏在主菜单上对齐菜单项

html - <select> 是否有正确的 :active selector?

html - 本地相对路径

css - css 变换/过渡后的模糊 div

php - 删除表在 tfoot 和 thead 内的边框

java - Html 或 EPUB 格式的 Android 电子书

javascript - 如何在网络浏览器上通过 Live555 服务器的 rtsp 协议(protocol)流式传输视频