HTML让网站的大小始终相同

时间:2015-11-18 20:15:33

标签: html css html5 css3

我想知道您是否可以让您的网站始终保持相同的尺寸,因此当您在更大的屏幕上查看网站时,它只会为页面添加更多空间/背景。

(我不想要媒体查询,以便在屏幕变大时样式发生变化)

1 个答案:

答案 0 :(得分:1)

使用CSS可以使主div(包装器)居中。

#wrapper {
  width: 500px;
  
  margin: 0 auto;
  
  background: green;
}
body {
  margin: 0px;
  font-family: Arial;
}

#wrapper {
  width: auto; /* You can set the width here, but if you want to make the page smaller on smaller devices you use 'auto' here. */
  max-width: 500px; /* Set the maximum width of the webpage. */
  margin: 0 auto; /* Center the wrapper */
  background: green;
  color: white;
}
<body>
  <div id="wrapper">
    <h1>Welcome to your webpage.</h1>
    <h2>Site content goes here.</h2>
  </div>
</body>