【问题标题】:How can i align <li> and logo<img> next to each other?如何将 <li> 和 logo<img> 对齐?
【发布时间】:2020-08-19 12:59:35
【问题描述】:

我不知道如何将其与徽标对齐。我正在尝试使用填充,但它不起作用,甚至浮动,也许我会更改容器大小以使其工作。顺便说一句,由于溢出不允许链接,您将无法看到图像和 li 选项,因此我附上了图像以更方便 如果可能的话,甚至可以告诉一些提示,以便在 HTML 中做得更好

enter image description here

header {
    height: 600px;
    background-image:urlenter code here;
    background-repeat: no-repeat;
    background-size: cover;
  }
  
  .header-container {
    height: 1240px;
    width: 1240px;
    padding-left: 3%;
  }
  
  .header-logo{
      height: 150px;
      width: 450px;


  }
  img.logo{
      width: 400px;
      height: 150px;
  }
  nav {
    padding-top: 10px;
  }
  
  nav ul {
    margin: 0;
    padding:0;
    }
  
  nav ul li {
    display: inline-flex;
    margin-left: 50px;
    list-style-type: none;
  }
  
  nav ul li a {
    padding-bottom: 11px;
    font-family: 'Raleway', sans-serif;
    font-weight: bold;
    font-size: 16px;
    text-transform: uppercase;
    text-decoration: none;
    letter-spacing: 0.1em;
    color: #111111;
  }
  
  nav ul li a:hover {
    border-bottom: 2px solid #f22222;
  }
<html lang="en">

<head>
    
    <link rel="stylesheet" href="./css/style.css">

    <title>Katalyst Incorporation LLC.</title>
</head>

<body>
    <header id="up">
        <div class="header-container">
            <nav>
                <div class="header-logo">
                    <img class="logo" src="./img/katalyst incorporation logo.png" alt="logo">
                </div>
                <ul>
                    <li><a href="index.html">HOME</a></li>
                    <li><a href="index.html">HOME</a></li>
                    <li><a href="index.html">HOME</a></li>
                    <li><a href="index.html">HOME</a></li>
                    <li><a href="index.html">HOME</a></li>
                </ul>
            </nav>
        </div>
    </header>
</body>

</html>

【问题讨论】:

标签: html css


【解决方案1】:

如果您想在一行中制作徽标和菜单,您应该在您的 div 中添加“float:left”样式。所以你的风格是这样的:

.header-logo {
    height: 150px;
    width: 450px;
    float: left;
}

如果你想改变你的菜单垂直对齐,你可以像这样在你的ul中添加“margin-top:px”:

nav ul {
    margin: 0;
    padding: 0;
    margin-top: 50px;
}

【讨论】:

    【解决方案2】:

    由于 logo divul 是同一个父级的子级,

    您可以将它们的父级(即&lt;nav&gt;)设置为display: flex,以将其子级对齐到 flex-row 中

    Learn More on FlexBox

    nav {
     display: flex;
    }
    

    header {
      height: 600px;
      background-image: urlenter code here;
      background-repeat: no-repeat;
      background-size: cover;
    }
    
    .header-container {
      height: 1240px;
      width: 1240px;
      padding-left: 3%;
    }
    
    .header-logo {
      height: 150px;
      width: 450px;
    }
    
    img.logo {
      width: 400px;
      height: 150px;
    }
    
    nav {
      padding-top: 10px;
      display: flex;
    }
    
    nav ul {
      margin: 0;
      padding: 0;
    }
    
    nav ul li {
      display: inline-flex;
      margin-left: 50px;
      list-style-type: none;
    }
    
    nav ul li a {
      padding-bottom: 11px;
      font-family: 'Raleway', sans-serif;
      font-weight: bold;
      font-size: 16px;
      text-transform: uppercase;
      text-decoration: none;
      letter-spacing: 0.1em;
      /* color: #ffffff; */
      color: #000; /* changing this so that you can see color */
    }
    
    nav ul li a:hover {
      border-bottom: 2px solid #f22222;
    }
    <html lang="en">
    
    <head>
    
      <link rel="stylesheet" href="./css/style.css">
    
      <title>Katalyst Incorporation LLC.</title>
    </head>
    
    <body>
      <header id="up">
        <div class="header-container">
          <nav>
            <div class="header-logo">
              <img class="logo" src="./img/katalyst incorporation logo.png" alt="logo">
            </div>
            <ul>
              <li><a href="index.html">HOME</a></li>
              <li><a href="index.html">HOME</a></li>
              <li><a href="index.html">HOME</a></li>
              <li><a href="index.html">HOME</a></li>
              <li><a href="index.html">HOME</a></li>
            </ul>
          </nav>
        </div>
      </header>
    </body>
    
    </html>

    我已经更改了字体颜色,以便您可以看到它正在工作。

    【讨论】:

      猜你喜欢
      • 2011-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      • 2014-02-21
      • 1970-01-01
      • 2015-11-22
      • 2020-12-22
      相关资源
      最近更新 更多