How can I center align an element that is larger than 100% of the entire page?

情到浓时终转凉″ 提交于 2019-12-05 15:21:53
locrizak

You can do it with CSS:

.row {
    position: absolute;
    top: 0;
    left: 50%;
    margin-left: -1500px; /* half of the width */
    height: 500px;
}

Just make sure the parent has a position: absolute/relative on it

I may not be understanding the root of your issue, but you can set the left and right margins of a container to (the same) negative values. My code is simplified for brevity/clarity.

div.center 
{
    margin:1em -10em; 
    background:#CCC; 
    text-align:center; 
    padding:1em;
}
<div class="center">
    <p>Lorem ipsum dolor sit amet.</p>
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!