html - 我如何水平居中我的 css 幻灯片

标签 html css slideshow centering

我已将 jsfiddle 用于该文件。幻灯片在底部。我试图让它居中,但到目前为止它停留在左边距。 最终结果在这里:https://jsfiddle.net/n6kae2rn/ https://jsfiddle.net/n6kae2rn/embedded/result/

.css-slideshow {
    text-align:center;
    position: relative;
    max-width: 410px;
    height: 730px;
}
.css-slideshow figure {
    margin: 0;
    position: absolute;
}
.css-slideshow figcaption {
    position: absolute;
    top: 0;
    color: #fff;
    background: rgba(0, 0, 0, .3);
    font-size: .8em;
    padding: 8px 12px;
    opacity: 0;
    transition: opacity .5s;
}
.css-slideshow:hover figure figcaption {
    transition: opacity .5s;
    opacity: 1;
}
.css-slideshow figure {
    opacity:0;
}
figure:nth-child(1) {
    animation: xfade 42s 32s infinite;
}
figure:nth-child(2) {
    animation: xfade 48s 24s infinite;
}
figure:nth-child(3) {
    animation: xfade 48s 16s infinite;
}
figure:nth-child(4) {
    animation: xfade 48s 8s infinite;
}
figure:nth-child(5) {
    animation: xfade 48s 0s infinite;
}
@keyframes xfade {
    0% {
        opacity: 1;
    }
    10.5% {
        opacity:1;
    }
    20% {
        opacity: 0;
    }
    98% {
        opacity:0;
    }
    100% {
        opacity:1;
    }
}
div.poster {
    background: url(http://jillun.com/dp-intsmall.jpg) repeat;
    padding: 25px;
}

最佳答案

添加<div class="css-container">在你的 <div class="css-slideshow"> 之上.不要忘记添加另一个 </div>在你的 css 幻灯片之后。

然后更改您的 css 以反射(reflect)这一点:

.css-slideshow {
text-align:center;
position: relative;
max-width: 410px;
height: 730px;
margin: auto;
}
.css-container {
width: 100%;
}

这会在您的页面上创建一个全宽容器元素。然后你的幻灯片 CSS 理解文本对齐元素居中,最后自动填充边距。

希望对您有所帮助。

JSfiddle

关于html - 我如何水平居中我的 css 幻灯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32022397/

相关文章:

javascript - 如何将一个字段向右移动

javascript - 向现有幻灯片添加简单的分页

javascript - 如何减慢 html 中图像幻灯片的播放速度?

css - 默认情况下从父级继承其值的属性列表

css - Bootstrap 中的嵌套行具有交替填充

javascript - 如何过滤 ListView 中的内部子元素以及使用 Jquery 在移动应用程序中将字母滚动条添加到 ListView 的任何简单方法

iphone - Three20 照片滚动替代品?

Internet Explorer 中的 JQuery 无法解析字符串 html

java - HTML 字段 json 编码为深层嵌套对象

html - 用CSS居中div