<分区>
如果我不使用 javascript 来监听调整大小的事件。有什么方法可以使 div 居中吗?
css 结构包含 3 个状态。正常,900px 以下,550px 以下。 当宽度超过 550px 时。我可以将部分设置为居中。当屏幕小于 550px 时。我使用比例缩小尺寸,然后无法将其设置为居中。
我尝试将位置更改为固定/相对、左/ float /转换原点/translateX/使用 vw/边距/填充... 是不是我必须使用 javascript 来监听窗口调整大小,然后更改该部分的 css 的 left 属性?
我的网站在 http://php-kkhchan.rhcloud.com
CSS:
@media screen and (max-width: 900px) {
.box {
width: 520px;
height: 650px;
}
#tabs {
width:520px ; height: 650px;
position: static;
margin: 0 auto;
padding-top: 1em;
}
}
@media screen and (max-width: 550px) {
#tabs, .box {
transform: scale(0.6,0.6);
left: -14%;
position: relative;
}
}
HTML:
<section id="tabs">
<article class="c_tab box" id="tab0" style="background: #A9D0F5;">
testing
</article>
</section>
你也可以引用下面的jsfuddle JSfuddle