gpt4 book ai didi

html - 调整盒模型布局

转载 作者:行者123 更新时间:2023-11-28 15:08:48 25 4
gpt4 key购买 nike

我试图在下面的代码中将表格居中,这样它就不会紧靠左边框墙。我似乎无法查明问题所在。截至目前,第 2 列中的表格向左浮动并触及边框的左墙。我需要它更集中在盒子里。有什么帮助吗?我需要表格看起来像这样:1 .

   header {
text-align: center;
font-size: 30px;
font-style: bold;
font-style: italic;
}

#column-1 {
float: left;
background-color: lightblue;
width: 25%;
border: 5px solid red;
padding: 20px;
margin: 2px;
height: 400px
}

#column-2 {
background-color: lightblue;
width: 100%;
border: 5px solid red;
padding: 20px;
margin: 2px;
text-align: center;
height: 400px
<!DOCTYPE html>
<html>

<head>
<title>Logans Dinner</title>
</head>

<body>
<header>Welcome to Logans Dinner</header>
<div id='column-1'>
<nav>
<ul>
<li><a href='/Menu.html'>Menu</a></li>
<li><a href='/About.html'>About Us</a></li>
<li><a href='/Contact.html'>Contact Us</a></li>
</ul>
</nav>
</header>
</div>
<div id='column-2'>
<section>
<p>Our Menu</p>
<table>
<thead>
<tr>
<th>Food</th>
<th>Description</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Burger</td>
<td>1/2 lb Angus Beef</td>
<td>$10.99</td>
</tr>
</tbody>
</table>
</div>

</section>
</body>

</html>

最佳答案

您可以使用规则 margin: 0 auto使你的 table 居中。这是以下内容的简写:
margin-top: 0; margin-bottom: 0; margin-left: auto; margin-right: auto;

此外,我注意到您有一些不匹配的 HTML 标签(例如早期的 </body> 和额外的 </header> )。确保您的开始和结束标签正确配对并位于正确的位置。

header {
text-align: center;
font-size: 30px;
font-style: bold;
font-style: italic;
}

#column-1 {
float: left;
background-color: lightblue;
width: 25%;
border: 5px solid red;
padding: 20px;
margin: 2px;
height: 400px
}

#column-2 {
background-color: lightblue;
width: 100%;
border: 5px solid red;
padding: 20px;
margin: 2px;
text-align: center;
height: 400px
}

table {
margin: 0 auto;
}
<header>Welcome to Logans Dinner</header>
<div id='column-1'>
<nav>
<ul>
<li><a href='/Menu.html'>Menu</a></li>
<li><a href='/About.html'>About Us</a></li>
<li><a href='/Contact.html'>Contact Us</a></li>
</ul>
</nav>
</div>
<div id='column-2'>
<section>
<p>Our Menu</p>
<table>
<thead>
<tr>
<th>Food</th>
<th>Description</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Burger</td>
<td>1/2 lb Angus Beef</td>
<td>$10.99</td>
</tr>
</tbody>
</table>
</div>

</section>

关于html - 调整盒模型布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48871073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com