响应式网页

时间:2016-05-06 12:24:11

标签: html css responsive-design

我已经添加了我的HTML代码以及我的CSS,我对如何使这个网页响应变得非常困惑,所以当用户在不同的设备上时,网页会自动扩展到他们的设备。 (对不起,如果这是一个重复的问题,我无法找到答案)。

       footer {
           margin: 50px 0;
       }

       .fade {
           opacity: 1;
           transition: opacity .25s ease-in-out;
           -moz-transition: opacity .25s ease-in-out;
           -webkit-transition: opacity .25s ease-in-out;
       }

       .fade:hover {
           opacity: 0.5;
       }

       h1 {
           margin: .67em 0;
           font-size: 2em;
           font-family: 'Dosis', sans-serif;
       }

       body {
           font-family: 'Dosis', sans-serif;
           font-size: 14px;
           line-height: 1.42857143;
           color: #333;
           background-color: #fff;
           padding-right: 5px;
       }

       body {
           max-width: 1000px;
           margin: 10px auto;
       }

       body {
           font-family: 'Dosis', sans-serif;
       }

       body {
           background: white;
       }

       .container {
           max-width: 100%;
           text-align: center;
       }

       .centre {
           position: relative;
           display: inline-block;
           float: left;
           max-width: 100%;
           padding: 50px;
       }

       ul {
           max-width: 100%;
           list-style-type: none;
           margin: 0;
           padding: 0;
           overflow: hidden;
           background-color: #333;
       }

       li {
           float: left;
           max-width: 100%;
       }

       li a {
           display: block;
           color: white;
           text-align: center;
           padding: 14px 16px;
           text-decoration: none;
       }

       a:hover:not(.active) {
           background-color: #111;
       }

       .active {
           background-color: #4CAF50;
       }

       .accordion {
           width: 895px;
           height: 485px;
           max-width: 100%;
           overflow: hidden;
           box-shadow: 0 10px 6px -6px #111;
           margin: 20px auto
       }

       .accordion ul {
           width: 200%;
           max-width: 100%;
       }

       .accordion li {
           position: relative;
           display: block;
           width: 160px;
           max-width: 100%;
           float: left;
           box-shadow: 0 0 30px 8px #222;
           transition: all 0.4s ease .300ms;
       }

       .accordion ul:hover li {
           width: 40px
       }

       .accordion ul li:hover {
           width: 640px
       }

       .caption {
           background: rgba(0, 0, 0, 0.5);
           position: absolute;
           bottom: 0;
           width: 640px
       }

       .caption a {
           display: block;
           color: #fff;
           text-decoration: none;
           font: normal 16px'Lato', Helvetica, Arial, sans-serif;
           -webkit-font-smoothing: antialiased;
           padding: 10px;
       }

       .center {
           align-content: center;
       }

       .thumbnail {
           display: block;
           padding: 4px;
           padding-left: 5px;
           margin-bottom: 20px;
           line-height: 1.42857143;
           background-color: #fff;
           border: 1px solid #ddd;
           border-radius: 4px;
           -webkit-transition: border .2s ease-in-out;
           -o-transition: border .2s ease-in-out;
           transition: border .2s ease-in-out;
       }

       .thumbnail > img,
       .thumbnail a > img {
           margin-right: auto;
           margin-left: auto;
       }

       a.thumbnail:hover,
       a.thumbnail:focus,
       a.thumbnail.active {
           border-color: #337ab7;
       }

       .thumbnail .caption {
           padding: 9px;
           color: #333;
       }
<body>

  <nav class="contain">
    <div>
      <div>
        <ul>
          <li><a class="active" href="index.html">Home</a>
          </li>
          <li><a href="Nike_Shoes1.html">Mens Shoes</a>
          </li>
          <li><a href="women_clothing.html">Womens Shoes</a>
          </li>
          <li><a href="boys_clothing.html">Boys Shoes</a>
          </li>
          <li><a href="boys_clothing.html">Girls Shoes</a>
          </li>
        </ul>
      </div>

    </div>

  </nav>


  <div class="container">

    <div>


      <div>

        <div class="accordion">
          <ul>
            <li>
              <div class="caption"><a href="#">Slide 1</a>
              </div>
              <a href="#">
                <img src='Slider_Image1.jpg' />
              </a>
            </li>

            <li>
              <div class="caption"><a href="#">Slide 2</a>
              </div>
              <a href="#">
                <img src='Slider_Image2.jpg' />
              </a>
            </li>

            <li>
              <div class="caption"><a href="#">Slide 3</a>
              </div>
              <a href="#">
                <img src='Slider_Image3.jpg' />
              </a>
            </li>

          </ul>
        </div>

      </div>

      <div>

        <div class="centre , fade ,">
          <div>
            <a href="Nike_Shoes1.html">
              <img src="Image1.jpg" alt="">
          </div>
        </div>

        <div class="centre , fade">
          <div>
            <a href="Nike_Trainers.html">
              <img src="Image2.jpg" alt="">

          </div>
        </div>

        <div class="centre , fade">
          <div>
            <img src="Image3.jpg" alt="">
          </div>
        </div>


        <div class="centre , fade">
          <div>
            <a href="boys_clothing.html">
              <img src="Boys_Clothing.jpg" alt="Boys Clothing">
          </div>
        </div>





      </div>

    </div>

  </div>

  </div>

  </div>


  <div>
    <!-- Footer -->
    <footer>



    </footer>

  </div>

2 个答案:

答案 0 :(得分:1)

通过向css文件添加媒体查询来使页面响应,例如:

@media(max-width: 800px){
    /* Add mobile styles here */
}

您可以在此处查看有关媒体查询的更多信息,因为有许多可用的配置:https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries

答案 1 :(得分:0)

您可以使用media queries,灵活的基于网格的布局进行相对尺寸调整和灵活图像来制作自适应网页。

这本书可能会帮助你Responsive Web Design by Ethan Marcotte