html - HTML CSS 居中整个站点
问题描述
我是 css、html 的新手,我正在为我叔叔的餐厅设计一个网站。我在 Adobe XD 中设计了我的第一个原型。然后我找到了一个叫 Avocode 的网站。我从那里使用了css代码。
.logo {
position: absolute;
top: 872px;
left: 57px;
width: 284px;
height: 193px;
z-index: +1;
}
然后我在 html 文档中使用了代码。
<div class="logo"><img src="logo.png" alt=""></div>
它工作得非常好,但我无法使网站居中。我应该怎么办?
解决方案
使整个网站居中的一种常见的、公认的方法是使用该margin: auto;
方法。
.content {
width: 75%; /* Could be anything, but 75% works here. */
margin: auto; /* This is what center the content div itself. */
border: 1px solid red;
}
p {
text-align: center; /* This will center the text inside the paragraph tag */
border: 1px solid black;
}
<html>
<head>
</head>
<body>
<div class="content">
<p>Here is some content!</p>
</div>
</body>
</html>
目标是将所有内容包装到一个 div 中,然后将该 div 居中。这将允许您仍然在该 div 中操作对象的样式,但总体而言,整个文档将居中。
推荐阅读
- postgresql - 使用 Python 代码将带有偏移量的日期插入 PostgreSQL 数据库
- javascript - 使用 ajax 和 laravel 提交表单
- javascript - AngularJS 重定向控制器和历史回溯问题
- html - 面临使用 VBA 从网站中提取数据的问题
- python - 在同一个表的报告中添加更多 id
- javascript - 使用 Gauge / Taiko 通过 removeAttribute('readonly') 自动化日期选择器
- amazon-web-services - 尝试使用 awsmobile init 初始化项目
- ios - Xamarion.iOS - statusBar 如何改变文本颜色?
- azure-log-analytics - 在 Azure Log Analytics 的查询中解析 IIS 日志
- fortran - 为什么不引发浮点异常 (FPE)?