我试图在我的网站上正确使用前/后滑块。我几乎就在那里,但是DIV没有在移动浏览器上正确扩展。它超出了智能手机屏幕的宽度。
Here's a link to the website page I'm working on
大约一半的时间你会看到一个带有前/后滑块的偏振器部分。它在我的桌面浏览器上看起来很好,但在移动设备上它超出了屏幕宽度。我的编码技巧非常弱,所以我可能会在这里遗漏一些简单的东西。
Here's where I got the Before / After code from.
我假设我只需要将一个基本属性插入下面的CSS部分之一?我已经将视口代码添加到头部:
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">div.beforeandafter{ /* main container */
background: white;
display: block;
height: 630x; /* default height of main container */
overflow: hidden;
position: relative;
width: 944px; /* default width of main container */
}
div.before, div.after{ /* before and after DIVs within main container */
height: 100%;
left: 0;
overflow: hidden;
position: absolute;
top: 0;
transition: width 0.4s ease-in-out; /* CSS transition. Actual duration set inside script (options.revealduration) */
width: 100%;
z-index: 100;
}
div.after{
z-index: 1; /* z-index of after div should be smaller than before's */
}
div.drag{ /* main div used for separating and dragging between before and after slides */
background: white;
cursor: col-resize;
display: block;
height: 100%;
left: 100%;
position: absolute;
top: 0;
transition: left 0.4s ease-in-out; /* transition. 0.4s sets duration of drag fade in time */
width: 2px; /* width of drag bar separator */
z-index: 1001;
}
div.drag div.draghandle{ /* handle bar within drag interface */
background: darkred;
background: -moz-radial-gradient(center, ellipse cover, rgba(169,3,41,1) 0%, rgba(143,2,34,1) 44%, rgba(109,0,25,1) 100%);
background: -ms-radial-gradient(center, ellipse cover, rgba(169,3,41,1) 0%,rgba(143,2,34,1) 44%,rgba(109,0,25,1) 100%);
background: -o-radial-gradient(center, ellipse cover, rgba(169,3,41,1) 0%,rgba(143,2,34,1) 44%,rgba(109,0,25,1) 100%);
background: radial-gradient(ellipse at center, rgba(169,3,41,1) 0%,rgba(143,2,34,1) 44%,rgba(109,0,25,1) 100%);
background: rgb(169,3,41);
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(169,3,41,1)), color-stop(44%,rgba(143,2,34,1)), color-stop(100%,rgba(109,0,25,1)));
background: -webkit-radial-gradient(center, ellipse cover, rgba(169,3,41,1) 0%,rgba(143,2,34,1) 44%,rgba(109,0,25,1) 100%);
border-radius: 2px;
box-shadow: 0 0 5px gray;
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a90329', endColorstr='#6d0019',GradientType=1 );
height: 20%; /* height of drag handle */
position: absolute;
text-align: center;
width: 16px; /* width of drag handle */
}
div.before span.caption, div.after span.caption{ /* CSS to syle SPAN caption. Optional */
background: black;
bottom: 10px;
color: white;
display: block;
font: bold 12px Germand;
padding: 5px;
position: absolute;
right: 10px;
width: 90px;
}
div.before span.caption{
left: 10px;
right: auto;
}
div.before span.caption a, div.after span.caption a{
color: lightyellow;
text-decoration: none;
}
最后,这是实际的DIV:
<div class="beforeandafter" id="baf" style="width:944px; height:630px; ">
答案 0 :(得分:1)
您在HTML
中定义了高度和宽度作为内联样式<div class="beforeandafter" id="baf" style="width:944px; height:630px; ">
将其更改为
<div class="beforeandafter" id="baf">
然后在您的CSS文档中,从height: 630px;
移除width: 944px
和div.beforeandafter
并添加padding-bottom: 66.73728814%