2 回答
TA貢獻1794條經驗 獲得超8個贊
您應該為 2 個子 div 提供公共父項(行)中的左列和右列)。這應該可以解決這里的問題。
PS - 這與問題無關。執行上述操作應該可以解決您當前的問題。但是,并排排列項目的理想方法是使用彈性框。你可以給行。無需使用浮子 - 留給兩個孩子,這將是實現這種布局的理想方式
.row {
display: flex
}
一個更好的解決方案是使用引導,你可以使用booprap網格系統輕松實現這種類型的布局 - https://getbootstrap.com/docs/4.1/layout/grid/
<head>
<style>
* {
color: black;
font-family: Arial, sans-serif;
}
body {
background: gray;
padding: 5px;
}
.header {
background-color: white;
border-radius: 4px;
padding: 25px;
text-align: center;
}
.header h1 {
font-size: 50px;
}
.header p {
font-size: 15px;
font-style: italic;
}
.topnav {
background-color: #444;
border-radius: 4px;
display: flex;
justify-content: center;
overflow: hidden;
}
.topnav a {
color: white;
float: left;
max-width: 25%;
padding: 12px 16px;
text-align: center;
text-decoration: none;
width: 100%;
}
.topnav a:hover {
background-color: #eee;
color: black;
}
.topnav a:active {
background-color: #444;
color: white;
}
.leftcolumn {
float: left;
width: 75%;
}
.rightcolumn {
background-color: white;
float: left;
padding-left: 20px;
width: calc(25% - 20px);
}
.card {
background-color: white;
border-radius: 4px;
margin-top: 20px;
padding: 20px;
}
.row:after {
clear: both;
content: "";
display: table;
}
table {
border: 1px solid black;
border-collapse: collapse;
font-family: Arial, sans-serif;
margin: 5px;
width: 100%;
}
th, td {
border: 1px solid black;
border-collapse: collapse;
font-family: Arial, sans-serif;
margin: 5px;
padding: 5px;
}
@media screen and (max-width: 800px) {
.leftcolumn, .rightcolumn {
padding: 0;
width: 100%;
}
}
@media screen and (max-width: 400px) {
.topnav a {
float: none;
width: 100%;
}
}
</style>
</head>
<body>
<div class="header">
<h1>Weight Calculator</h1>
</div>
<div class="topnav">
<a href="index.html">Home</a>
<a href="calculator.html">Calculator</a>
<a href="solutions.html">Solutions</a>
</div>
<div class="row">
<div class="leftcolumn">
<div class="card">
<table>
<caption>Weight Calculator</caption>
<tr>
<th>Person</th>
<th>Weight</th>
</tr>
<tr>
<td>Jack</td>
<td id="jack" oninput="myFunction()">1</td>
</tr>
<tr>
<td>John</td>
<td id="john" oninput="myFunction()">2</td>
</tr>
<tr>
<td>Joe</td>
<td id="joe" oninput="myFunction()">3</td>
</tr>
<tr>
<td>Total</td>
<td id="total"></td>
</tr>
</table>
</div>
</div>
<div class="rightcolumn">
<div class="card">
<h3>Test</h3>
<p>Text</p>
</div>
<div class="card">
<h3>Test</h3>
<p>Text</p>
</div>
<div class="card">
<h3>Test</h3>
<p>Text</p>
</div>
</div>
</div>
<script type="text/javascript">
document.getElementById("jack").contentEditable = true;
document.getElementById("john").contentEditable = true;
document.getElementById("joe").contentEditable = true;
function myFunction() {
var jack2 = document.getElementById("jack").innerText;
var john2 = document.getElementById("john").innerText;
var joe2 = document.getElementById("joe").innerText;
var total2 = parseInt(jack2) + parseInt(john2) + parseInt (joe2);
document.getElementById("total").innerHTML = total2;
}
myFunction();
</script>
</body>
TA貢獻1848條經驗 獲得超2個贊
.row:after {
clear: both;
content: "";
display: table;
}
“清楚:兩者”是問題所在。要么刪除它,要么將其設置為“清除:右”
添加回答
舉報
