首页 > 解决方案 > 如何为具有全尺寸背景的登录表单设置模糊、居中和响应框的样式?

问题描述

我试图在具有全尺寸、居中背景图像的 HTML 页面(Angular)上构建登录表单,并且表单放置在背景模糊的 div 中,该表单位于浏览器的 x 轴和 y 轴的中心窗户。

这就是我走了多远:https ://codepen.io/surfermicha/pen/ZwpxBa

<div class="login-background-door2">
  <div class="aero-background centered">
    <h3>Here will be a login form later</h3>
  </div>
</div>

不幸的是,我对此有一些问题:

  1. 居中的框不完全在中心
  2. 它没有响应。div 在小型设备上很小。我想要左右 10 像素的边距,但在更大的屏幕上最大宽度为 500 像素。

任何人都可以帮助编辑代码笔以获得有效的响应解决方案

标签: htmlcssangularresponsive

解决方案


您可以根据需要设置媒体查询,就像我设置为 567px 一样,因为在您的中心块的 567px 视图之后,看起来不太好,所以我设置为 567px。

body, html {
  font-family: "roboto", monospace;
  color: #EEE;
  padding: 0;
  width: 100%;
  margin: 0;
  height: 100%;
  overflow-x: hidden;
}

.aero-background::before {
  content: '';
  background: url("http://placekitten.com/2400/2000") center no-repeat;
  filter: blur(6px);
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  pointer-events: none;
}

.aero-background {
  border-radius: 5px;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  align-items: center;
  justify-content: center;
  text-shadow: 0 0 10px black;
}

.centered {
  max-width: 500px;
  min-height: 300px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.login-background-door2 {
  background: url("http://placekitten.com/2400/2000") center no-repeat;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

@media screen and (max-width: 567px) {
  .centered {
    width: 250px;
  }
}
<div class="login-background-door2">
  <div class="aero-background centered">
    <h3>Here will be a login form later</h3>
  </div>
</div>


推荐阅读