Reputation: 2568
I've got the following HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Homepage</title>
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<div class="topbar">
<div class="title">Welcome</div>
<div class="control">
<span style="padding-right: 0.5em;"><a href="index.html">Bla</a></span>
<span style="padding-right: 0.5em;">Blue</span>
<span style="padding-right: 0.5em;"><a href="contact.html">Blub</a></span>
</div>
</div>
<div class="main">
<div class="text">
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam
</div>
</div>
</body>
And the following CSS file:
.body {
overflow: hidden;
color: black;
}
.html {
overflow: hidden;
margin: 0;
}
.title {
color: black;
font-family: 'Arial';
font-weight: bold;
font-size: 20pt;
padding: 0 0 0 0;
margin-left: 20%;
margin-top: 15px;
margin-bottom: 15px;
text-align: left;
float: left;
}
.control {
color: black;
font-family: 'Arial';
font-size: 15pt;
padding: 0 0 0 0;
margin-left: 0;
margin-right: 20%;
margin-top: 21px;
text-align: right;
}
.text {
margin-left: 20%;
margin-right: 20%;
font-family: 'Arial';
font-size: 12pt;
text-align: justify;
}
.topbar {
padding: 0 0 0 0;
overflow: hidden;
position: fixed;
top: 0;
left: 0;
right: 0;
width: 100%;
background-color: rgba(241, 241, 241, 0.9);
border-bottom: solid 1px black;
}
.main {
padding: 0 0 0 0;
overflow: hidden;
top: 0;
left: 0;
right: 0;
width: 100%;
padding-top: 75px;
}
How can I align both texts?
Upvotes: 0
Views: 37
Reputation: 272955
margin:0
to body and correct a typo: it's not .body
but only body
(same with html
) as they are not classes but tags.
For the explanation: Your top bar was fixed and set with left:0
and thus the default margin of body is not applied to it unlike the other content. That's why you had this small miss alignement (8px).
body {
overflow: hidden;
color: black;
margin:0;
}
html {
overflow: hidden;
margin: 0;
}
.title {
color: black;
font-family: 'Arial';
font-weight: bold;
font-size: 20pt;
padding: 0 0 0 0;
margin-left: 20%;
margin-top: 15px;
margin-bottom: 15px;
text-align: left;
float: left;
}
.control {
color: black;
font-family: 'Arial';
font-size: 15pt;
padding: 0 0 0 0;
margin-left: 0;
margin-right: 20%;
margin-top: 21px;
text-align: right;
}
.text {
margin-left: 20%;
margin-right: 20%;
font-family: 'Arial';
font-size: 12pt;
text-align: justify;
}
.topbar {
padding: 0 0 0 0;
overflow: hidden;
position: fixed;
top: 0;
left: 0;
right: 0;
width: 100%;
background-color: rgba(241, 241, 241, 0.9);
border-bottom: solid 1px black;
}
.main {
padding: 0 0 0 0;
overflow: hidden;
/* not needed since the element is static
top: 0;
left: 0;
right: 0;
*/
width: 100%;
padding-top: 75px;
}
<div class="topbar">
<div class="title">Welcome</div>
<div class="control">
<span style="padding-right: 0.5em;"><a href="index.html">Bla</a></span>
<span style="padding-right: 0.5em;">Blue</span>
<span style="padding-right: 0.5em;"><a href="contact.html">Blub</a></span>
</div>
</div>
<div class="main">
<div class="text">
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam
</div>
</div>
Upvotes: 1