【问题标题】:Menus on the same line as the logo (html/css)与徽标位于同一行的菜单 (html/css)
【发布时间】:2021-10-25 19:06:39
【问题描述】:

我正在建立一个站点,我想将菜单与徽标(图像)放在同一行,问题是菜单放在下面......我认为我的 css 代码有几个矛盾这会阻止菜单转到正确的位置。简而言之,我想创建一个标头,左侧带有徽标,菜单居中

这是我的 HTML 代码:

<!DOCTYPE HTML>
<html lang=fr_FR>
    <head>
        <meta charset="UTF-8"></meta>
        <link rel="stylesheet" type="text/css" href="styles.css">
        <title>STADE BRESTOIS 29 - LE SITE OFFICIEL</title>
    </head>
    <body>
        <div class="navigation">
            <a href="#" class="logo" ><img src="logo_header.png" id="logo_header"></a>
            <div class="header">   
                <header id="header-center">
                    <ul id="menu">
                        <li id="element">
                            <a href="#">Pro</a>
                        </li>
                        <li id="element">
                            <a href="#">Formation</a>
                        </li>
                        <li id="element">
                            <a href="#">Club</a>
                        </li>
                        <li id="element">
                            <a href="#">Association</a>
                        </li>
                        <li id="element">
                            <a href="#">Féminines</a>
                        </li>
                    </ul>
            </header>
            </div>
        </div>
    

    </body>
</html>

这是我的 CSS 代码:

@charset "utf-8";

@font-face{
    font-family: 'nagoda';
    src: url('Nagoda.woff') format('woff'),
         url('Nagoda.otf') format('otf'),
         url('Nagoda.ttf') format('ttf');
    font-weight: normal;
    font-style: normal;
}

* {
    box-sizing: border-box;
    scroll-behavior: smooth;
}

#logo_header{
    height: 110px;
    width: 110px;
    position: relative;
    text-decoration: none;
    margin-left: 54px;
    margin-top: 25px;
}

ul {
    text-align: center;
}

#menu{
    font-family: 'nagoda';
    font-size: 25px;
    text-decoration: none;
    list-style: none;
    list-style-type: none;
    align-items: center;
}

#header{
    overflow: hidden;
    background: none;
    padding: 20px 10px;
    padding-top: 695px;
}

.header a {
    float: left;
    color: #383838;
    text-align: center;
    padding: 12px;
    text-decoration: none;
    font-size: 25px; 
    line-height: 15px;
    border-radius: 5px;
    margin: 70px;
}

.header a:hover {
    background-color: #ed1c24;
    color: white;
}

.header a.active {
    background-color: #ed1c24;
    color: white;
}

li {
    line-height: normal;
}

.header-center {
    position: relative;
    float: center;
    height: 100px;
    width: 400px;
    display: flex; 
    justify-content: center;
    top: 0;
    left: 0;
    right: 0;
    margin: 0 auto;
}


@media screen and (max-width: 800px) {
    .header a {
      float: none;
      display: block;
      text-align: left;
    }
    .header-center {
      float: none;
    }
}

body {
    background-image: url(Image_bg1.png);
    background-repeat: no-repeat;
    background-position: center center;
    background-attachment: local;
    background-size: cover;
    width: 1440px;
    height: 695px;
}

提前感谢那些愿意帮助我的人!

【问题讨论】:

    标签: html css navigation header


    【解决方案1】:

    我改变了一点你的 css

    <style>
        @charset "utf-8";
    
        @font-face {
          font-family: 'nagoda';
          src: url('Nagoda.woff') format('woff'),
            url('Nagoda.otf') format('otf'),
            url('Nagoda.ttf') format('ttf');
          font-weight: normal;
          font-style: normal;
        }
    
        * {
          box-sizing: border-box;
          scroll-behavior: smooth;
        }
    
        .navigation {
          display: flex;
          flex-direction: row;
          align-items: center;
        }
    
        #logo_header {
          height: 110px;
          width: 110px;
          position: relative;
          text-decoration: none;
          margin-left: 54px;
          margin-top: 25px;
        }
    
        ul {
          text-align: center;
        }
    
        #menu {
          font-family: 'nagoda';
          font-size: 25px;
          text-decoration: none;
          list-style: none;
          list-style-type: none;
          align-items: center;
        }
    
        #header {
          overflow: hidden;
          background: none;
          padding: 20px 10px;
          padding-top: 695px;
          display: flex;
          flex-direction: row;
        }
    
        #menu {
          display: flex;
          flex-direction: row;
        }
    
        .header a {
          color: #383838;
          text-align: center;
          padding: 12px;
          text-decoration: none;
          font-size: 25px;
          line-height: 15px;
          border-radius: 5px;
          margin: 70px;
        }
    
        .header a:hover {
          background-color: #ed1c24;
          color: white;
        }
    
        .header a.active {
          background-color: #ed1c24;
          color: white;
        }
    
        li {
          line-height: normal;
        }
    
        .header-center {
          height: 100px;
          width: 400px;
          display: flex;
          justify-content: center;
          top: 0;
          left: 0;
          right: 0;
          margin: 0 auto;
        }
    
    
        @media screen and (max-width: 800px) {
          .header a {
            display: flex;
            flex-direction: column;
            text-align: left;
          }
        }
    
        body {
          background-image: url(Image_bg1.png);
          background-repeat: no-repeat;
          background-position: center center;
          background-attachment: local;
          background-size: cover;
          width: 1440px;
          height: 695px;
        }
      </style>
    

    使用 flexbox 比使用 float 更好。 here你的教程很好。

    【讨论】:

    • 感谢您的帮助,我查看了您的 flexbox 指南,我明白它是如何更好地工作的!我纠正了我的错误。
    • 欢迎您。您也可以将 wv 和 hv 用于您的身体,而不是像这样:width:100 wv; height: 100 hv; 或 pourcentage %,这样您的身体就可以看到设备 ecran 的所有视图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 2014-07-20
    • 2017-06-21
    • 1970-01-01
    • 1970-01-01
    • 2015-08-23
    相关资源
    最近更新 更多