javascript - 我怎样才能水平居中这个包含敏感 javascript 的 div?

标签 javascript html css

关于 this webpage如果您向下滚动到第一个内联图像,我会在 javascript slider 发生之前/之后发生。

但是,正常的居中选项似乎对我不起作用并且最终破坏了 slider 。任何帮助将不胜感激。

HTML:

<div class="before_after_slider">
    <div class="photo">
    <div class="after">
    <img src="center_before.jpg" width="1000px" height="600px"  alt="after" />
    </div>
    <div class="before">
    <img src="center_after.jpg" width="1000px" height="600px" alt="before" />
    </div>
    </div>
    </div>
    <div class="caption">
    <p>Roll over the photo with your cursor to see the before/after images. </p>
  </div>

CSS:

.before_after_slider {
    position: relative;
    padding-bottom: 10px;
    width: 55%;
    margin: 0 auto;
  & > * {
    position: relative;
  }
}

.after {
  overflow: hidden;
  position: absolute;
  top: 0px;
  width:1000px;
  height:600px;
}

.caption {
    font-family: helvetica;
    font-weight: 100;
    line-height: 140%;
    letter-spacing: 0px;
    font-size: 13px;
    width: 55%;
    margin: 0 auto;
    padding-top: 0px;
    padding-bottom: 30px;
}

最佳答案

这有很多问题。就像外部容器的宽度小于内部元素一样。 但现在您可以试试这个。

.before_after_slider{
width:1000px;
}

和你的图片一样

关于javascript - 我怎样才能水平居中这个包含敏感 javascript 的 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20414245/

相关文章:

javascript - 使用 .on() 时传递值

javascript - 我可以在 twitter-bootstrap popover 数据内容中使用 html 标签吗?

javascript - 在其外部单击时隐藏 Bootstrap 侧导航栏

html - 如何在同一个地方的所有div上制作图像

javascript - 在CSS中将CSS样式应用于表单项

JavaScript 从数组简单登录

javascript - 为 Google 服务帐户身份验证正确创建 JWT 时遇到问题

javascript - 在组合框中选择项目时将数据放入文本框中

java - 如何防止Jsoup在解析时删除文本内的尖括号

c# - 在 IE8 中,chrome 下拉列表的宽度与下拉框的宽度相同,而在 IE9 中,下拉列表的宽度不同。如何修复?