Reputation: 359
today my question is asking how I could make an html page layout stay the same even for any different proportional screen size. For example, I'm creating an html page on a 15.6" 16:9 ratio screen size and I want to make it stay the same for when changing screen sizes.
Here's an example:
<!DOCTYPE html>
<html>
<head>
<style>
#header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
#nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#section {
width:350px;
float:left;
padding:10px;
}
#footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
</head>
<body>
<div id="header">
<h1>City Gallery</h1>
</div>
<div id="nav">
London<br>
Paris<br>
Tokyo<br>
</div>
<div id="section">
<h2>London</h2>
<p>
London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.
</p>
<p>
Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
</p>
</div>
<div id="footer">
</div>
</body>
</html>
So now I want the footer to stay at the bottom so yeah, how would I do that?
Upvotes: 0
Views: 122
Reputation: 1779
Not really sure about what you want to get, neverthless you can set specific rules based on aspect-ratio of the output device es:
...
@media screen and (device-aspect-ratio: 16/9) {
.foo {
...
}
}
@media screen and (device-aspect-ratio: 4/3) {
.foo {
...
}
}
and so on...
there are alo other ways to achive that kind of transformations, in my opinion media queries is the easiest.
Upvotes: 1
Reputation: 3174
Replace your footer CSS with this one
#footer {
background-color: black;
color: white;
text-align: center;
padding: 5px;
bottom: 2px;
position: fixed;
width: 100%;
}
And the full Code should be
<!DOCTYPE html>
<html>
<head>
<style>
#header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
#nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#section {
width:350px;
float:left;
padding:10px;
}
#footer {
background-color: black;
color: white;
text-align: center;
padding: 5px;
bottom: 2px;
position: fixed;
width: 100%;
}
</style>
</head>
<body>
<div id="header">
<h1>City Gallery</h1>
</div>
<div id="nav">
London<br>
Paris<br>
Tokyo<br>
</div>
<div id="section">
<h2>London</h2>
<p>
London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.
</p>
<p>
Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
</p>
</div>
<div id="footer">
</div>
</body>
</html>
Upvotes: 1