网站的自适应布局

时间:2018-02-10 14:03:41

标签: html css

我提前为我糟糕的英语道歉,如果不是这样的话))。

您好,我需要帮助,如何在为手机缩放时移动块。

目前,如果缩小屏幕,它们会稍微缩小。

以下是缩放时应如何迁移的example

帮助,请提前感谢。

以下是网站的块布局代码:

.section {
    position: absolute;
    z-index: 0;
    width: 50%;
    height: 50%;
    overflow: hidden;
    -webkit-transform: scale(1);
            transform: scale(1);
    will-change: transform;
    -webkit-transition-property: all;
    transition-property: all;
    -webkit-transition-duration: 300ms;
            transition-duration: 300ms;
    -webkit-transition-timing-function: ease-in-out;
            transition-timing-function: ease-in-out;
  }
  .section:first-child {
    top: 0;
    left: 0;
    background: #F06060;
  }
  .section:nth-child(2) {
    top: 0;
    left: 50%;
    background: #FA987D;
  }
  .section:nth-child(3) {
    top: 50%;
    left: 0;
    background: #72CCA7;
  }
  .section:nth-child(4) {
    top: 50%;
    left: 50%;
    background: #10A296;
  }
  .section.is-expanded {
    top: 0;
    left: 0;
    z-index: 1000;
    width: 100%;
    height: 100%;
  }
  .has-expanded-item .section:not(.is-expanded) {
    -webkit-transform: scale(0);
            transform: scale(0);
    opacity: 0;
  }
  
  .section.is-expanded {
    visibility: visible;
    opacity: 1;
    -webkit-transition: opacity 200ms linear 300ms;
    transition: opacity 200ms linear 300ms;
  }
  .demo-box {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    height: 100%;
    -webkit-box-pack: center;
        -ms-flex-pack: center;
            justify-content: center;
    -webkit-box-align: center;
        -ms-flex-align: center;
            align-items: center;
    color: #fff;
    font-size: 2rem;
    font-weight: 300;
  }
<main class="main">
  <section class="section">
    <div class="demo-box">Section 1</div>
  </section>
  <section class="section">
    <div class="demo-box">Section 2</div>
  </section>
  <section class="section">
    <div class="demo-box">Section 3</div>
  </section>
  <section class="section">
    <div class="demo-box">Section 4</div>
  </section>
</main>

1 个答案:

答案 0 :(得分:0)

@media only screen and (max-width:480)
{  
   .section {
        width: 100%;
        height: 50%;
        float:left;
    }
}

试试这个我觉得它很有用