我试图让我的页面上的链接左对齐但以页面为中心。我该怎么做呢?我已经尝试了很多方法并用Google搜索了很多我没有编写很长时间的代码,这已成为一种真正的方法。
这是我的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");
}
答案 0 :(得分:0)
喜欢这个?我也清理了你的HTML。您可以使用ul.container
上的宽度进行游戏,这会将“列表”向左或向右移动。
img {
padding-bottom: 30px;
display: block;
margin: auto;
width: 10%;
}
a {
line-height: 1.7em;
display: block;
margin-left: auto;
color: black;
text-decoration: none;
}
ul.container {
text-align: left;
margin-left: auto;
margin-right: auto;
width: 60%;
list-style-type: none;
padding: 0;
}
main {
background-image: url("https://presentations.inxpo.com/SharedContent/VX/images/background-
shell.jpg");
}
<!DOCTYPE html>
<html>
<head>
<Title> Conspiracy Theories </Title>
<link href="mystyle.css" type="text/css" rel="stylesheet">
</head>
<main>
<img src="http://media.moddb.com/images/groups/1/9/8589/tin_foil_hat.gif" />
<ul class="container">
<li><a href="WP1.html" type="text/html"> EmDrive is being tested on the X-37B</a></li>
<li><a href="WP2.html" type="text/html"> Diesel Submarines</a></li>
<li><a href="WP3.html" type="text/html"> Lethal B-21 vs. B-2 Stealth Bomber</a></li>
<li><a href="WP4.html" type="text/html"> Air Force Wants a New Fighter</a></li>
<li><a href="WP5.html" type="text/html"> King Tiger Tank : Super Weapon or Super Myth?</a></li>
<li><a href="WP6.html" type="text/html"> Ground Combat Vehicle (GCV)</a></li>
<li><a href="WP7.html" type="text/html"> 3 service men killed</a></li>
<li><a href="WP8.html" type="text/html"> US intercepts 2 Russian bombers</a></li>
<li><a href="WP9.html" type="text/html"> World reacts to US strikes</a></li>
</ul>
</main>
<h1> </h1>
答案 1 :(得分:0)
这是一个有效的fiddle我添加了一个容器,它是具有display: inline-block;
属性的导航项的宽度。此div被包装并以text-align: center;
属性为中心。我从中心更改了a
文字对齐&gt;左边使div在div内对齐。我也会validate HTML,因为看起来你的代码中有一些错误。
查看此问题,了解有关良好HTML样板的更多信息。 A good HTML skeleton
如果您想稍微清理一下代码DirtyMarkup
,请查看此页面<!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 ></a>
</div>
</div>
</body>
</html>
.text-center {
text-align: center;
}
.display-inline {
display: inline-block;
}
a {
text-align: left;
}
答案 2 :(得分:0)
这是一个示例解决方案。我将链接包装在div中以使其工作。我希望它有所帮助
body {
background-image: url(https://presentations.inxpo.com/SharedContent/VX/images/background-shell.jpg);
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
img {
padding-bottom: 30px;
display: block;
margin: auto;
width: 10%;
}
body > div {
text-align: left;
margin: 0 auto;
}
a {
line-height: 1.7em;
display: block;
color: black;
}
<!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" />
<div>
<a link href="WP1.html" type="text/html" style="text-decoration:none" rel="html"> EmDrive is being tested on the X-37B</a>
<a link href="WP2.html" type="text/html" style="text-decoration:none" rel="html"> Diesel Submarines</a>
<a link href="WP3.html" type="text/html" style="text-decoration:none" rel="html">Lethal B-21 vs. B-2 Stealth Bomber</a>
<a link href="WP4.html" type="text/html" style="text-decoration:none" rel="html"> Air Force Wants a New Fighter</a>
<a link href="WP5.html" type="text/html" style="text-decoration:none" rel="html"> King Tiger Tank : Super Weapon or Super Myth?</a>
<a link href="WP6.html" type="text/html" style="text-decoration:none" rel="html"> Ground Combat Vehicle (GCV)</a>
<a link href="WP7.html" type="text/html" style="text-decoration:none" rel="html"> 3 service men killed</a>
<a link href="WP8.html" type="text/html" style="text-decoration:none" rel="html"> US intercepts 2 Russian bombers</a>
<a link href="WP9.html" type="text/html" style="text-decoration:none" rel="html"> World reacts to US strikes</a>
</div>
</Body>
</html>