How to inherit a certain position (CSS)

Viewed 220

After ~2 hours of researching I couldn't find a solution for my problem, I am trying to inherit the center of the background since the "blurred-box" gets bigger depending on the computer resolution.

It looks like this(laptop resolution): website image 1 And I would like to make it show the center of the background image instead of the corner.

* {
  margin: 0;
  padding: 0;
}

html {
  width: 100vw;
  height: 100vh;
}

body {
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  background-position: top;
  background-image: url(https://images.unsplash.com/photo-1477346611705-65d1883cee1e?dpr=0.800000011920929&auto=format&fit=crop&w=1199&h=800&q=80&cs=tinysrgb&crop=);
  width: 100%;
  height: 100%;
  font-family: Arial, Helvetica;
  letter-spacing: 0.02em;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

.blurred-box {
  position: fixed;
  width: 550px;
  height: 670px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: inherit;
  border-radius: 2px;
  overflow: hidden;
}

.blurred-box:after {
  content: '';
  width: 1000px;
  height: 1000px;
  background: inherit;
  position: absolute;
  bottom: 0;
  box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.05);
  filter: blur(10px);
}

.user-login-box {
  position: relative;
  margin-top: 50px;
  text-align: center;
  z-index: 1;
}

.user-login-box>* {
  display: inline-block;
}
<div class="blurred-box">
  <div class="user-login-box">
    <h1>text here</h1>
  </div>
</div>

If someone posts a solution I would like to have a link for documentation with those informations(if that is okay), thanks.

1 Answers

You are almost good, remove the use of translate() which is creating the issue and center your element using margin:auto instead:

body {
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  background-position: top;
  background-image: url(https://images.unsplash.com/photo-1477346611705-65d1883cee1e?dpr=0.800000011920929&auto=format&fit=crop&w=1199&h=800&q=80&cs=tinysrgb&crop=);
  margin:0;
  height: 100vh;
  font-family: Arial, Helvetica;
  letter-spacing: 0.02em;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

.blurred-box {
  position: fixed;
  width: 550px;
  height: 670px;
  top: 0;
  left: 0;
  bottom:0;
  right:0;
  margin:auto;
  background: inherit;
  border-radius: 2px;
  overflow: hidden;
}

.blurred-box:after {
  content: '';
  width: 1000px;
  height: 1000px;
  background: inherit;
  position: absolute;
  bottom: 0;
  box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.05);
  filter: blur(10px);
}

.user-login-box {
  position: relative;
  margin-top: 50px;
  text-align: center;
  z-index: 1;
}

.user-login-box>* {
  display: inline-block;
}
<div class="blurred-box">
  <div class="user-login-box">
    <h1>text here</h1>
  </div>
</div>

Related