使页面的左侧和右侧无需引导即可响应

时间:2017-06-19 07:57:41

标签: html css responsive-design

我已经创建了一个网页,现在我正在努力做出回应。它是一个非常简单的页面,包含注册表单和一些链接左侧+右侧。

结构非常简单,例如:

flatMap()

我尝试从某些教程添加媒体查询,但它不起作用,我不知道为什么以及如何执行此操作。这是查询

<div id="wrapper"> 
  <div id="main-content">    
     <div class="text-intro">
        .. some text
     </div>  

     <div id="left-sidebar">            
         <div id="navigation">
              .. some links
         </div>  
     </div>

     <div id="content">
         <div id="form"> 
          .. the form on the right side
         </div>
     </div>
</div>

这是上述来源的完整演示:https://jsfiddle.net/q97odta6/

这里有人可以帮忙吗?

4 个答案:

答案 0 :(得分:0)

尝试检查 head 标记中添加的viewport meta 标记。如果没有在 head 标记

中添加以下内容
<meta name="viewport" content="width=device-width, initial-scale=1.0">

答案 1 :(得分:0)

您可以使用 Flexbox 执行此操作:

&#13;
&#13;
* {margin: 0; padding: 0; box-sizing: border-box}

#wrapper {
  width: 1200px;
  max-width: 100%; /* responsiveness */
  margin: 0 auto; /* horizontally centered */
}

section {
  display: flex; /* displays flex-items (children) inline */
}

aside {
  flex: 1; /* takes the remaining width */
  display: flex;
  justify-content: center; /* horizontally centers the content */
  background: lightgreen;
}

article {
  width: 400px; /* fixed width */
  text-align: center;
  background: lightblue;
}

@media (max-width: 600px) {
  section {flex-direction: column} /* stacks flex-items vertically */
  article {width: initial} /* back to default behavior */
}
&#13;
<div id="wrapper"> 
  <section> 
    <aside>            
      <nav>
        links
      </nav>
    </aside>    
    <article>
      text
    </article>
    <aside>
      <form> 
        form
      </form>
    </aside>
  </section>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

这是你正在寻找的吗?

&#13;
&#13;
body {
  margin: 0px;
  padding: 0px;
  background: #f5f5f5;
}

.qt4 {
  transition: .4s ease-in-out 0s;
}

* {
  font-family: "Myriad Set Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: .02em;
  font: 10;
}

.container {
  position: relative;
  margin: 0 auto;
  max-width: 1000px;
  width: 100%;
  height: ;
}

.box {
  width: calc(100% - 20px);
  height: calc(100% - 20px);
  background: white;
  margin: 10px auto;
  border-radius: 5px;
  position: relative;
  box-shadow: 0 1px 5px rgba(68, 68, 68, 0.26);
}

.me.box {
  position: absolute;
  top: 0px;
  left: 10px;
  z-index: 2;
}

.sides {
  position: absolute;
  width: 200px;
  height: 100%;
}

.side_containers {
  width: 100%;
  height: 100%;
  top: 0px;
  position: absolute;
}

.left {
  left: 0px;
}

.right {
  right: 0px;
}

.center {
  position: relative;
  margin: 0 auto;
  width: calc(100% - 400px);
  height: 400px;
  z-index: 1;
}

.name {
  font-size: 40px;
  text-align: center;
  color: red;
  padding-top: 150px;
  color: black;
  opacity: .15;
}

@media only screen and (max-width: 700px) {
  .side_containers {
    width: 100%;
    height: 100%;
    position: relative;
  }
  .side_containers .name {
    padding-top: 120px;
  }
  .sides {
    width: 50%;
    height: 300px;
  }
  .center {
    width: 100%;
    height: 400px;
  }
}

@media only screen and (max-width: 400px) {
  .side_containers {
    height: auto;
  }
  .sides {
    width: 100%;
    height: 300px;
    position: relative;
  }
}
&#13;
<body>
  <div class="qt container">

    <div class="qt center">
      <div class="me box">

        <div class="qt name">Center</div>

      </div>

    </div>
    <div class="qt side_containers">
      <div class="qt sides right">
        <div class="right box">

          <div class="qt name">Right</div>

        </div>

      </div>
      <div class="qt sides left">
        <div class="left box">

          <div class="qt name">Left</div>

        </div>

      </div>

    </div>

  </div>

</body>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

这里的东西要短得多。这使用弹性盒系统。 由于缺乏对视口的完全控制,因此在现代设计中不建议使用向左浮动。

左浮=旧设计

Flexbox =现代设计

body {
  margin: 0px;
  background: #f5f5f5;
  font-family: "Myriad Set Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: .02em;}

.r {position: relative;}

.white {
  background: white;
  border-radius: 5px;
  box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.25);}

.container {
  width: calc(100% - 40px);
  display: flex;
  padding: 20px;
  max-width: 1000px;
  margin: 0px auto;
  text-align: center;}

.box div {
  padding-top: 150px;
  font-size: 30px;
  color: rgba(0, 0, 0, 0.1);}







.side {width: 200px;height: 400px;}
.left.side {margin: 100px 0px 0px 0px;}
.right.side {margin: 100px 0px 0px 0px;}

.center {
  width: calc(100% - 400px);
  height: 400px;
  margin: 20px;}







@media only screen and (max-width: 900px) {
  .container {flex-flow: wrap;}
  .side {width: calc(50% - 10px);}
  .left.side {margin: 20px 20px 0px 0px;}
  .right.side {margin: 20px 0px 0px 0px;}
  .center {
    width: 100%;
    order: -1;
    margin: 0px;}}

@media only screen and (max-width: 400px) {
  .container {flex-flow: wrap;}
  .side {width: 100%;}
  .left.side {margin: 20px 0 0 0;}
  .right.side {margin: 20px 0 0 0;}}
<title>Resize</title>


<body class="">
  <div class="r container">
    <div class="r white box left side">
      <div>Left</div>
    </div>
    <div class="r white box center">
      <div>Center</div>
    </div>
    <div class="r white box right side">
      <div>Right</div>
    </div>
  </div>