@Media滑动侧面板的圣杯布局

发布于 2025-02-10 02:37:21 字数 1577 浏览 1 评论 0原文

这是CSS技巧响应的圣杯起动器 3-column 3-column 3-ROW 3行CSS css grid css grid 我的布局正在尝试适应以下方式:

  • 标头和页脚保持顶部和底部,跨越1行和3列。
  • 在全宽时,左侧栏和右侧栏出现在文章的两侧。
  • 在第一个断点,平板电脑/768px,右侧栏应隐藏并在右侧切换按钮上向左滑动。第二行只显示左侧栏和文章。
  • 在第二个断点,移动/380PX,左侧栏应在LS切换按钮上从左到右滑动。第二行只显示文章。

我意识到这可能是移动优先设计的错误顺序,但是从已知到未知的解释似乎更容易。

在下面的布局中,标头和页脚不是锚定的顶部和底部,并且文章伸展以填充全高度。同样,当然,两个侧面面板都堆叠在断点,而不是根据需要隐藏。我猜@Media查询和/或JS需要执行此操作。

.grid {
  display: grid;
  grid-template-columns: 150px auto 150px;
  grid-gap: 1em;
}

header,
footer {
  grid-column: 1 / 4;
}

@media all and (max-width: 700px) {
  aside,
  article {
    grid-column: 1 / 4;
  }
}


/* Demo Specific Styles */

body {
  margin: 0 auto;
  max-width: 56em;
  padding: 1em 0;
}

header,
aside,
article,
footer {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 25vh;
}

header,
footer {
  background: #bbb;
}

article {
  background: #FEF8DD;
}

.sidebar-left {
  background: #ACDDDE;
}

.sidebar-right {
  background: #CAF1DE;
}
<div class="grid">
  <header>Header</header>
  <aside class="sidebar-left">Left Sidebar</aside>
  <article>Article</article>
  <aside class="sidebar-right">Right Sidebar</aside>
  <footer>Footer</footer>
</div>

Here is a CSS Tricks Responsive Holy Grail starter 3-column 3-row CSS grid layout which I am trying to adapt as follows:

  • The header and footer remain top and bottom spanning 1 row and 3 columns.
  • At fullwidth the left sidebar and right sidebar appear on either side of the article.
  • At the first breakpoint, tablet/768px, the right sidebar should hide and slide right-to-left on right side toggle button. The second row would only show the left sidebar and the article.
  • At the second breakpoint, mobile/380px, the left sidebar should hide and slide left-to-right on ls toggle button. The second row would only show the article.

I realize this is probably in the wrong order for mobile-first design but it seemed easier to explain from known to unknown.

In the layout below, the header and footer are not anchored top and bottom and with Article stretching to fill full height. Also, of course, both side panels stack at breakpoints rather than hide as desired. I'm guessing @media queries and/or JS will be required to do this.

.grid {
  display: grid;
  grid-template-columns: 150px auto 150px;
  grid-gap: 1em;
}

header,
footer {
  grid-column: 1 / 4;
}

@media all and (max-width: 700px) {
  aside,
  article {
    grid-column: 1 / 4;
  }
}


/* Demo Specific Styles */

body {
  margin: 0 auto;
  max-width: 56em;
  padding: 1em 0;
}

header,
aside,
article,
footer {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 25vh;
}

header,
footer {
  background: #bbb;
}

article {
  background: #FEF8DD;
}

.sidebar-left {
  background: #ACDDDE;
}

.sidebar-right {
  background: #CAF1DE;
}
<div class="grid">
  <header>Header</header>
  <aside class="sidebar-left">Left Sidebar</aside>
  <article>Article</article>
  <aside class="sidebar-right">Right Sidebar</aside>
  <footer>Footer</footer>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文