html - css 中的百分比宽度不起作用

标签 html css width viewport percentage

我使用一种方法通过视口(viewport)测量在 css 中定义我的宽度属性,css 代码:

#content {
    position: absolute;
    background-color: white;
    width: 100vw;
    top: 115px;
    bottom: 30px;
    display: table;
    z-index: 0;
}

当我改变宽度时 width: 100vw;宽度:100%;我的代码不再工作了。我想更改为百分比测量,因为我发现视口(viewport)在 Android < 4.4

上不起作用

其他相关的HTML和css代码:

HTML

  <div id="mainslide"> 
    <section id="aanbod"> 
      <div id="content" align="center">
        <table class="tablestyleorchideeaanbod">
          <tr>
            <td class="titel" width="85%">Orchidee</td>
            <td class="beschrijving" width="15%" rowspan="1" align="right">21 aug</td>
          </tr>
          <tr>
            <td class="soort">Cherry red</td>
            <td width="15%" rowspan="2" align="right"><svg height="30" width="30">
              <circle cx="15" cy="15" r="12" fill="#ff4641" />
              </svg></td>
          </tr>
          <tr>
            <td class="beschrijving"><span class="width">Aantal: 100 stuks</span>Grootte: 3 Liter</td>
          </tr>
        </table>
      </div>
    </section>

    <section>
    ..............
    </section>

    <section>
    ..............
    </section>
  </div>

CSS

#mainslide {
    position: absolute;
    left: 100%;
    z-index: 1;
}
#aanbod {
    position: absolute;
    left: 0px;
}
.tablestyleorchideeaanbod {
    width: 100%;
    padding: 12px;
    padding-left: 8%;
    padding-right: 8%;
    border-bottom-width: 1px;
    border-top-width: 0px;
    border-left-width: 0px;
    border-right-width: 0px;
    border-style: solid;
    border-color: #8cca49;
}

最佳答案

使位置 relative 而不是 absolute ,然后 width:100% 应该可以工作

#mainslide {
    position: relative;
    left:100%
    z-index: 1;
}
#aanbod {
    position: relative;
    left: 0px;
}
.tablestyleorchideeaanbod {
    width: 100%;
    padding: 12px;
    padding-left: 8%;
    padding-right: 8%;
    border-bottom-width: 1px;
    border-top-width: 0px;
    border-left-width: 0px;
    border-right-width: 0px;
    border-style: solid;
    border-color: #8cca49;
}
#content {
    position: absolute;
    background-color: white;
    width: 100%;
    top: 115px;
    bottom: 30px;
    display: table;
    z-index: 0;
}

工作示例:http://jsfiddle.net/duvx5qLp/

如果您正在寻找其他东西,请告诉我:)

关于html - css 中的百分比宽度不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28559305/

相关文章:

python - 如何以像素为单位设置 Tkinter Entry 小部件的宽度?

html - 嵌套列表中的反重置问题

javascript - 使用 JavaScript 将 svg 导出为 png 或其他具有样式的图像

javascript - 在选择框中快速选择整个 optgroup 的简便方法

iphone - 如何编写类似于 iPhone UI 的 HTML?

css - 在 IE 中使用 Angular Material 在 div 外部流动的文本

html - 水平滚动条不适应 css 样式的宽度?

html - 在内容框剩余宽度中输入标签

javascript - 将JS文件放在网页底部是否实用?

html - Bootstrap 阴影不适用于网格系统