【问题标题】:Can you stretch the CSS grid to fill the width of the screen?你可以拉伸 CSS 网格来填充屏幕的宽度吗?
【发布时间】:2022-02-06 23:14:52
【问题描述】:

我想将网格拉伸成下面图片中附加的第二张图片(对不起,我不能直接发布,我没有足够的积分直接发布图片)

我的代码:

.container {  
    display: grid;
    grid-template-columns: 0.5fr 2.4fr 1.3fr 1fr;
    grid-template-rows: 1fr 1fr 1fr [F] 1fr;
    /* gap: 1px 0px; */
    grid-auto-flow: row;
    grid-template-areas:
      "One oneTitle oneDescrip Picture"
      "Two twoTitle twoDescrip Picture"
      "Three threeTitle threeDescrip Picture"
      "Four fourTitle fourDescrip Picture";
  }
  
  .One { grid-area: One; }
  
  .Two { grid-area: Two;  }
  
  .Three { grid-area: Three; }
  
  .Four { grid-area: Four; }
  
  .oneTitle { grid-area: oneTitle;  }
  
  .twoTitle { grid-area: twoTitle; }
  
  .threeTitle { grid-area: threeTitle; }
  
  .fourTitle { grid-area: fourTitle; }
  
  .oneDescrip { grid-area: oneDescrip; }
  
  .twoDescrip { grid-area: twoDescrip; }
  
  .threeDescrip { grid-area: threeDescrip; }
  
  .fourDescrip { grid-area: fourDescrip; }
  
  .Picture { grid-area: Picture; }
  
  .One,.Two,.Three,.Four {
      font-size: 60px;
      color: lightgray;

  }

  .oneTitle, .twoTitle, .threeTitle, .fourTitle, .oneDescrip, .twoDescrip, .threeDescrip, .fourDescrip {
    /* padding-top: 35px; */
    color: black;
    padding-right: 30px;
    padding-left: 20px;
  }

  
  .oneTitle, .twoTitle, .threeTitle, .fourTitle {
    font-weight: bold;
    padding-top: 17px;
    font-size: 25px;
  }
<div class="container">
      <div class="One">1</div>
      <hr>
      <div class="Two">2</div>
      <div class="Three">3</div>
      <div class="Four">4</div>
      <div class="oneTitle">Connect your Crowds</div>
      <div class="twoTitle">Gamify the Experience</div>
      <div class="threeTitle">Engage with Business Growth</div>
      <div class="fourTitle">Continuous Interaction</div>
      <div class="oneDescrip">Descript</div>
      <div class="twoDescrip">Descript</div>
      <div class="threeDescrip">whehwehahha</div>
      <div class="fourDescrip">Descriptjwsenwejwje</div>
      <div class="Picture"><img id="block3img" src="https://i.imgur.com/PEbCBjt.png")></div>
      </div>

它的样子:

我想要它的样子:

【问题讨论】:

  • "你能拉伸...网格来填充屏幕的宽度吗?" - 显然,是的;当你尝试时,你在哪里卡住了?你自己尝试了什么,出了什么问题? something 出错的事实表明您对正在使用的布局存在误解,或者对我们很可能非常乐意提供帮助的 CSS 的某些方面存在误解。

标签: html css css-grid


【解决方案1】:

.container 规则集中进行此声明。 width: 100%;

【讨论】:

  • @WillCrawford 试试这个 width: fit-content。它可能不起作用,因为它适合所有东西..
  • 感谢您的回复! width: 100% 无法单独运行,但 min-width: 100% 运行良好。
猜你喜欢
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-22
  • 1970-01-01
  • 2018-04-25
相关资源
最近更新 更多