skip to Main Content

I’m beginner, I would like to ask how can I make the "blured gray img" always stay in the center like the image. What I want with figma

This is my code and result:This is what created but it doesn’t like before image.Right and bottom sides are stuck to the browser edge.

The CSS:

html,body {
    margin: 0px;
    height: 100%;
}

.bg img {
    position: fixed;
    width: 100%;
    height: 100%;
    background-size: cover;
}


.wrapper {
    position: fixed;
    width: 100vw;
    height: 100vh;
    background-color: #38323283;
    border-radius: 45px;
    box-shadow: 3px 3px 4px #00000040, -3px -3px 4px #00000040;
    margin-top: 50px;
    margin-bottom: 50px;
    margin-left: 50px;
    margin-right: 50px;
}

The HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>profile</title>
    <link rel="stylesheet" href="CSS/style.css">
</head>
<body>
    <div class="bg">
        <img src="/img/IMG_0720.png" alt="">
        <div class="wrapper">

        </div>
    </div>
    
</body>
</html>

2

Answers


  1. Bro use this code

        * {
          margin: 0;
          padding: 0;
          box-sizing: border-box;
        }
    
        .bg {
          height: 100vh;
          display: flex;
          justify-content: center;
          align-items: center;
        }
    
        .bg img {
          position: fixed;
          width: 100%;
          height: 100%;
          background-size: cover;
        }
    
        .wrapper {
          position: fixed;
          width: calc(100% - 50px); /* change the 50px with your value */
          height: calc(100% - 50px); /* change the 50px with your value */
          background-color: #38323283;
          border-radius: 45px;
          box-shadow: 3px 3px 4px #00000040, -3px -3px 4px #00000040;
          /* margin-top: 50px; */
          /* margin-bottom: 50px; */
          /* margin-left: 50px; */
          /* margin-right: 50px; */
        }
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <title>profile</title>
        <link rel="stylesheet" href="CSS/style.css" />
      </head>
    
      
    
      <body>
        <div class="bg">
          <img src="/img/IMG_0720.png" alt="" />
          <div class="wrapper"></div>
        </div>
      </body>
    </html>
    Login or Signup to reply.
  2. I guess you just missed to code top into your wrapper.

    Perhaps you can fiddle with this?

    html,body {
        margin: 0px;
        height: 100%;
        width: 100%;
    }
    
    .bg {
        justify-content: center;
        align-items: center;
        display: flex;
        margin: 0 auto;
    }
    
    .bg img {
        width: 100%;
        display:block;
        margin:0 auto;
    }
    
    .cut {
        overflow: hidden;
        width: 80%;
        height: 80%;
        background: red;
        margin: 0 auto;
    }
    
    .wrapper {
        position: fixed;
        width: 80%;
        height: 80%;
        background-color: #38323283;
        border-radius: 45px;
        box-shadow: 3px 3px 4px #00000040, -3px -3px 4px #00000040;
        margin-top: 50px;
        margin-bottom: 50px;
        margin: 0 auto;
        top: 10%;
        left: 10%;
    }
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>profile</title>
        <link rel="stylesheet" href="CSS/style.css">
    </head>
    <body>
        <div class="bg">
          <div class="cut">
            <img src="https://images.unsplash.com/photo-1713494500139-a0d182b60cb8" alt="">
          </div>
            <div class="wrapper">
    
            </div>
        </div>
        
    </body>
    </html>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search