简体   繁体   English

如何使宽度超过 100% 的表格居中?

[英]How can I center a table with width more than 100%?

I would like to center a table with more than 100% width on a webpage.我想在网页上将宽度超过 100% 的表格居中。 On my wordpress webpage I have a plugin which is creating a calender table for me automatically.在我的 wordpress 网页上,我有一个自动为我创建日历表的插件。 Unfortunately my theme is limiting the space on my webpage to only a portion of my screen.不幸的是,我的主题将我网页上的空间限制在我屏幕的一部分上。 The rest on the right and left is white space.左右的 rest 是空白。

I am fine with this behavior on the other sides, but the calender table would be more beautiful if the calender table would dynamically adapt to the screen resolution and increase to the whole screen to the right and to the left.我对其他方面的这种行为很好,但是如果日历表能够动态适应屏幕分辨率并向右和向左增加到整个屏幕,那么日历表会更漂亮。 Therefore I think I have to increase the width of the table to more than 100%, because 100% is just as it is now.所以我想我必须把表格的宽度增加到100%以上,因为100%就是现在这样。 Here is the link to my webpage: https://www.greendroid.de/kalender这是我网页的链接: https://www.greendroid.de/kalender

If I use the following code snippet, the calender gets bigger, but is not centered anymore.如果我使用以下代码片段,日历会变大,但不再居中。 The right table columns are not longer visible右表列不再可见

.ics-calendar-month-grid
{
    width:150%;
}

I tried different methods to center the table afterwards again, but no CSS snippet worked for me.之后我尝试了不同的方法使表格居中,但没有 CSS 片段对我有用。 Anyone has an idea how I can adapt the width of the table automatically to the screen size on my webpage?任何人都知道如何使表格的宽度自动适应网页上的屏幕尺寸? Thanks and best regards NKL谢谢和最好的问候 NKL

Since it will grow from the current position you only have to apply negative margin to the half of the amount over 100... so (150-100)/2=25 so appliying -25% margin to the left side will do:由于它将从当前的 position 增长,您只需对超过 100 的金额的一半应用负边距......所以 (150-100)/2=25 所以在左侧应用 -25% 边距即可:

.ics-calendar-month-grid {
    width: 150%;
    margin-left: -25%;
}

It will work.它会起作用的。

Update更新

To make it responsive just add/update your CSS with:要使其响应,只需添加/更新您的 CSS :

.ics-calendar-month-grid {
    width: 150%;
    margin-left: -25%;
}

@media screen and (max-width: 1699px) {
    .ics-calendar-month-grid {
        width: 125%!important; margin-left: -12.5%!important;
    }
}

@media screen and (max-width: 1415px) { 
    .ics-calendar-month-grid {
         width: 110%!important; margin-left: -5%!important;
    }
}

@media screen and (max-width: 1415px) {
    .ics-calendar-month-grid {
         width: 100%!important; margin-left: 0!important;
    }
}

This is an approach that should work... you can add all the steps you need/want just take a look in chrome tools (hit F12) the resolution you have on the top right corner to add a specific step.这是一种应该可行的方法...您可以添加您需要/想要的所有步骤,只需查看 chrome 工具(按 F12)右上角的分辨率即可添加特定步骤。 Note that i've put !important declaration because i played with you website directly with chrome developer tools.请注意,我已经放置了!important声明,因为我直接使用 chrome 开发人员工具与您的网站一起玩。

It's a Wordpress theme that allows the use of full-width elements.这是一个允许使用全角元素的 Wordpress 主题。 So, either you add the class .alignfull to that element/section in the HTML code or (if the block editor lets you) you choose "full width" from the alignment selection menu of that block in the editor.因此,您可以将 class .alignfull添加到 HTML 代码中的该元素/部分,或者(如果块编辑器允许您)从 alignment 选择的块中选择“全宽”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM