php - 导航按钮超出了 div

标签 php html css

我的网站导航行为很奇怪,2 个按钮超出了 div,我找不到原因。

我想要的是 2 个蓝色按钮位于 div 的右侧,但如果我将它们 float ,它们仍然不在 div 之外。

图片: enter image description here

HTML:

    <div id="navigation">
        <ul>
                <li><a href="index.php">Home</a></li>
                <li><a href="newadvertentie.php">plaats advertentie</a></li>
                <li><a href="advertenties.php">Advertenties</a></li>
        </ul>
        <ul>
            <?php
            session_start();
            echo '<div id="login">';
                if(isset($_SESSION['username'])){
                    echo'<li><a href="profile.php">Profile</a></li>
                         <li><a href="logout.php">Logout</a></li>';
                }else{
                    echo'<li><a href="register.php">Register</a></li>';
                    echo'<li><a href="login.php">Login</a></li>';
                }
            echo '</div>';
            ?>
        </ul>
   </div>

CSS:

            #navigation{
        border:1px solid;
        border-radius: 2px;
        height:50px;
        margin-top:1%;
        margin-bottom:1%;
        background:#6F4E37;
        border-radius:8px;
    }

    #navigation ul
    {
        margin: 0;
        padding-top:1%;
        border:1px solid;
    }

    #navigation ul li
    {
        display: inline;
    }

    #navigation li a
    {
        padding:10px;
        margin:0.5%;
        background: #6F4E37;
        color:black;
        -webkit-border-radius: 4px;
        -moz-border-radius: 4px;
        border-radius: 4px;
        border: solid 1px #20538D;
        text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.4);
        -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
        -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
        -webkit-transition-duration: 0.2s;
        -moz-transition-duration: 0.2s;
        transition-duration: 0.2s;
        -webkit-user-select:none;
        -moz-user-select:none;
        -ms-user-select:none;
        user-select:none;
        text-decoration: none;
    }



    #login li a
    {
        background:#b2fff1;
        padding:10px;
        margin:0.5%;
        background:#b2fff1;
        color:black;
        text-decoration: none;
    }

    #navigation li a:hover {
        background: #805a3f;
        border: solid 1px #2A4E77;
        text-decoration:underline;
     }

    #login li a:hover
    {
        background:#4cffdf;
        border: solid 1px #2A4E77;
        text-decoration:underline;
    }

最佳答案

<?php
        session_start();
        echo '<div id="login">';
            if(isset($_SESSION['username'])){
                echo'<li><a href="profile.php">Profile</a></li>
                     <li><a href="logout.php">Logout</a></li>';
            }else{
                echo'<li><a href="register.php">Register</a></li>';
                echo'<li><a href="login.php">Login</a></li>';
            }
         echo '</div>';
        ?>

然后更改您的 CSS:

        #navigation {
            border:1px solid;
            border-radius: 2px;
            height:50px;
            margin-top:1%;
            margin-bottom:1%;
            background:#6F4E37;
            border-radius:8px;
        }
        #navigation ul {
            margin: 0;
            padding-top:1%;
            border:1px solid;
        }
        #navigation ul li {
            display: inline;
        }
        #navigation li a {
            padding:10px;
            margin:0.5%;
            background: #6F4E37;
            color:black;
            -webkit-border-radius: 4px;
            -moz-border-radius: 4px;
            border-radius: 4px;
            border: solid 1px #20538D;
            text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.4);
            -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
            -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 1px rgba(0, 0, 0, 0.2);
            -webkit-transition-duration: 0.2s;
            -moz-transition-duration: 0.2s;
            transition-duration: 0.2s;
            -webkit-user-select:none;
            -moz-user-select:none;
            -ms-user-select:none;
            user-select:none;
            text-decoration: none;
        }
        #login {
            float:right;
        }
        #login li {
            float:left;
            padding-left:10px;
        }
        #login li a {
            background:#b2fff1;
            padding:10px;
            margin:0.5%;
            background:#b2fff1;
            color:black;
            text-decoration: none;
        }
        #navigation li a:hover {
            background: #805a3f;
            border: solid 1px #2A4E77;
            text-decoration:underline;
        }
        #login li a:hover {
            background:#4cffdf;
            border: solid 1px #2A4E77;
            text-decoration:underline;
        }

Fiddle Here

关于php - 导航按钮超出了 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20522139/

相关文章:

php - 点击 "Warning: page has expired"按钮时 IE 出现 "back"错误

php - PHP 中的密码哈希 : Am I Doing This Right?

html - 为什么水平箭头不垂直对齐?

javascript - 纯 CSS 导航栏 :Hover on List not staying

jquery - 如何强制网站在顶部加载?

javascript - 光滑的旋转木马永久关闭屏幕

php - 如何检查 Opencart 3 中最后执行的查询

php - 使用 PHP 从指纹设备获取数据

javascript - 当到达当前卡住的 header 时,用第二个 header 替换粘性 header

javascript - rails :how to create dynamic drop-down box in rails?