gpt4 book ai didi

javascript - 用 css 居中 html 内容

转载 作者:行者123 更新时间:2023-11-28 01:37:16 24 4
gpt4 key购买 nike

我正在为自己构建一个 WIP 占位符页面,但我一直坚持使用 CSS 将媒体内容居中。我设法让它在移动设备上运行,但内容在桌面设备上略微偏右。

更新:我已经添加了整个代码以及我选择的支持它的 CSS。如您所知,CSS 的 .display 部分是我遇到最多麻烦的地方(假设我已经解决了这个问题)。根据我在这里被告知和在其他地方阅读的内容,我最初在 HTML 中尝试的标签不适用于 HTML5,所以我希望让 CSS 完成它。就像我之前提到的,在移动设备上预览时,它工作正常,页面底部的链接堆叠得很好,但在完整的桌面上一切都崩溃了。

下面是代码:

@charset "utf-8";
/* CSS Document */
.content {
max-width: 500px;
margin: auto;
}
.display{
position:relative;
display: block;
padding: 0;
margin:0 auto;
width: auto;
text-align:center;
display:flex;
justify-content:center;
}

.button {
background-color: #FFFFFF;
border: #000000;
border-bottom-width: 2px;
text-decoration-color: #FFFFFF;
padding: 15px 32px;
text-align: center;
display: inline-block;
font-size: 16px;
}

.help-block.with-errors {
color: #ff0000;
margin-top: 5px;
}

.overlay {
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
background-color:rgba(0, 0, 0, 0.8);
z-index:100;
color:white;
display: none;
font-family: 'source_sans_proregular';
line-height: 25px;
-webkit-text-size-adjust:none;
text-size-adjust:none;
}

.container {
width:100%;
height:100%;
margin:0;
padding:0;
border:0;
}

.container td {
vertical-align: middle;
text-align: center;
}

.centerAlign {
text-align: center;
}

.margin2x {
margin-bottom: 24px;
}

.margin1x {
margin-bottom: 12px;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>mAdjetey is getting an upgrade</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link href="index_files/mine.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="index_files/favicon.png">

</head>
<a name="tepin"></a>

<div class="display" align="center">
<img src="index_files/uc_main.png" style="max-width:100%" height="auto" alt="Website under redesign">
</div>

<div class="display">
<div class="w3-topbar">
<a href="email.html"><img src="index_files/icon_email.png" alt="Email"></a>
</div>
</div>

<div class="display" align="center">
<a href="#tepin" class="button">Back to top of page</a>
</div>

</html>

This is the main image in question

最佳答案

有几种方法,但在这个例子中,我将“显示: block ”应用于图像,以便它可以使用边距属性。

/* CSS */
.display img {
display: block;
padding: 0;
/* maybe some top margin too? margin: 30% auto 0 */
margin: 0 auto;
width: auto;
}

<!-- HTML -->
<div class="display" align="center">
<img src="index_files/uc_main.png" style="max-width:100%" height="auto" alt="Website under redesign">
</div>

关于javascript - 用 css 居中 html 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50605242/

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