CSS将指定像素缩放为动态

时间:2017-11-04 19:37:07

标签: css html5 twitter-bootstrap css3 web-frontend



body {
  margin: 0;
  background-color: #2196F3;
}

.outer {
  height: 100vh;
}

.inner {
  width: 500px;
  height: 1000px;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  background-color: #FF5722;
}

<div class="outer">
  <div class="inner"></div>
</div>
&#13;
&#13;
&#13;

内部div与特定像素如何适合屏幕高度或宽度,CSS 保持比率相同

1 个答案:

答案 0 :(得分:0)

喜欢这个?:

&#13;
&#13;
body {
  margin: 0;
  background-color: #2196F3;
}

.outer {
  height: 100vh;
  width: 100%;
}

.inner {
  width: calc(100% - 40px);
  height: calc(100% - 40px);
  background-color: #FF5722;
  margin-top: 20px;
  margin-left: 20px;
}
&#13;
<div class="outer">
  <div class="inner"></div>
</div>
&#13;
&#13;
&#13;