我有一个白色的盒子,我正在用它做一个文字游戏.当我调整浏览器窗口以缩小视区时,框不会移动到中心或缩小,它几乎会滑动.

我希望它像Wordle一样工作,因为即使你缩小浏览器,网格也保持不变.

有人能帮我解释一下我的css定位有哪些错误吗?

* {
  padding:0;
  margin:0;
}

body{
  margin: 0;
  padding: 0;
  font-family: 'Figtree', sans-serif;
  font-family: 'Inter', sans-serif;
  font-family: 'Montserrat', sans-serif;
  background: #212529;
}

.wrapper{
  margin-top: 120px;
  align-content: center;
  position: fixed;
  left:400px;
  padding: 0px 80px;
  background: white; opacity: 1;
  border-radius: 10px;
  box-shadow: 0 3px 5px rgba(0,0,0,0.5);
  max-width: 500px;
  max-height: 500px;
}
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="style.css" />
    <link href="https://fonts.googleapis.com/icon?family=Material+Symbols+Outlined" rel="stylesheet">
  </head>
  <body>
    <div class="wrapper">
      <div class="content">
        <div class="guesses-text">0/10</div>
          <hr class="bum">
          <div class="inputs">
          <input type="text" class="exterior-letters">
          <input type="text" class="interior-letters">
          <input type="text" class="interior-letters">
          <input type="text" class="interior-letters">
          <input type="text" class="exterior-letters">
        </div>
      </div>
    </div>
  </body>
</html>

我try 过使用"Display:Flex;"和其他方法,但都不起作用.

推荐答案

要使页面中心的框与任意大小的浏览器保持居中,您可以使用Flexbox并相应地调整css属性.

以下是我为达到效果而修改的css:

* {
    padding: 0;
    margin: 0;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Figtree', sans-serif;
    font-family: 'Inter', sans-serif;
    font-family: 'Montserrat', sans-serif;
    background: #212529;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.wrapper {
    padding: 0px 80px;
    background: white;
    opacity: 1;
    border-radius: 10px;
    box-shadow: 0 3px 5px rgba(0, 0, 0, 0.5);
    max-width: 500px;
    max-height: 500px;
}

我从.wrapper类中删除了固定位置、页边距-顶部和Left属性.相反,我将FlexBox属性应用于Body元素,以使长方体在视口中水平和垂直居中.这样,框将保持居中,并与任何大小的浏览器进行zoom .

我不是职业球员,但这里有一种方法可以调整它在中间的位置.

Html相关问答推荐

为什么在这种情况下是弹性基础:自动不解决内容的大小?

损坏的可点击html邮箱签名

为什么我的网页底部是蓝色背景而不是渐变色?

创建带有弯曲边框的水平时间线

在将DevExtreme升级到版本23.2之后,到处都会生成一个Pesudo类,我在其中使用了<;DXi-Item Title=&Quot;&Quot;>;

天使17:令人惊叹的动画

我怎样才能在我的网站上制作花哨的角落

SVG动画只有在打开S开发工具的浏览器时才开始播放

有没有什么方法可以很容易地给一个SVG一个插框阴影?

如何使元素具有粘性