我正在为自己构建一个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>

发布于 2018-05-30 21:08:32
有几种方法,但在本例中,我将"display: block“应用于图像,以便它可以使用margin属性。
/* 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>发布于 2018-05-30 21:20:32
HTML5中不支持align属性。请改用CSS。
.className{
text-align:center
}或者,您可以始终使用display flex
.className{
display:flex;
justify-content:center
}https://stackoverflow.com/questions/50605242
复制相似问题