首页htmlmediaCSS Layout - 如何对介质宽度反应

CSS Layout - 如何对介质宽度反应

我们想知道如何对介质宽度反应。

<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#yourPageContainer {
  width: 1000px;
  border: 1px solid #f00;
}

#otherElements {
  background-color: #afa;
  width: 200px;
  height: 100px
}

@media screen and (max-width:500px) {
  #yourPageContainer {
    width: 500px;
  }
  #otherElements {
    background-color: #aaf;
    width: 100px;
  }
}

@media screen and (max-width:300px) {
  #yourPageContainer {
    width: 300px;
  }
  #otherElements {
    background-color: #faa;
    width: 50px;
  }
}
</style>
</head>
<body>
  <div id="yourPageContainer">
    <div id="otherElements">Other elements</div>
  </div>
</body>
</html>