简体   繁体   English

如何将图像添加到导航菜单栏的左侧?

[英]How do I add an image to the left side of Navigation Menu Bar?

How Do I get an image in line with the Navigation bar on the left side and the menu items listed on the right side?如何获得与左侧导航栏和右侧列出的菜单项一致的图像? I keep getting my image to go on top of the navigation bar instead of being inline/on the navigation bar.我一直将我的图像放在导航栏顶部的 go 而不是内联/导航栏上。

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
<title>TLC Music Group</title>
<link rel="stylesheet" href="css/style.css">
<meta name="description" content="Our first page">
<meta name="keywords" content="html tutorial template">
</head>
<body>
    <nav>    
    <ul class="navigationbar">
        <li><img src="imgs/tlclogo.png" id=logo alt="TLC Logo" /> </li>
        <li><a href="index.html">Home</a></li>
        <li><a href="music.html">Music</a></li>
        <li><a href="news.html">News</a></li>
    </ul>        
    </nav>
</body>
</html>
  .navigationbar ul {
    list-style-type: none;
    padding: 0px;
    margin: 0px;
    text-align: center;
    float: left;
    vertical-align:top;
    top: 0;
    width: 100%;
    overflow: hidden;
    background-color: #333
  }

  #logo {
    float: left;
}

  li {
    float: right;
  }
  
  li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
  }
  
  /* Change the link color to #111 (black) on hover */
  li a:hover {
    background-color: #111;
  }

Try using display:flex;尝试使用display:flex; this will make your life a lot easier.这将使您的生活更轻松。 Also put img tag outside un-ordered list for HTML还将 img 标签放在HTML un-ordered list之外

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>TLC Music Group</title>
    <link rel="stylesheet" href="css/style.css" />
    <meta name="description" content="Our first page" />
    <meta name="keywords" content="html tutorial template" />
  </head>
  <body>
    <nav>
        <img src="imgs/tlclogo.png" id=logo alt="TLC Logo" />
      <ul class="navigationbar">
    
        <li><a href="index.html">Home</a></li>
        <li><a href="music.html">Music</a></li>
        <li><a href="news.html">News</a></li>
      </ul>
    </nav>
  </body>
</html>

and for CSSCSS

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}
ul li {
  position: relative;
  margin: 0 20px;
  list-style: none;
  display: inline-block;
  cursor: pointer;
}

I hope this will resolve your issue.我希望这能解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM