gpt4 book ai didi

html - 居中我的文字,但保持左对齐?

转载 作者:行者123 更新时间:2023-12-04 02:05:43 24 4
gpt4 key购买 nike

我试图让我的页面上的链接左对齐但居中。我该怎么做呢?我尝试了很多方法并在谷歌上搜索了更多我没有编写很长时间的代码,这正在成为一场真正的斗争。

My site

这是我的HTML代码

    <!DOCTYPE html>
<html>
<head>
<Title> Conspiracy Theories </Title>
</head>
<link href="mystyle.css" type="text/css" rel="stylesheet">
<Body>
<img src="http://media.moddb.com/images/groups/1/9/8589/tin_foil_hat.gif" />
<a <link href="WP1.html" type="text/html" style="text-decoration:none" rel="html"> EmDrive is being tested on the X-37B</a></li>
<a <link href="WP2.html" type="text/html" style="text-decoration:none" rel="html"> Diesel Submarines</a></li>
<a <link href="WP3.html" type="text/html" style="text-decoration:none" rel="html">Lethal B-21 vs. B-2 Stealth Bomber</a></li>
<a <link href="WP4.html" type="text/html" style="text-decoration:none" rel="html"> Air Force Wants a New Fighter</a></li>
<a <link href="WP5.html" type="text/html" style="text-decoration:none" rel="html"> King Tiger Tank : Super Weapon or Super Myth?</a></li>
<a <link href="WP6.html" type="text/html" style="text-decoration:none" rel="html"> Ground Combat Vehicle (GCV)</a></li>
<a <link href="WP7.html" type="text/html" style="text-decoration:none" rel="html"> 3 service men killed</a></li>
<a <link href="WP8.html" type="text/html" style="text-decoration:none" rel="html"> US intercepts 2 Russian bombers</a></li>
<a <link href="WP9.html" type="text/html" style="text-decoration:none" rel="html"> World reacts to US strikes</a></li>
</div>
</div>
</Body>
<h1> </h1>

CSS

img {
padding-bottom: 30px;
display: block;
margin: auto;
width: 10%;
}

a {
line-height: 1.7em;
display:block;
margin-left: auto;
text-align: center;
color: black;
}

body {
background-image:
url("https://presentations.inxpo.com/SharedContent/VX/images/background-
shell.jpg");
}

最佳答案

这是一个有效的 fiddle我添加了一个容器,它是具有 display: inline-block; 属性的导航项的宽度。这个 div 用 text-align:center; 属性包裹并居中。我将 a 文本对齐方式从 center > left 更改为在 div 内左对齐。我也会validate HTML,因为看起来您的代码中存在一些错误。

查看此问题以获取有关良好 HTML 样板的更多信息。 A good HTML skeleton

如果您想稍微清理一下代码,也请查看此页面 DirtyMarkup

HTML

<!DOCTYPE html>
<html>
<head>
<title>
Conspiracy Theories
</title>
<link href="mystyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<img src="http://media.moddb.com/images/groups/1/9/8589/tin_foil_hat.gif">
<div class="text-center">
<div class="display-inline">
<a><link href="WP1.html" rel="html" style="text-decoration:none" type="text/html">EmDrive is being tested on the X-37B</a>
<a><link href="WP2.html" rel="html" style="text-decoration:none" type="text/html">Diesel Submarines</a>
<a><link href="WP3.html" rel="html" style="text-decoration:none" type="text/html">Lethal B-21 vs. B-2 Stealth Bomber</a>
<a><link href="WP4.html" rel="html" style="text-decoration:none" type="text/html">Air Force Wants a New Fighter</a>
<a><link href="WP5.html" rel="html" style="text-decoration:none" type="text/html">King Tiger Tank : Super Weapon or Super Myth</a> <a><link href="WP6.html" rel="html" style="text-decoration:none" type="text/html">Ground Combat Vehicle (GCV)</a>
<a><link href="WP7.html" rel="html" style="text-decoration:none" type="text/html">3 service men killed</a>
<a><link href="WP8.html" rel="html" style="text-decoration:none" type="text/html">US intercepts 2 Russian bombers</a>
<a><link href="WP9.html" rel="html" style="text-decoration:none" type="text/html">World reacts to US &gt;</a>
</div>
</div>
</body>
</html>

CSS

.text-center {
text-align: center;
}

.display-inline {
display: inline-block;
}

a {
text-align: left;
}

关于html - 居中我的文字,但保持左对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43597126/

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