如何安全地编辑这个三列弹性布局

huangapple go评论62阅读模式
英文:

How to safely edit this 3 column flex layout

问题

我需要编辑我在互联网上找到的这个布局,但它是用CSS flex编写的,我对flex一无所知,只懂普通的旧CSS。

如何安全地编辑它,而不损坏代码?

我也创建了一个Codepen
https://codepen.io/familias/pen/WNYQeqQ

我需要的是:
安全地删除左侧边栏,标有文字"This must be deleted",并保留中间部分如下:
<main class="content">Content</main>
100%宽度
<aside class="ads">Aside</aside>
100px宽度

我尝试过,但在移动设备上显示效果不好。

英文:

I need to edit this layout I found on internet but it is in CSS flex and I know nothing about flex, but only normal old css.

How to edit it safely without damaging the code?

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

body {
  margin: 0;
  padding: 0;
  font-size: 30px;
  text-align: center;
}

.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  color: white;
}

.header,
.footer {
  flex: 0 0 50px;
  background: #34495e;
}

.content-body {
  /*   flex: 1 1 auto; */
  flex-grow: 1;
  /* equla to: height: calc(100vh - 100px); */
  display: flex;
  flex-direction: row;
}

.content-body .content {
  /*   flex: 1 1 auto; */
  flex-grow: 1;
  /* width: calc(100% - 200px); */
  overflow: auto;
  background: #1abc9c;
}

.content-body .sidenav,
.content-body .ads {
  flex: 0 0 100px;
  overflow: auto;
}

.content-body .sidenav {
  background: #e74c3c;
}

.content-body .ads {
  background: #e67e22;
}

<!-- language: lang-html -->

&lt;div class=&quot;container&quot;&gt;
  &lt;header class=&quot;header&quot;&gt;Header&lt;/header&gt;
  &lt;div class=&quot;content-body&quot;&gt;
    &lt;nav class=&quot;sidenav&quot;&gt;This must be deleted&lt;/nav&gt;
    &lt;main class=&quot;content&quot;&gt;Content&lt;/main&gt;
    &lt;aside class=&quot;ads&quot;&gt;Aside&lt;/aside&gt;
  &lt;/div&gt;
  &lt;footer class=&quot;footer&quot;&gt;Footer&lt;/footer&gt;
&lt;/div&gt;

<!-- end snippet -->

I also created a Codepen
https://codepen.io/familias/pen/WNYQeqQ

What I need is:
to safely delete the left sidebar, marked with the text "This must be deleted" and leave middle part like this:
&lt;main class=&quot;content&quot;&gt;Content&lt;/main&gt;
100% width
&lt;aside class=&quot;ads&quot;&gt;Aside&lt;/aside&gt;
100px width

I tried myself but it does not displayed good on mobile device

答案1

得分: 0

删除sidenav元素和相关的CSS。属性flex: 0 0 100pxflex-grow设置为0(即不增长),flex-shrink设置为0(即不缩小),并将flex-basis设置为100px,即保持宽度为100px。

这里有一个关于CSS技巧的解释器

Kevin Powell的这个视频是关于flexbox的良好入门教程。

希望这有所帮助。

英文:

Just delete the sidenav element and the associated css. The propoerty flex: 0 0 100px sets the flex-grow to 0 (i.e. don't grow) and flex-shrink to 0 (i.e. don't get smaller, and the flex-basis to 100px, i.e. keep it at 100px wide.

Here's an explainer on CSS tricks

This video by Kevin Powell is a good starter for flexbox.

Hope this helps.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

body {
  margin: 0;
  /*padding: 0; body has no padding by default so removed this*/
  font-size: 30px;
  text-align: center;
}

.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  color: white;
}

.header,
.footer {
  flex: 0 0 50px;
  background: #34495e;
}

.content-body {
  /*   flex: 1 1 auto; */
  flex-grow: 1; /* equla to: height: calc(100vh - 100px); */
  display: flex;
  /*flex-direction: row;  this is default so removed it */
}

.content-body .content {
  /*   flex: 1 1 auto; */
  flex-grow: 1; /* width: calc(100% - 200px); */
  overflow: auto;
  background: #1abc9c;
}

.content-body .ads {
  flex: 0 0 100px;
  overflow: auto;
}

.content-body .ads {
  background: #e67e22;
}

<!-- language: lang-html -->

&lt;div class=&quot;container&quot;&gt;
  &lt;header class=&quot;header&quot;&gt;Header&lt;/header&gt;
  &lt;div class=&quot;content-body&quot;&gt;
    &lt;main class=&quot;content&quot;&gt;Content&lt;/main&gt;
    &lt;aside class=&quot;ads&quot;&gt;Aside&lt;/aside&gt;
  &lt;/div&gt;
  &lt;footer class=&quot;footer&quot;&gt;Footer&lt;/footer&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月13日 00:36:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76458643.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定