html - 将宽度设置为 100% 以上后,div 水平向右移动
问题描述
我目前正在一个网站上使用已经编程的滑块。今天我想稍微重构一下页面,当我将滑块的 div 设置为超过 100% 的宽度时,div 一直向右移动......所以 f.ex。120% 中的 20% 被添加到右侧,并且 div 不再放置在页面的中心。
这是正常的吗?如何保持 div 居中?div 的 id 是“之前”。
<style>
.credits {
margin: 20px auto;
text-align: center;
}
#beforeafter {
width: 150%;
max-width: 150%;
margin: 0 auto;
}
/* Plugin CSS */
.twentytwenty-horizontal .twentytwenty-handle:before,
.twentytwenty-horizontal .twentytwenty-handle:after,
.twentytwenty-vertical .twentytwenty-handle:before,
.twentytwenty-vertical .twentytwenty-handle:after {
content: " ";
display: block;
background: white;
position: absolute;
z-index: 30;
-webkit-box-shadow: 0px 0px 12px rgba(51, 51, 51, 0.5);
-moz-box-shadow: 0px 0px 12px rgba(51, 51, 51, 0.5);
box-shadow: 0px 0px 12px rgba(51, 51, 51, 0.5);
}
.twentytwenty-horizontal .twentytwenty-handle:before,
.twentytwenty-horizontal .twentytwenty-handle:after {
width: 3px;
height: 9999px;
left: 50%;
margin-left: -1.5px;
}
.twentytwenty-vertical .twentytwenty-handle:before,
.twentytwenty-vertical .twentytwenty-handle:after {
width: 9999px;
height: 3px;
top: 50%;
margin-top: -1.5px;
}
.twentytwenty-before-label,
.twentytwenty-after-label,
.twentytwenty-overlay {
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.twentytwenty-before-label,
.twentytwenty-after-label,
.twentytwenty-overlay {
-webkit-transition-duration: 0.5s;
-moz-transition-duration: 0.5s;
transition-duration: 0.5s;
}
.twentytwenty-before-label,
.twentytwenty-after-label {
-webkit-transition-property: opacity;
-moz-transition-property: opacity;
transition-property: opacity;
}
.twentytwenty-before-label:before,
.twentytwenty-after-label:before {
color: white;
font-size: 13px;
letter-spacing: 0.1em;
}
.twentytwenty-before-label:before,
.twentytwenty-after-label:before {
position: absolute;
background: rgba(255, 255, 255, 0.2);
line-height: 38px;
padding: 0 20px;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
}
.twentytwenty-horizontal .twentytwenty-before-label:before,
.twentytwenty-horizontal .twentytwenty-after-label:before {
top: 50%;
margin-top: -19px;
}
.twentytwenty-vertical .twentytwenty-before-label:before,
.twentytwenty-vertical .twentytwenty-after-label:before {
left: 50%;
margin-left: -45px;
text-align: center;
width: 90px;
}
.twentytwenty-left-arrow,
.twentytwenty-right-arrow,
.twentytwenty-up-arrow,
.twentytwenty-down-arrow {
width: 0;
height: 0;
border: 6px inset transparent;
position: absolute;
}
.twentytwenty-left-arrow,
.twentytwenty-right-arrow {
top: 50%;
margin-top: -6px;
}
.twentytwenty-up-arrow,
.twentytwenty-down-arrow {
left: 50%;
margin-left: -6px;
}
.twentytwenty-container {
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
z-index: 0;
overflow: hidden;
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
}
.twentytwenty-container img {
max-width: 100%;
position: absolute;
top: 0;
display: block;
}
.twentytwenty-container.active .twentytwenty-overlay,
.twentytwenty-container.active:hover.twentytwenty-overlay {
background: rgba(0, 0, 0, 0);
}
.twentytwenty-container.active .twentytwenty-overlay .twentytwenty-before-label,
.twentytwenty-container.active .twentytwenty-overlay .twentytwenty-after-label,
.twentytwenty-container.active:hover.twentytwenty-overlay .twentytwenty-before-label,
.twentytwenty-container.active:hover.twentytwenty-overlay .twentytwenty-after-label {
opacity: 0;
}
.twentytwenty-container * {
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
.twentytwenty-before-label {
opacity: 0;
}
.twentytwenty-horizontal .twentytwenty-before-label:before {
left: 10px;
}
.twentytwenty-horizontal .twentytwenty-after-label:before {
right: 10px;
}
.twentytwenty-vertical .twentytwenty-before-label:before {
top: 10px;
}
.twentytwenty-vertical .twentytwenty-after-label:before {
bottom: 10px;
}
.twentytwenty-overlay {
-webkit-transition-property: background;
-moz-transition-property: background;
transition-property: background;
background: rgba(0, 0, 0, 0);
z-index: 25;
}
.twentytwenty-overlay:hover {
background: rgba(0, 0, 0, 0.5);
}
.twentytwenty-overlay:hover .twentytwenty-after-label {
opacity: 1;
}
.twentytwenty-overlay:hover .twentytwenty-before-label {
opacity: 1;
}
.twentytwenty-before {
z-index: 20;
}
.twentytwenty-after {
z-index: 10;
}
.twentytwenty-handle {
height: 38px;
width: 38px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -22px;
margin-top: -22px;
border: 3px solid white;
-webkit-border-radius: 1000px;
-moz-border-radius: 1000px;
border-radius: 1000px;
-webkit-box-shadow: 0px 0px 12px rgba(51, 51, 51, 0.5);
-moz-box-shadow: 0px 0px 12px rgba(51, 51, 51, 0.5);
box-shadow: 0px 0px 12px rgba(51, 51, 51, 0.5);
z-index: 40;
cursor: pointer;
}
.twentytwenty-horizontal .twentytwenty-handle:before {
bottom: 50%;
margin-bottom: 22px;
-webkit-box-shadow: 0 3px 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
-moz-box-shadow: 0 3px 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
box-shadow: 0 3px 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
}
.twentytwenty-horizontal .twentytwenty-handle:after {
top: 50%;
margin-top: 22px;
-webkit-box-shadow: 0 -3px 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
-moz-box-shadow: 0 -3px 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
box-shadow: 0 -3px 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
}
.twentytwenty-vertical .twentytwenty-handle:before {
left: 50%;
margin-left: 22px;
-webkit-box-shadow: 3px 0 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
-moz-box-shadow: 3px 0 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
box-shadow: 3px 0 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
}
.twentytwenty-vertical .twentytwenty-handle:after {
right: 50%;
margin-right: 22px;
-webkit-box-shadow: -3px 0 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
-moz-box-shadow: -3px 0 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
box-shadow: -3px 0 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
}
.twentytwenty-left-arrow {
border-right: 6px solid white;
left: 50%;
margin-left: -17px;
}
.twentytwenty-right-arrow {
border-left: 6px solid white;
right: 50%;
margin-right: -17px;
}
.twentytwenty-up-arrow {
border-bottom: 6px solid white;
top: 50%;
margin-top: -17px;
}
.twentytwenty-down-arrow {
border-top: 6px solid white;
bottom: 50%;
margin-bottom: -17px;
}
</style>
解决方案
您的 HTML 代码在哪里,以便我们为您提供帮助?
推荐阅读
- amazon-web-services - GCP us-central1 区域最接近延迟效率的 AWS 区域是什么?
- snowflake-cloud-data-platform - 将镶木地板文件缓慢加载到雪花
- google-bigquery - 查询 INFORMATION_SCHEMA.JOBS_BY_PROJECT 抛出 dml_stats 错误
- android - 为什么我在尝试在 android studio 中打开新活动时出现错误
- python - 使用当前 RGB 值和亮度计算新的 RGB 值
- sap - Talend - 检索 SAP 表窗口未打开
- swift - Swift ui mac os 小部件滚动列表文本
- javascript - (vue-test-utils) '不能覆盖属性 $route,...'
- java - 在不接触 XML 字符的情况下取消转义 HTML
- ios - iOS:以字节为单位的 UIImage 大小与实际图像大小不同