首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >响应网站内容宽度比查看端口宽度宽

响应网站内容宽度比查看端口宽度宽
EN

Stack Overflow用户
提问于 2017-03-22 10:05:32
回答 1查看 2.4K关注 0票数 0

好的,所以我正在工作一个小模板,并试图学习响应网站开发。在测试它是否具有移动响应能力时,我遇到了一个问题,他们说:

内容宽度大于视口宽度▾视图端口宽度:320▾,内容宽度:563▾

然而,我似乎无法从我的样式表中弄清楚问题是什么?

代码语言:javascript
复制
body {
  background-color: #f1f1f1;
}

.wrapper {
  margin: 0 auto;
  padding: 0 20px 20px 20px;
  max-width: 1080px;
  min-width: 200px;
  background-color: #ffffff;
  height: 100%;
}

.header {
  width: 100%;
  height: 100px;
}

.header-right {
  float: right;
  height: 15px;
  padding: 24px 40px 20px 5px;
  margin-bottom: 30px;
}

.logo {
  float: left;
  display: block;
  max-width: 100%;
  max-height: 100%;
  border: 0;
}

.call-us {
  padding-right: 20px;
  max-width: 100%;
}

.cartImg {
  max-width: 40px;
  max-height: 40px;
}


/*MEDIA QUERY at 676 to 808px*/

@media (min-width: 676px) and (max-width: 808px) {
  .logo {
    float: left;
    display: block;
    max-width: 100%;
    margin-left: 25%;
    border: 0;
  }
}

@media (min-width: 676px) and (max-width: 808px) {
  .call-us {
    float: left;
    display: block;
    margin-right: 25%;
    max-width: 100%;
  }
}

@media (min-width: 676px) and (max-width: 808px) {
  .cartImg {
    float: left;
    margin-left: 25%;
    margin-top: 10px;
  }
}


/*MEDIA QUERY at 330 to 456px*/

@media (min-width: 330px) and (max-width: 456px) {
  .call-us {
    float: left;
    display: block;
    margin-left: 45px;
    max-width: 100%;
  }
}

@media (min-width: 330px) and (max-width: 456px) {
  .cartImg {
    float: left;
    margin-left: 50%;
    margin-top: 10px;
  }
}


/*MEDIA QUERY at 279 to 330px*/

@media (min-width: 279px) and (max-width: 330px) {
  .call-us {
    float: left;
    display: block;
    margin-left: 20px;
    max-width: 100%;
  }
}

@media (min-width: 279px) and (max-width: 330px) {
  .cartImg {
    float: left;
    margin-left: 50%;
    margin-top: 10px;
  }
}

.main {
  width: 100%;
  font-family: Segoe UI, Arial;
}

p {
  font-family: Segoe UI, Arial;
  font-size: 16px;
}

h1 {
  text-transform: uppercase;
  font-family: Segoe UI, Arial;
  font-weight: bold;
  letter-spacing: -0.5px;
  clear: both;
  text-align: center;
}

.styleBottomRed {
  height: 40px;
  line-height: 40px;
  padding: 0 10px;
  color: #FFFFFF;
  text-transform: uppercase;
  font-family: Segoe UI, Arial;
  font-weight: bold;
  letter-spacing: -0.5px;
  background-color: #204393;
  border-left: 2px solid white;
  text-align: center;
}

.tab_content_main {
  padding: 0 15px;
  background-color: #F1F1F1;
}

.prod-img {
  max-width: 100%;
  max-height: 100%;
}

hr {
  display: block;
  position: relative;
  padding: 0;
  margin: 8px auto;
  height: 0;
  width: 100%;
  line-height: 0;
  clear: both;
  border: none;
}

.bottomTabs {
  font-size: 20px;
  font-family: Segoe UI, Arial;
  font-weight: bold;
  height: 55px;
  max-height: 55px;
  text-align: center;
  color: white;
  background-color: #204393;
}

#iconImg {
  float: right;
  max-width: 40px;
  max-height: 40px;
}

.bottomTabsUL,
ul,
li {
  list-style-type: square;
  font-size: 16px;
  text-align: left;
}


/*MEDIA QUERY at 866 to 2000px hide different content and show other*/

@media screen and (min-width: 866px) and (max-width: 2000px) {
  .bottomTabs {
    display: none;
  }
  /* hide it elsewhere */
}

@media screen and (min-width: 866px) and (max-width: 2000px) {
  .bottomTabsUL,
  {
    display: none;
  }
  /* hide it elsewhere */
}

@media screen and (min-width: 866px) and (max-width: 2000px) {
  .tdMobile {
    display: none;
  }
  /* hide it elsewhere */
}

@media screen and (min-width: 0px) and (max-width: 866px) {
  section {
    display: none;
  }
  /* hide it elsewhere */
}


/*TAB CSS*/

* {
  box-sizing: border-box;
}

section {
  position: relative;
  width: 100%;
  margin: 0 auto;
  z-index: 0;
  color: white;
}

section:after {
  content: 'your message goes here';
  position: absolute;
  left: 0;
  top: 45px;
  font-size: 16px;
  text-align: left;
  background-color: #F1F1F1;
  padding: 8px 20px 20px 20px;
  max-width: 100%;
  min-width: 200px;
  min-height: 125px;
  color: black;
}

button {
  cursor: pointer;
  width: 199px;
  display: inline-block;
  background-color: #204393;
  color: white;
  text-align: center;
  transition: .25s ease;
  border: none;
  padding: 10px;
  font-size: 18px;
  margin-bottom: 145px;
}

.divTab:focus button,
button:focus {
  background-color: #EE2725;
  outline: none;
  font-size: 18px;
}

.tabP {
  display: none;
  font-size: 16px;
  padding: 20px 20px 20px 20px;
}

button:focus+.tabP,
.divTab:focus P {
  display: block;
  position: absolute;
  background-color: #F1F1F1;
  width: 100%;
  min-width: 200px;
  min-height: 150px;
  left: 0;
  color: black;
  z-index: 2;
  outline: none;
  top: 29px;
  text-align: left;
  padding-top: 8px;
}

.divTab {
  display: inline-block;
}

.divTab:focus {
  outline: none;
}

table {
  border: 1px solid #ccc;
  border-collapse: collapse;
  margin: 0;
  padding: 0;
  width: 100%;
  table-layout: fixed;
}

table caption {
  font-size: 1.5em;
  margin: .5em 0 .75em;
}

table tr {
  background: #f8f8f8;
  padding: 0px;
}

table th,
table td {
  padding: 10px;
  text-align: center;
}

table th {
  font-size: .85em;
  letter-spacing: .1em;
  text-transform: uppercase;
  background: #204393;
  color: white;
}

@media screen and (max-width: 600px) {
  table {
    border: 0;
  }
  table caption {
    font-size: 1.3em;
  }
  table thead {
    border: none;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
  }
  table tr {
    border-bottom: 3px solid #ddd;
    display: block;
    margin-bottom: 15px;
  }
  table td {
    border-bottom: 1px solid #ddd;
    display: block;
    font-size: .8em;
    text-align: right;
  }
  table td:before {
    /*
                    * aria-label has no advantage, it won't be read inside a table
                    content: attr(aria-label);
                    */
    content: attr(data-label);
    float: left;
    font-weight: bold;
    text-transform: uppercase;
  }
  table td:last-child {
    border-bottom: 0;
  }
}
代码语言:javascript
复制
<div class="wrapper">
  <div class="header">

    <a href="http://" target="_blank"><img class="logo" alt="Store" title="Store" src="http://placehold.it/350x150?text=Logo" /></a>

    <div class="header-right">
      <a href="tel:0000000000"><img class="call-us" alt="Call Us" title="Call Us" src="http://placehold.it/100x30?text=Call+Us" /></a>
      <a href="http://" target="_blank"><img class="cartImg" alt="Cart Image" title="CartImg" src="http://placehold.it/40x40?text=Cart" /></a>
    </div>

  </div>

  <hr>
  <div class="main">
    <hr>
    <h1>{{ title }}</h1>

    <hr>
    <center><img class="prod-img" src="http://placehold.it/100x100?text=Product+Image" width="20%" /></center>
    <hr>

    <p>{{ description }}</p>

    <ul>
      <li>CONTENT GOES HERE</li>
    </ul>

    <table>
      <tbody>
        <caption>Specification</caption>
        <thead>
          <tr>
            <th scope="col">Model</th>
            <th scope="col">Size</th>
            <th scope="col">Weight</th>
            <th scope="col">Platform Height</th>
            <th scope="col">Overall Height</th>
            <th scope="col">Width</th>
          </tr>
        </thead>
      </tbody>
      <tbody>
        <tr>
          <td data-label="Model">CONTENT GOES HERE</td>
          <td data-label="Size">CONTENT GOES HERE</td>
          <td data-label="Weight">CONTENT GOES HERE</td>
          <td data-label="Platform Height">CONTENT GOES HERE</td>
          <td data-label="Overall Height">CONTENT GOES HERE</td>
          <td data-label="Width">CONTENT GOES HERE</td>
        </tr>

      </tbody>
    </table>

    <br>

    <!--Footer tabs for selecting payment, delivery, returns and warranty.-->
    <section>
      <div class="divTab">
        <button>Payment</button>
        <p class="tabP">CONTENT GOES HERE.</p>
      </div>
      <div class="divTab">
        <button>Delivery</button>
        <p class="tabP">CONTENT GOES HERE.</p>

      </div>
      <div class="divTab">
        <button>Returns</button>
        <p class="tabP">CONTENT GOES HERE.</p>
      </div>
      <div class="divTab">
        <button>Warranty</button>
        <p class="tabP">CONTENT GOES HERE.</p>
      </div>
    </section>


    <!--Footer tabs for Mobile application compatibility. selecting payment, delivery, returns and warranty.-->
    <table style="width:100%; text-align:center;">

      <tr>
        <td class="bottomTabs">Payment</td>
      </tr>
      <tr>
        <td class="tdMobile" style="text-align: left;">
          <p>CONTENT GOES HERE.</p>
        </td>
      </tr>

      <tr>
        <td class="bottomTabs">Delivery</td>
      </tr>
      <tr>
        <td class="tdMobile" style="text-align: left;">
          <p>CONTENT GOES HERE.</p>
          <ul class="bottomTabsUL">
            <li>CONTENT GOES HERE.</li>
            <li>CONTENT GOES HERE.</li>
          </ul>
        </td>
      </tr>

      <tr>
        <td class="bottomTabs">Returns</td>
      </tr>
      <tr>
        <td class="tdMobile" style="text-align: left;">
          <p>CONTENT GOES HERE.</p>
      </tr>

      <tr>
        <td class="bottomTabs">Warranty</td>
      </tr>
      <tr>
        <td class="tdMobile" style="text-align: left;">
          <p>CONTENT GOES HERE.</p>
        </td>
      </tr>
    </table>
  </div>
</div>

The Issue

好的,所以我决定测试并取出部分,并注意到这个表导致了这个问题。但是,我不明白的是,我在样式表中设置了表属性,使其与响应web兼容。

代码语言:javascript
复制
<table>
      <tbody>
        <caption>Specification</caption>
        <thead>
          <tr>
            <th scope="col">Model</th>
            <th scope="col">Size</th>
            <th scope="col">Weight</th>
            <th scope="col">Platform Height</th>
            <th scope="col">Overall Height</th>
            <th scope="col">Width</th>
          </tr>
        </thead>
      </tbody>
      <tbody>
        <tr>
          <td data-label="Model">CONTENT GOES HERE</td>
          <td data-label="Size">CONTENT GOES HERE</td>
          <td data-label="Weight">CONTENT GOES HERE</td>
          <td data-label="Platform Height">CONTENT GOES HERE</td>
          <td data-label="Overall Height">CONTENT GOES HERE</td>
          <td data-label="Width">CONTENT GOES HERE</td>
        </tr>

      </tbody>
    </table>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-22 11:05:49

这是因为桌子的缘故。它不能再收缩了

你有几个解决方案

  1. 减少td字体大小(但如果您有许多列,这是行不通的)
  2. 您可以将表包装在div内,给出div溢出卷轴和最大宽度100 to (可以选择在移动上显示文本:“向右滚动或旋转设备以查看完整的表”)

请参阅下面的解决方案2或小提琴片段

让我知道它是否有效:D干杯

代码语言:javascript
复制
body {
  background-color: #f1f1f1;
}

.wrapper {
  margin: 0 auto;
  padding: 0 20px 20px 20px;
  max-width: 1080px;
  min-width: 200px;
  background-color: #ffffff;
  height: 100%;
}

.header {
  width: 100%;
  height: 100px;
}

.header-right {
  float: right;
  height: 15px;
  padding: 24px 40px 20px 5px;
  margin-bottom: 30px;
}

.logo {
  float: left;
  display: block;
  max-width: 100%;
  max-height: 100%;
  border: 0;
}

.call-us {
  padding-right: 20px;
  max-width: 100%;
}
.tablewrapper { max-width:100vw;overflow-y:scroll}

@media only screen and (min-width: 768px) {
h3.showOnMobile { display:none;}
}
代码语言:javascript
复制
<div class="wrapper">
  <div class="header">

    <a href="http://" target="_blank"><img class="logo" alt="Store" title="Store" src="http://placehold.it/350x150?text=Logo" /></a>

    <div class="header-right">
      <a href="tel:0000000000"><img class="call-us" alt="Call Us" title="Call Us" src="http://placehold.it/100x30?text=Call+Us" /></a>
      <a href="http://" target="_blank"><img class="cartImg" alt="Cart Image" title="CartImg" src="http://placehold.it/40x40?text=Cart" /></a>
    </div>

  </div>

  <hr>
  <div class="main">
    <hr>
    <h1>{{ title }}</h1>

    <hr>
    <center><img class="prod-img" src="http://placehold.it/100x100?text=Product+Image" width="20%" /></center>
    <hr>

    <p>{{ description }}</p>

    <ul>
      <li>CONTENT GOES HERE</li>
    </ul>
  <div class="tablewrapper">
    <h3 class="showOnMobile">scroll right or rotate your device to see full table</h3>
    <table>
      <tbody>
        <caption>Specification</caption>
        <thead>
          <tr>
            <th scope="col">Model</th>
            <th scope="col">Size</th>
            <th scope="col">Weight</th>
            <th scope="col">Platform Height</th>
            <th scope="col">Overall Height</th>
            <th scope="col">Width</th>
          </tr>
        </thead>
      </tbody>
      <tbody>
        <tr>
          <td data-label="Model">CONTENT GOES HERE</td>
          <td data-label="Size">CONTENT GOES HERE</td>
          <td data-label="Weight">CONTENT GOES HERE</td>
          <td data-label="Platform Height">CONTENT GOES HERE</td>
          <td data-label="Overall Height">CONTENT GOES HERE</td>
          <td data-label="Width">CONTENT GOES HERE</td>
        </tr>

      </tbody>
    </table>
    </div>

    <br>

    <!--Footer tabs for selecting payment, delivery, returns and warranty.-->
    <section>
      <div class="divTab">
        <button>Payment</button>
        <p class="tabP">CONTENT GOES HERE.</p>
      </div>
      <div class="divTab">
        <button>Delivery</button>
        <p class="tabP">CONTENT GOES HERE.</p>

      </div>
      <div class="divTab">
        <button>Returns</button>
        <p class="tabP">CONTENT GOES HERE.</p>
      </div>
      <div class="divTab">
        <button>Warranty</button>
        <p class="tabP">CONTENT GOES HERE.</p>
      </div>
    </section>


    <!--Footer tabs for Mobile application compatibility. selecting payment, delivery, returns and warranty.-->

   
 
    <table style="width:100%; text-align:center;">

      <tr>
        <td class="bottomTabs">Payment</td>
      </tr>
      <tr>
        <td class="tdMobile" style="text-align: left;">
          <p>CONTENT GOES HERE.</p>
        </td>
      </tr>

      <tr>
        <td class="bottomTabs">Delivery</td>
      </tr>
      <tr>
        <td class="tdMobile" style="text-align: left;">
          <p>CONTENT GOES HERE.</p>
          <ul class="bottomTabsUL">
            <li>CONTENT GOES HERE.</li>
            <li>CONTENT GOES HERE.</li>
          </ul>
        </td>
      </tr>

      <tr>
        <td class="bottomTabs">Returns</td>
      </tr>
      <tr>
        <td class="tdMobile" style="text-align: left;">
          <p>CONTENT GOES HERE.</p>
      </tr>

      <tr>
        <td class="bottomTabs">Warranty</td>
      </tr>
      <tr>
        <td class="tdMobile" style="text-align: left;">
          <p>CONTENT GOES HERE.</p>
        </td>
      </tr>
    </table>

  </div>
</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42948372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档