简体   繁体   English

如何与CSS并排放置两个块

[英]How to position two blocks side by side with CSS

I have a logo and a secondary menu that I would like to appear on the same line (the logo on the far left, and the menu on the far right). 我有一个徽标和一个辅助菜单,希望将它们显示在同一行上(最左边的徽标和最右边的菜单)。 The logo width is undefined and the secondary menu width is 200px wide. 徽标宽度未定义,辅助菜单宽度为200px。 When I apply the following CSS, the secondary menu is pushed to the line below the logo (but still on the right side of the page): 当我应用以下CSS时,辅助菜单被推到徽标下方的行(但仍在页面右侧):

#logo {
padding-bottom: 40px;
}

.secondaryMenu {
width: 200px;
float: right;
margin-right: 0px;
padding-right: 2px;
color: black;
font-size: 9px;
letter-spacing: 1px;
text-align: right;
}

Here is the relevant part of the HTML: 这是HTML的相关部分:

<div id="logo"> 
  <a href="index.html"> <img id="logoimg" border="0" alt="" src="images/logo.gif"/> </a>        
</div> 
<div class="secondaryMenu">
  <a href="about.html">About</a> | <a href="services.html">Services</a> |
  <a href="contactus.html">Contact Us</a> 
</div>

I would appreciate any thoughts on what I'm doing wrong. 对于我在做什么错的任何想法,我将不胜感激。

#logo would need to float: left #logo需要float: left

then you should probably add a clear: both styled container after .secondardMenu or wrap them both with a clearfix class'd container 那么您可能应该添加一个clear: both.secondardMenu之后的clear: both样式容器,或使用clearfix类的容器将它们包装

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

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