Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why won't my background-size change in CSS?

enter image description here

The white box with the cut off form to the left is the background here.

I temporarily took out all other styling and this is all that is left (some of it is not mine):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

body {
    margin: 0;
    font-family: -apple-system, Arial, sans-serif;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #69ce16;
    text-align: left;
    background-color: #fff;
    background-position: center;
    background-size: 20%;
    background-repeat: no-repeat;
    padding: 30px;
    padding-bottom: 10px;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    width: 50%;
}

I added the background size, repeat and position myself and even tried adjusting every other value there but nothing has worked. I used developer.mozilla.org for info on every single one of those css properties, so I have no idea why it won’t center to the middle of that "grey" page, or anywhere I want it, and even trying to reduce its size/width has not worked.

>Solution :

Try changing your width for example to

body{
   ...
   width: 50%;
   /* maybe add some height? */
   height: 500px;
}

Then you will see a change

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <style>
    body {
    margin: 0;
    font-family: -apple-system, Arial, sans-serif;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #69ce16;
    text-align: left;
    background-color: white;
    background-position: center;
    background-size: 20%;
    background-repeat: no-repeat;
    padding: 30px;
    padding-bottom: 10px;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    width: 80%;
    height:200px;
}</style>
</body>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading