我需要在同一行显示2个div但它们都有p标签,其中一个有图像,我需要这样我无法摆脱它们,所以我需要一个解决问题的方法 在此先感谢;)
请参阅以下代码:
HTML
<div class="MainMenu">
<a href="home.php"><p>HOME</p></a>
<a href="#"><p>ABOUT</p></a>
<a href="store.php"><p>STORE</p></a>
</div>
<div class="MainMenuBasket">
<img src="../Images/jigsoar-icons/PNG/light/64px/64_cart.png" width="px" height="px" />
<a href="#"><p>BASKET</p></a>
</div>
CSS
.MainMenu{width: 680px; float: left; margin-top:25px;}
.MainMenu a{text-decoration: none; color: #FFF; }
.MainMenu a:link {color: #FFF; text-decoration: none;}
.MainMenu a:active {color: #; text-decoration: none;}
.MainMenu a:hover {background-color: #7D3B05; text-decoration: none;}
.MainMenu a:visited {color: #; text-decoration: none;}
.MainMenu p{display: inline; font-size: 18px; padding-left: 20px;}
.MainMenuBasket{float: left; margin-top:25px;}
.MainMenuBasket a{text-decoration:none; color: #FFF;}
.MainMenuBasket a:link {color: #FFF; text-decoration: none;}
.MainMenuBasket a:active {text-decoration: none;}
.MainMenuBasket a:hover {background-color: #7D3B05; text-decoration: none;}
.MainMenuBasket a:visited {text-decoration: none;}
.MainMenuBasket p {display: inline; font-size: 18px; padding left: 20px;}
答案 0 :(得分:3)
更改.MainMenu
.MainMenu {
float: left;
margin-top: 25px;
width: 250px;
}
答案 1 :(得分:0)
将属性“position:absolute”和“float:right”添加到.MainMenuBasket。现在玩这个类的“左”属性。它应该在右边正确对齐。
将来尝试使用CSS库bootstrap http://twitter.github.com/bootstrap/。很容易创建这样的div。
答案 2 :(得分:0)
如果您希望div
位于同一行,则需要将float:left
设置为第一个div,将float:right
设置为第二个div。
试试这个:
.MainMenuBasket{float: right; margin-top:25px;}
答案 3 :(得分:0)
移除width
并将display:table-cell
添加到.MainMenu
并从float:left
移除.MainMenuBasket
.MainMenu{display:table-cell; margin-top:25px; background:violet}
<强> DEMO 强>
答案 4 :(得分:0)
这是你需要的吗?
<强> CSS 强>
.MainMenu{width: 680px; float: left; margin-top:25px; background:violet;float:left; width:300px;}
.MainMenu a{text-decoration: none; color: #FFF;display: inline; font-size: 18px; padding-left: 20px; }
.MainMenu a:link {color: #FFF; text-decoration: none;}
.MainMenu a:active {color: #; text-decoration: none;}
.MainMenu a:hover {background-color: #7D3B05; text-decoration: none;}
.MainMenu a:visited {color: #; text-decoration: none;}
.MainMenuBasket{float: left; margin-top:25px; background:maroon}
.MainMenuBasket a{text-decoration:none; color: #FFF;display: inline; font-size: 18px; padding left: 20px;}
.MainMenuBasket a:link {color: #FFF; text-decoration: none;}
.MainMenuBasket a:active {text-decoration: none;}
.MainMenuBasket a:hover {background-color: #7D3B05; text-decoration: none;}
.MainMenuBasket a:visited {text-decoration: none;}
<强> HTML 强>
<div class="MainMenu">
<a href="home.php">HOME</a>
<a href="#">ABOUT</a>
<a href="store.php">STORE</a>
</div>
<div class="MainMenuBasket">
<img src="../Images/jigsoar-icons/PNG/light/64px/64_cart.png" width="px" height="px" />
<a href="#">BASKET</a>
</div>