如何居中“位置:绝对”元件 [英] How to center a "position: absolute" element

查看:198
本文介绍了如何居中“位置:绝对”元件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题为中心的一个元素的属性 position 设置为 absolute
有人知道为什么图片不居中?

I'm having a problem centering an element that has the attribute position set to absolute. Does anyone know why the images are not centered?

<style type="text/css">
body {
    text-align: center;
}

#slideshowWrapper {
    margin-top: 50px;
    text-align:center;
}

ul#slideshow {
    list-style: none;
    position: relative;
    margin: auto;
}

ul#slideshow li {
    position: absolute;
}

ul#slideshow li img {
    border: 1px solid #ccc;
    padding: 4px;
    height: 450px;
}
</style>
<body>
    <div id="slideshowWrapper">
        <ul id="slideshow">
            <li><img src="img/dummy1.JPG" alt="Dummy 1" /></li>
            <li><img src="img/piano_unlicened.JPG" alt="Dummy 2" /></li>
        </ul>
    </div>
</body>


推荐答案

position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;

这篇关于如何居中“位置:绝对”元件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆