简体   繁体   English

如何将图片放在导航栏的左侧?

[英]How to put the picture in the left side of my nav bar?

How to put the picture in the left side of my navbar? 如何将图片放在导航栏的左侧? I can't seem to understand how it works- the picture is going up and the navbar is outside the div. 我似乎无法理解它的工作原理-图片在上升,导航栏在div之外。

 body { margin: 0; } #navbar { background-color: gray; width: 100%; height: 160px; } #logo { width: 50%; height: 50%; } ul { list-style: none; background-color: red; margin: 0; padding: 0; text-align: center; overflow: hidden; } #navbar li { display: inline; } #navbar li a { display: inline-block; padding: 10px; font-size: 20px; text-decoration: none; } 
 <div class="container"> <div id="navbar"> <img class="logo" src="logo.gif"> <ul> <li><a href="#none">Home</a></li> <li><a href="#none">Game Info</a></li> <li><a href="#none">Gameplay</a></li> <li><a href="#none">Media</a></li> </ul> </div> </div> 

use this code 使用此代码

#navbar{
    position: absolute;
    right: 20px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
}

In the case you want to use flexbox, you may try this: 如果要使用flexbox,可以尝试以下操作:

 favorite body { margin: 0; } #navbar { background-color: gray; width: 100%; height: 160px; /*****************/ display:flex; justify-content:space-between; align-items:center; /*****************/ } #logo { width: 50%; height: 50%; } ul { list-style: none; background-color: red; margin: 0; padding: 0; text-align: center; overflow: hidden; } #navbar li { display: inline; } #navbar li a { display: inline-block; padding: 10px; font-size: 20px; text-decoration: none; } 
 <div class="container"> <div id="navbar"> <img width="40" class="logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/apple.png"> <ul> <li><a href="#none">Home</a></li> <li><a href="#none">Game Info</a></li> <li><a href="#none">Gameplay</a></li> <li><a href="#none">Media</a></li> </ul> </div> </div> 

1-Access class logo by '.' 1-通过“。”访问班级徽标。

2-apply positioning to class logo as i applied and set height and width of class 2-在我应用时将定位应用于班级徽标并设置班级的高度和宽度

3- set width of also heres my code 3-设置宽度也是我的代码

 favorite body { margin: 0; } #navbar { background-color: gray; width: 100%; height: 160px; /*****************/ display:flex; justify-content:space-between; align-items:center; /*****************/ } .logo { position :relative; top: 0px; width: 10%; height: 27%; } ul { list-style: none; background-color: red; width: 90%; margin: 0; padding: 0; text-align: center; overflow: hidden; } #navbar li { display: inline; } #navbar li a { display: inline-block; padding: 10px; font-size: 20px; text-decoration: none; } 
 <div class="container"> <div id="navbar"> <img width="40" class="logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/apple.png"> <ul> <li><a href="#none">Home</a></li> <li><a href="#none">Game Info</a></li> <li><a href="#none">Gameplay</a></li> <li><a href="#none">Media</a></li> </ul> </div> </div> 

down vote favorite body {
  margin: 0;
}

#navbar {
  background-color: gray;
  width: 100%;
  height: 160px;
}

#logo {
  width: 50%;
  height: 50%;
}

ul {
  list-style: none;
  background-color: red;
  margin: 0;
  padding: 0;
  text-align: center;
  overflow: hidden;
}

#navbar li {
  display: inline;
}

#navbar li a {
  display: inline-block;
  padding: 10px;
  font-size: 20px;
  text-decoration: none;
}
<div class="container">
  <div id="navbar"> <img class="logo" src="logo.gif">
    <ul>
      <li><a href="#none">Home</a></li>
      <li><a href="#none">Game Info</a></li>
      <li><a href="#none">Gameplay</a></li>
      <li><a href="#none">Media</a></li>
    </ul>
  </div>
</div>

use this css 使用这个CSS

   ul {
        list-style: none;
        background-color: red;
        margin: 0;
        padding: 0;
        text-align: center;
        overflow: hidden;
        display: inline-block;
    }

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

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