Reputation: 67
Im trying to make my links on my page left-aligned but centered on the page. How do I do this? I have tryed many ways and googled many more I haven't been codeing very long and this is becoming a real strugle.
This is my Html code
<!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>
The 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");
}
Upvotes: 5
Views: 13484
Reputation: 45454
#app {
/* step 2: center the text container in a flex box */
display: flex;
justify-content: center;
}
/* step 3: be stylish */
#app, body, html {
background: skyblue;
color: royalblue;
}
<div id="app">
<!-- step 1: wrap the text in a display:block element -->
<div>
<h2>foo bar</h2>
<h2>lorem ipsum</h2>
<span>hey hey</span><br />
<span>blah blah blah</span>
</div>
</div>
Upvotes: 0
Reputation: 1645
This is a sample solution. I wrapped the links in a div to make this work. I hope it helps
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>
Upvotes: 2
Reputation: 346
Here is a working fiddle I added a container that is the width of the nav items with the display: inline-block;
property. This div is wrapped and centered with the text-align: center;
property. I changed the a
text alignment from center > left to make the left aligned inside the div. I would also validate the HTML because it looks like there is some error inside your code.
Check out this question for more information about a good HTML boilerplate. A good HTML skeleton
Also check out this page if you want to clean up your code a bit 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;
}
Upvotes: 3
Reputation: 1334
Like this? I also cleaned up your html a bit. You can play around with the width on the ul.container
, this will move the 'list' to the left or right.
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>
Upvotes: 1