我一直在試圖解決這個問題。我很茫然。我搜索並嘗試了大部分我能找到的解決方案,但沒有運氣。CSS浮動,除了正確的位置以外浮動
我正在建立一個基本的網站,作爲我自己的一個愛好項目的一部分。我試圖讓頁面內容分成兩部分;左和右。然而,左邊總是坐在正確的內容之上。就好像它忽略了float:left;
和float: right;
命令。
body {
font-family: 'Noto Sans', sans-serif;
background-color: #DAA520;
}
#container {
width: 80%;
margin: 25px auto;
background: #fff !important;
border: 1px solid black;
border-radius: 10px;
overflow: auto;
}
.header img {
padding-left: 30%;
float: none;
}
.header {
border-bottom: 5px solid #ccc;
margin-bottom: 4px;
height: 300px;
}
.nav ul {
list-style: none;
width: 100%;
margin-top: 25px;
text-align: center;
}
.nav li {
float: left;
width: 24%;
box-sizing: border-box;
border: 1px solid black;
margin-left: 2px;
}
.nav li:hover {
background: gold;
}
.banner img {
display: block;
height: 400px;
width: 100%;
}
.sub1 h3,
p {
float: left;
margin-left: 10px;
width: 48%;
display: inline-block;
position: relative;
}
.sub2 {
float: right;
margin-right: 10px;
width: 48%;
display: flex;
display: inline-block;
position: relative;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/day1.css">
<link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet">
<title>Bakem and Shakem</title>
</head>
<body>
<div id="container">
<div class="header">
<img src="http://kojaks.betterplacesonline.com/wp-content/uploads/2016/09/Kojaks-Houose-of-Ribs-BBQ-Tampa-Logo-w-slogan-one-line-001-retina.png" alt="Logo">
<div class="nav">
<ul>
<li>Home</li>
<li>Recipes</li>
<li>Contact</li>
<li>Bakem</li>
</ul>
</div>
<!-- navigation bar divider -->
</div>
<!-- header divider -->
<div class="banner">
<img src="http://www.brucelauderdale.com/wp-content/uploads/2011/08/ribs.png" alt="banner">
</div>
<div class="sub1">
<h3>We make em, you bake em!</h3>
<p>Boudin ham hock fatback, tongue beef ribs drumstick capicola picanha pork chop meatloaf. Strip steak meatball hamburger tri-tip flank. Biltong sirloin spare ribs tongue, shank cupim corned beef burgdoggen venison. Kevin shankle sirloin porchetta
frankfurter.
</p>
</div>
<!-- sub1 divider -->
<div class="sub2">
<form class="signup" action="index.html" method="post">
<h3>Sign up for our news letter</h3>
<p>Be apart of the bakem family</p>
<input type="text" name="name" value="name"><label for="email" required>Name</label>
<input type="email" name="email" value="email" required><label for="email">Email address</label>
</form>
</div>
<!-- sub2 divider -->
</div>
<!-- conatiner divider -->
</body>
</html>
的主要問題可以在SUB1和SUB2類被發現。我開始認爲這應該是另一個階級,我已經制定了一個與這個衝突的規則,我不確定。
非常感謝!你一提到它,我就意識到了。 – Futurewaves