简体   繁体   English

Bootstrap-如何确保移动设备最左侧和最右侧的空白

[英]Bootstrap - How to ensure white space on far left and far right on mobile

Can anyone tell me how to ensure I get white space/margin on the left hand side and right hand side when the page is viewed on a mobile phone? 谁能告诉我在手机上查看网页时如何确保左侧和右侧留有空白?

My CSS is: 我的CSS是:

#maxCostSlider {
    max-width:304px;
    width:304px;
    padding:0px;
    margin-left:-6px;
}
@media (max-width: 480px) {
    #maxCostSlider,#sliderScale {
        margin-left: 20px;
        margin-right: 20px;
    }
}

HTML is: HTML是:

<div class="container-fluid">
  <div class="row">
    <div class="col-md-offset-4 col-md-4">
      <img id="sliderScale" src="/assets/img/price slider 1.png" alt="" class="img-responsive" />
    </div>
  </div>
  <div class="row text-center">
    <div class="col-md-offset-4 col-md-4">
      <input id="maxCost" data-slider-id='maxCostSlider' type="text" data-slider-min="0" data-slider-max="100" data-slider-step="10" data-slider-value="40" />
    </div>
  </div>
</div>

This all looks good on a desktop and an iPad but when viewed on an iPhone the bootstrap-slider widget spans the entire width of the device. 这一切在台式机和iPad上看起来都不错,但是在iPhone上查看时,bootstrap-slider小部件会覆盖设备的整个宽度。 I would like to ensure there is always a margin of at least 20px either side of the two rows. 我想确保两行两侧的边距始终至少为20px。 Ideally the bootstrap-slider would scale to fit. 理想情况下,自举滑块可以缩放以适合自己。

Hard to tell without know the exact slider component you are using, but adding this to your CSS should work: 不知道您正在使用的确切滑块组件很难说,但是将其添加到CSS应该可以:

#maxCostSlider {
    margin-left: 20px;
    margin-right: 20px;
}

However if you only want that to happen at mobile width, wrap it in a media query: 但是,如果只希望在移动宽度上发生这种情况,请将其包装在媒体查询中:

@media (max-width: 480px) {
    #maxCostSlider {
        margin-left: 20px;
        margin-right: 20px;
    }
}

For small device(sm) and extra small device (xs) you can call them separately. 对于小型设备(sm)和超小型设备(xs),您可以分别调用它们。

<div class="col-sm-offset-1 col-xs-offset-1 col-md-offset-4 col-md-4"></div>

And another way you can do this by css. 还有另一种方法可以通过CSS执行此操作。

@media (min-width: 240px) and (max-width: 480px) {
  #max-cost {
       padding-left: 20px;
       padding-right: 20px;
      }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何显示以最左侧和最右侧的内容为中心的容器 - How to display container that is centered with content that is in the far left and far right of it 删除最左边和最右边的边框 - Remove border on far left and far right 标题最右侧的空白区域 - Empty space to the far right of header 使用 flexbox,如何对齐最左边的一个元素,最右边的一个元素和最右边的另一个元素? - Using a flexbox, how can I align one element on the far left, one on the far right and another below the far right one? 如何对齐HTML / JavaScript列表最左边的项目和最右边的项目? - How to align items on the far left and items on the far right of a HTML/Javascript list? 如何将一个元素推到最左边,将另一个元素推到最右边,嵌套在同一个容器中? - How can I push one element far left, and the other element far right, nested in the same container? 如何将滑块按钮放置在页面的最左侧和右侧 - How to place the slider button to the far left and right hand side of the page 如何使用 Bootstrap 将导航栏徽标与屏幕的最左侧对齐? - How do I align the navbar logo to the far left of the screen with Bootstrap? 移动视图右侧的 Bootstrap 空白区域 - Bootstrap white space on the right on mobile view 引导程序,无法将导航栏元素移到最左侧 - Bootstrap, cannot move navbar elements to the far left
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM