CSS:在页面中央对齐手风琴 [英] CSS: align accordion in the center of the page

查看:95
本文介绍了CSS:在页面中央对齐手风琴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天的问题:我如何在页面的正中央垂直对齐*#@ $¤<ç〜&#手风琴(垂直和水平对齐)?
这是 jsFiddle

Today's question : how do i vertically align that *#@$¤<ç~&# accordion in the very center of my page (align it vertically & horizontally)? here's the jsFiddle

推荐答案

尝试:

myUl = $("ul");
myUl.css('position', 'absolute');
myUl.css('top', $(window).height() / 2 - myUl.height() / 2);  
myUl.css('left', $(window).width() / 2 - myUl.width() / 2);  

结果: http://jsfiddle.net/z6Zyj/2/

Result: http://jsfiddle.net/z6Zyj/2/.

如果仅需要CSS解决方案,您必须执行以下操作:

If you want a CSS only solution, you must do something as:

ul {
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -45px;
    margin-left: -295px;
}

其中 45px 是手风琴的高度大约一半, 245px 的宽度是它的一半。

Where 45px is approximately half the height of your accordion and 245px is half the width of it.

结果: http:// jsfiddle。 net / z6Zyj / 3 /

Result: http://jsfiddle.net/z6Zyj/3/.

这篇关于CSS:在页面中央对齐手风琴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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