0

It's my html code:

<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Problem 01</title>
        
        <link rel="stylesheet" href="./main.css">
        <link rel="stylesheet" href="./style.css">
    </head>
    <body>
        <img id="logo" src="./images/logo.png" alt="Code-Star logo"/>
    </body>
</html>

and the styles:

body {
    position: relative;
    background-image: linear-gradient(to bottom right, #f3440e, #f02e08);
}

#logo {
    position: absolute;
    display: block;
    background-color: green;
    left: 50%;
    bottom: 50%;
    width: 100px;
}

I want to center the #logo element and create a gradient for body.
the first problem is that when I set position: absolute; for #logo element, the gradient doesn't apply to the body.
the second is that when I set position: relative; to the body, the #logo element doesn't align properly to the screen!

1 Answers1

-1

use flex style and also give a height to body

html {
  height: 100%;
}

body {
  background-image: linear-gradient(to bottom right, #f3440e, #f02e08);
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
}

#logo {
  background-color: green;
  width: 100px;
}
<img id="logo" src="./images/logo.png" alt="Code-Star logo" />
Deepu Reghunath
  • 8,132
  • 2
  • 38
  • 47