Morgan February 2016

How to get background to scale to any screen?

How do I get my background to scale to fit any screen? I have tried background-size: cover and height: auto but nothing works! Any ideas? I can't seem to find anything that works. I appreciate anything that you can offer to this problem.

<!DOCTYPE html>
<html>
<link rel="shortcut icon" href="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5e/Metro-M.svg/2000px-Metro-M.svg.png">
<head>
<style>
html {
    background: URL("https://lh3.googleusercontent.com/-lYQ3vQHE3Mo/VrVKGwg8pqI/AAAAAAAADMQ/QKjs5ALViKo/w530-d-h253-p-rw/desk%2Bbackground.png") #363634 no-repeat center top;
    background-size: cover;
    margin: 0;
    padding: 0;
    position: fixed; 
    width: 100%;
    height: auto;
    position: fixed;
    top: 0;
    left: 0;
}
h1 {
    position: absolute;
    top: 21%;
    left: 25%;
    color: white;
    font-family: Arial;
    font-size: 4.6vw;
    letter-spacing: 1px;
}
p {
    position: absolute;
    width: 250px;
    top: -1px;
    left: 15px;
    height: 25px;
    font-family: Arial;
}
ul {
    word-spacing: .2em;
    letter-spacing: .2em;
}
ul li {
    font-family: Arial;
    text-align: center;
    vertical-align: middle;
    line-height: 40px;
    top: 43%;
    display: inline-block;
    margin-top: 250px;
    margin-left: 115px;
    letter-spacing: 1px;
    word-spacing: normal;
    background-color: rgba(5, 4, 2, 0.1);
    border: 2px solid white;
    color: white;
    text-align: center;
    text-decoration: none;
    font-size: 90%;
    width: 150px;
    height: 40px;
}
ul li:link,
ul li:visited {
    font-family: Arial;
    text-align: center;
    vertical-align: middle;
    line-height: 40px;
    display: inline-block;
    margin-top: 250px;
    margin-left: 115px;
    letter-spacing: 1px;
    word-spacing: normal;
    background-color: rgba(5, 4, 2, 0.1);
    border: 2px solid white;
    font-size: 90%;
    width: 150px;
    height: 40px;
    text-decoration: none;        

Answers


Pangloss February 2016

You can use the position tricks, set all to 0.

html {
  background: URL("https://lh3.googleusercontent.com/-lYQ3vQHE3Mo/VrVKGwg8pqI/AAAAAAAADMQ/QKjs5ALViKo/w530-d-h253-p-rw/desk%2Bbackground.png") #363634 no-repeat center top;
  background-size: cover;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}

Or set both width:100% and height:100%.

html {
  background: URL("https://lh3.googleusercontent.com/-lYQ3vQHE3Mo/VrVKGwg8pqI/AAAAAAAADMQ/QKjs5ALViKo/w530-d-h253-p-rw/desk%2Bbackground.png") #363634 no-repeat center top;
  background-size: cover;
  position: fixed;
  width: 100%;
  height: 100%;
}

Post Status

Asked in February 2016
Viewed 3,020 times
Voted 6
Answered 1 times

Search




Leave an answer