gpt4 book ai didi

html - 如何在不使用表格的情况下布置我的部分

转载 作者:太空宇宙 更新时间:2023-11-04 10:18:45 26 4
gpt4 key购买 nike

我可以强制使用表格进行此布局,但我认为最佳做法可能是在 CSS 中进行一些显示/ float 设置。我有一个按需要工作的标题和菜单部分。在它们下面是包裹丑陋的顶部、中间和底部部分。顶部应该有一个图像,后跟一个文本 block 。中间部分应该有 3 个相等的文本 block 。底部(页脚)应该有 1 个相等的文本 block 。有没有一种干净的方法可以做到这一点而不把它塞进 table 里?到目前为止,这是我正在做的事情,正如我所说,它很丑陋:

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home Page</title>
<link href="/Content/site.css" rel="stylesheet"/>
</head>
<body>
<header>
<span class="HeaderTitle">My header info</span>
</header>
<nav>
<!-- the menu is working fine -->
</nav>
<main>
<style>
.MyArticle
{
width: 30%;
display: inline-block;
float: left;
margin: 8px;
}
</style>
<div class="jumbotron">
<img src="/Images/Photo.jpg" style="border:solid 1px black; margin-right: 14px;" height="180px" align="left">
<p class="lead">Some text</p>
</div>
<br/>

<section id="MiddleSection">
<span class="MyArticle">
<h2>Current News</h2>
<p>Some text</p>
</span>
<span class="MyArticle">
<h2>Something</h2>
<p>Some text</p>
</span>
<span class="MyArticle">
<h2>Something</h2>
<p>Some text</p>
</span>
</section>
</main>

<footer>
<div>
<br />
<hr />
<p>&copy; 2016 - Steve Gaines</p>
</div>
</footer>
</body>
</html>

最佳答案

这是一种方法。基本上,您只需要清除 float 即可。下面是一些关于 CSS Floats 的读物:

* {
box-sizing: border-box;
}
.jumbotron img {
border: solid 1px black;
margin-right: 14px;
}
#MiddleSection {
clear: left;
margin: 0px auto;
}
.MyArticle {
width: 33%;
display: inline-block;
text-align: center;
background: grey;
}
footer {
clear: left;
text-align: center;
}
<header>
<span class="HeaderTitle">My header info</span>
</header>
<main>
<div class="jumbotron">
<img src="/Images/Photo.jpg" height="180px" align="left">
<p class="lead">Some text</p>
</div>
<br/>
<section id="MiddleSection">
<span class="MyArticle">
<h2>Current News</h2>
<p>Some text</p>
</span>
<span class="MyArticle">
<h2>Something</h2>
<p>Some text</p>
</span>
<span class="MyArticle">
<h2>Something</h2>
<p>Some text</p>
</span>
</section>
</main>
<footer>
<div>
<br />
<hr />
<p>&copy; 2016 - Steve Gaines</p>
</div>
</footer>

虽然大多数人通常不会在他们的网站上制作全宽内容(将代码段展开到全屏以了解我的意思)。

另一种对现代浏览器更好/更简单的方法是使用 Flexbox 方法(如果您必须支持 IE8 或 IE9 等,则不是真正的选择)。

关于html - 如何在不使用表格的情况下布置我的部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37016074/

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