html – 以标题为中心的垂直边框/分隔线

在我的标题中创建一个居中的垂直边框是否可行且相当容易?我希望它将我的logo / h1-text和导航栏分开.

我知道CSS很乱,我上周才学会了html和css!我可能会删除一些CSS.

        header {
            height: 60px;
            width: 85%;
            /background-color: white;
            margin: 0 auto;
            /box-shadow: 0px 2px 31px -2px rgba(0, 0, 0, 0.86);
            /border: 2px solid #333;
            left: 0;
            right: 0;
            /border-sizing: border-box;
            /-moz-box-sizing: border-box;
            /-webkit-box-sizing: border-box;
            z-index: 999999;
        }


        header #kage > *, header li {
            display: inline-block;
        }

        header li {
            padding: 0 8px 0 8px;
            float:left;
        }

        #kage {
            width: 99%;
            margin: 0 auto;
            height: 100%;
            line-height: 59px;
            text-align: center;
        }

        .button1:hover {
            background-color: #f2f2f2;
        }
        .button2:hover {
            background-color: #f2f2f2;
        }
        .button3:hover {
            background-color: #f2f2f2;
        }

        .active {
            text-decoration: underline;
        }

        header a {
            text-decoration: none;
            color: #333;
            position: relative;
        }

        header h1 {
            margin: 0;
            float: left;
            height: 100%;
            text-shadow: 1px 2px lightgrey;
        }

        header h1:hover {
            color: #f2f2f2;
        }

        #topnav {
            height: 100%;
            /*float: right;*/
            font-weight: 700;
            font-size: 1.3em;
            width: 310.95px;
        }

        header ul {
            list-style-type: none;
            margin: 0;
        }
    <header>
      <div id="kage">
      <a href="index.html"><h1>H1 TEXT HEREEEEE</h1></a>
        <nav id="topnav">
            <ul class="menu">
                <a href="index.html"><li class="button1 active">Home</li></a>
                <a href="profil.html"><li class="button2">About</li></a>
                <a href="mdu.html"><li class="button3">MDU</li></a>
            </ul>
        </nav>
      </div>
    </header>

好像你需要全屏运行代码片段,所以标题不会分成两行.

最佳答案 有很多方法可以做到这一点.

我认为最简单的方法是在你的#topnav上留一个边框.

#topnav {
            height: 100%;
            /*float: right;*/
            font-weight: 700;
            font-size: 1.3em;
            width: 310.95px;
            border-left: 2px solid rgb(0,0,0);
            margin: 0 0 0 40px;
        }

我很容易在你topnav的左侧添加一个2像素的边框,颜色为黑色.
并在左侧调整了一点边距.保证金:0 0 0 40px; 〜(保证金:右上角左下)

        header {
            height: 60px;
            width: 85%;
            /background-color: white;
            margin: 0 auto;
            /box-shadow: 0px 2px 31px -2px rgba(0, 0, 0, 0.86);
            /border: 2px solid #333;
            left: 0;
            right: 0;
            /border-sizing: border-box;
            /-moz-box-sizing: border-box;
            /-webkit-box-sizing: border-box;
            z-index: 999999;
        }


        header #kage > *, header li {
            display: inline-block;
        }

        header li {
            padding: 0 8px 0 8px;
            float:left;
        }

        #kage {
            width: 99%;
            margin: 0 auto;
            height: 100%;
            line-height: 59px;
            text-align: center;
        }

        .button1:hover {
            background-color: #f2f2f2;
        }
        .button2:hover {
            background-color: #f2f2f2;
        }
        .button3:hover {
            background-color: #f2f2f2;
        }

        .active {
            text-decoration: underline;
        }

        header a {
            text-decoration: none;
            color: #333;
            position: relative;
        }

        header h1 {
            margin: 0;
            float: left;
            height: 100%;
            text-shadow: 1px 2px lightgrey;
        }

        header h1:hover {
            color: #f2f2f2;
        }

        #topnav {
            height: 100%;
            /*float: right;*/
            font-weight: 700;
            font-size: 1.3em;
            width: 310.95px;
            border-left: 2px solid rgb(0,0,0);
            margin: 0 0 0 40px;
        }

        header ul {
            list-style-type: none;
            margin: 0;
        }
    <header>
      <div id="kage">
      <a href="index.html"><h1>H1 TEXT HEREEEEE</h1></a>
        <nav id="topnav">
            <ul class="menu">
                <a href="index.html"><li class="button1 active">Home</li></a>
                <a href="profil.html"><li class="button2">About</li></a>
                <a href="mdu.html"><li class="button3">MDU</li></a>
            </ul>
        </nav>
      </div>
    </header>
点赞