简体   繁体   English

删除CSS中用于移动视图但不用于桌面视图的模板中的填充和边距

[英]Removing padding and margins in template for mobile view but not for desktop view in CSS

I have downloaded a template for designing a website, which contains all HTML files and CSS. 我已经下载了用于设计网站的模板,其中包含所有HTML文件和CSS。 I want to add some custom padding and margins according to my needs for the desktop view. 我想根据我对桌面视图的需求添加一些自定义的填充和边距。 But I don't want those in mobile view because that is not getting responsive. 但是,我不希望这些人处于移动视图中,因为这样无法响应。 The CSS file that came with the template already have @media screen defined. 模板随附的CSS文件已经定义了@media屏幕。 I tried adding 我尝试添加

@media only screen and (max-width: 768px) {
    .row{
        margin:0;
        padding:0;
        }
}

but this does not work in css nor in the HTML file itself. 但这不适用于CSS或HTML文件本身。 How can I remove my forced padding and margins when opened in mobile view for ready made templates? 在移动视图中打开现成的模板时,如何删除强制填充和边距?

Try extending the padding and margin selector to include html , body and * : 尝试扩展padding和margin选择器,使其包含htmlbody*

@media only screen and (max-width: 768px) {
   *, html, body, .row {
      margin-left:0 !important;
      margin-right:0 !important;
      padding-left:0 !important;
      padding-right:0 !important;
   }
}

A common characteristic of browsers is that html and body will automatically insert margin spacing around your page if you do not specifically set it to 0 via CSS. 浏览器的一个共同特征是,如果您没有通过CSS专门将htmlbody设置为0 ,则htmlbody会自动在页面周围插入页边距。

The CSS you provided is quite complex so it's not clear exactly what else is causing the issue, however by adding the above to the bottom of your CSS, this should remove horizontal padding/spacing throughout your page on mobile devices. 您提供的CSS非常复杂,因此尚不清楚到底是什么导致了该问题,但是通过将以上内容添加到CSS底部,这应该可以消除移动设备上整个页面的水平填充/间距。

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

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