html - 当浏览器在 Bootstrap 中调整大小时,隐藏左侧 div 内容中的溢出

标签 html twitter-bootstrap css

我已经阅读了所有 SO 问题并进行了谷歌搜索但无法回答。我有一个 Bootstrap 布局,我需要在浏览器调整内容大小时从两侧(左侧和右侧)隐藏。

  • 如果我使用 overflow-x:hidden 那么它只会从右侧隐藏

  • 如果我给负边距那么布局就会出错

如您在代码中所见。当浏览器仅调整右侧图像大小时隐藏。但我需要从双方隐藏该页面。我只需要 CSS 解决方案。

body {
   overflow-x:hidden;
}
.wrapper {
  width: 1170px;
  margin: 0 auto 0 -585px;
  position:relative; 
  left:50%
}
.left-img {
  width: 600px;
  height: 700px;
 }
.right-img {
  width: 700px;
  height: 600px;
 }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>



<div class="wrapper">
  <div class="col-xs-6">
    <img src="http://www.w3schools.com/w3images/lights.jpg" class="img-responsive left-img">
  </div>
  
  <div class="col-xs-6">
    <img src="http://www.w3schools.com/w3images/lights.jpg" class="img-responsive right-img">
   </div>

</div><!-- end wrapper-->

最佳答案

将它添加到您的包装器中,它将起作用。我不知道这是否是最佳解决方案,但它确实有效,因为它必须溢出左侧屏幕,必须将边距设置为负数(包装宽度的一半)。

Live example

.wrapper {
   width:1270px;
   margin:0 auto 0 -635px; 
   position:relative; 
   left:50% 
}

我认为,在小屏幕上可能会有问题。但是您有一个如何执行此操作的示例,以及您可以通过媒体查询定位的一些特定屏幕。

关于html - 当浏览器在 Bootstrap 中调整大小时,隐藏左侧 div 内容中的溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40701582/

相关文章:

javascript - React Bootstrap 无法呈现

css - 图形图像无法根据主题选择图像

html - 如何使用 flex 在 div 之间放置均匀的空间?

html - 在悬停显示 div 时,从主 div 底部开始定位

javascript - 在 HTML 中将除法写为分数

html - Font Awesome 图标不显示

javascript - 取决于媒体查询的通用参数

javascript - @fontface 页面刷新后无法正确加载

javascript - Bootstrap datetimepicker 日历不可见

Jquery bootstrap select2 插件问题与验证插件