简体   繁体   English

CSS 中的固定列布局

[英]Fixed column layout in CSS

How is this website able to push the content "inward" into the page with no margin.网站如何能够将内容“向内”推入页面而没有边距。 It appears to me as they have a single column fixed layout, but I don't understand how this is done.在我看来,它们具有单列固定布局,但我不明白这是如何完成的。 Perhaps with flexbox?也许用 flexbox?

What's the CSS code that makes the label in the screenshot with such a small width?使屏幕截图中的标签具有如此小的宽度的 CSS 代码是什么? I've added some red arrows to highlight what I mean.我添加了一些红色箭头来突出我的意思。 Basically there seems to be no margin that from the leftmost part of the browser to the label, though there is something that holds the content in the center of the page.基本上,从浏览器的最左侧到标签似乎没有边距,尽管有一些东西可以将内容保存在页面的中心。

在此处输入图片说明

They use a container called widecontainer with the following style他们使用一个名为 widecontainer 的容器,其样式如下

.widecontainer {
   position: relative;
   max-width: 1080px;
   margin: 0 auto;
   padding: 0 20px;
}

This is common practise in websites, I use a margins-container in my websites with the following code这是网站的常见做法,我在我的网站中使用边距容器,代码如下

.margins-container {
    width: 85%;
    max-width: 1244px;
    margin: 0 auto 0 auto;
    @media (max-width: $tablet) {
         margin: 0 auto 20px auto;
     width: 95%;
     }
    &.no-margin {
        margin: 0 auto;
    }
    &.constrained {
        width: 85%;
    }
}

In each new section, they will include the margins container to ensure the website stays within the same constraints, but at the same time is adjustable throughout through styling just one selector.在每个新部分中,它们将包含边距容器以确保网站保持在相同的约束范围内,但同时可以通过样式设置一个选择器进行调整。

Using a margins-container like this will often follow this format使用像这样的边距容器通常会遵循这种格式

<section class="main-content">
  <div class="margins-container">
    // content
  </div>
</section>
<section class="secondary-content">
  <div class="margins-container">
    // secondary content
  </div>
</section>

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

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