CSS: align accordion in the center of the page

2019-09-02 11:19发布

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

标签: css accordion
2条回答
时光不老,我们不散
2楼-- · 2019-09-02 11:56

I just wrapped the whole accordion div in a 1x1 table and center aligned the table. Make the table width the same as the accordion width.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-09-02 12:01

Try:

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

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

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;
}

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

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

查看更多
登录 后发表回答