html - 在 PX 和百分位之间选择

标签 html css twitter-bootstrap twitter-bootstrap-3

我是 BootStrap 的新手,我有以下问题。

  1. 建议在 bootstrap 中使用 px 和百分位数的方法是什么?
  2. 如果我使用 PX,对网站浏览量会有什么影响吗?

最佳答案

像素单位和百分位数单位之间存在相当大的差异。根据定义,百分位数是基于容器大小的可变维度,而以像素为单位声明的大小将始终占用给定的像素数。

你需要根据你想要完成的事情来选择:

  • 是否需要渲染大小始终为固定像素数?然后选择像素(或另一个固定单位)(这不是响应)
  • 您是否希望呈现的大小根据容器的尺寸而变化?然后选择百分位数

了解差异的最佳方法是对两者进行试验。并更改浏览器窗口的大小。

<div style="width: 80%; border: 2px solid #000; height: 30px">
  <span>80% WIDE DIV</span>
</div>
  
<div style="width: 40%; border: 1px solid #00F; height: 30px; float: left;">
  <span>60% WIDE DIV</span>
</div>
<div style="width: 40%; border: 1px solid #F00; height: 30px; float: left;">
  <span>40% WIDE DIV</span>
</div>  
<div style="clear:both; margin-bottom: 20px;"></div>

<p>FIXED LAYOUT</p>
<div style="width: 300px; border: 2px solid #000; height: 30px">
  <span>300px WIDE DIV</span>
</div>
  
<div style="width: 160px; border: 1px solid #00F; height: 30px; float: left;">
  <span>160px WIDE DIV</span>
</div>
<div style="width: 140px; border: 1px solid #F00; height: 30px; float: left;">
  <span>140px WIDE DIV</span>
</div>  
<div style="clear:both;"></div>

关于html - 在 PX 和百分位之间选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26857270/

相关文章:

javascript - Bootstrap 容器流体 div 的右侧超出页面包装器

javascript - 无法解析目录 'bootstrap'

javascript - 单击按钮显示/隐藏 div

javascript - 从底部滑动一个 <div>

html - 如何使用我的结构显示 slice 中的表格

css - webkit 滤镜渐变

javascript - 如何在 100% 高度 div 中始终将背景图像保持在底部?

jquery - 将图像的一部分变灰

html - 使用 css 在图像上叠加

css - Bootstrap : Resizing background image for mobile