【问题标题】:CSS - Rows and Columns arrangementCSS - 行和列排列
【发布时间】:2019-10-14 22:11:57
【问题描述】:

我正在创建一个包含新闻的网站,并希望将其设置为 reddit 新闻框。它看起来像下面这样。我使用的是角度材质和 css,所以基本上是纯 HTML 和 CSS,没有引导程序或类似的东西。

_____________________________________
|Column 1  |  Column2 - Area 1        |
|Column 1  |  Column2 - Area 2        |
|Column 1  |  Column2 - Area 2        |
|Column 1  |  Column2 - Area 2        |
|Column 1  |  Column2 - Area 2        |
|Column 1  |  Column2 - Area 2        |
|Column 1  |  Column2 - Area 2        |
|_____________________________________|
|Coulmn 1  |  Column2 - Area 3        |
______________________________________

我使用 display: flex 玩过不同的版本,但不能完全正确地安排它。任何人都可以帮忙吗?

我试过了

<div class="news-container">
  <div class="news-header">
    <div class="news-vote-column">
      <div>
        <mat-icon matSuffix color="accent" class="clickable-icon" (click)="voteUp()">arrow_drop_up</mat-icon>
      </div>
      <div class="vote-number">1</div>
      <div>
        <mat-icon matSuffix color="accent" class="clickable-icon" (click)="voteDown()">arrow_drop_down</mat-icon>
      </div>
    </div>
     <div>
      <h3>I am a new post!</h3>
    </div>
    <div>
      <h5>- Posted by admin - 10/10/2019 12:00</h5>
    </div>
  </div>
</div> 

.news-container {
  margin-bottom: 1em;
  background-color: #f1f2f3;
  border: #7e868d 1px solid;
  border-radius: 5px;
  min-height: 200px;
}

.news-vote-column {
  min-height: 200px;
  min-width: 40px;
  background-color: #d2d3d6;
  border-radius: 5px 0 0 5px;
  text-align: center;
}

.news-header {
  display: flex;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  color: #7e868d;
  h3 {
    margin: 2px 2px 2px 10px;
  }

  h5 {
    color: #cecfd1;
    margin: 5px;
  }
}

.vote-number {
  text-align: center;
  margin: 2px 2px 2px 2px;
}

.clickable-icon {
  cursor: pointer;
} 

【问题讨论】:

  • StackOverflow 不是免费的编码服务。你应该try to solve the problem first。请更新您的问题以在minimal reproducible example 中显示您已经尝试过的内容。如需更多信息,请参阅how to ask, 并拨打tour
  • 我会在这里查看网格,但没有代码,也没有尝试在这里得到你真正的问题:(
  • 我在与我在做什么有关的问题中添加了一些内容。

标签: html css


【解决方案1】:

看看这个解决方案: https://jsfiddle.net/YvanBarbaria/a82ub30p/

我使用弹性框来定位您的 div。快速解决方案,但我认为适合您的需求。您可以使用“col”类轻松地在 div 上循环您的角度模板。

<div class="cols-container">
  <div class="col">
    <div class="col1">
      <span>
        Column
      </span>
      <span>
        1
      </span>
    </div>
    <div class="col2">
        <div class="col2-name">
          <span>
            Column
          </span>
          <span>
            2
          </span>
        </div>
         <div class="col2-area">
          <span>
            Area 1
          </span>
        </div>
    </div>
  </div>
</div>


.cols-container {
  display:flex;
  flex-direction: row;
  width: 100%;
    height: 100%;
  .col {
    display: flex;
    flex-direction: row;
    width: 100%;

    .col1 {
       flex-grow:1;
    }
    .col2 {
       flex-grow:1;
       display: flex;
       .col2-name {
         flex-grow:1;
       }
        .col2-area {
         flex-grow:1;
       }
    }
  }
}

【讨论】:

  • 不幸的是,这会将所有内容放在一行中,这就是我已经发生的事情。
  • 是的,我只为您的设计中的一行生成代码。 |Column 1 | Column2 - Area 1 | 就像我告诉你的那样,你必须循环创建所有其他行。类似的东西`
    `
  • 请给我一个 Stackblitz,我会帮助你。你不是很清楚你想要什么,所以最好的方法是向我展示整个代码。
【解决方案2】:

我终于可以一起摆弄一些东西了:https://jsfiddle.net/dtq1p0w4/

<div class="news-container">
  <div class="news-vote-column">
    <div>
      <mat-icon matSuffix color="accent" class="clickable-icon" (click)="voteUp()">arrow_drop_up</mat-icon>
    </div>
    <div class="vote-number">1</div>
    <div>
      <mat-icon matSuffix color="accent" class="clickable-icon" (click)="voteDown()">arrow_drop_down</mat-icon>
    </div>
  </div>
  <div>
    <div class="news-header">
      <h3>I am a new post!</h3>
      <h5>- Posted by admin - 10/10/2019 12:00</h5>
    </div>
    <div class="news-content">
      I am news content!
    </div>
  </div>
</div>

.news-container {
  margin-bottom: 1em;
  background-color: #f1f2f3;
  border: #7e868d 1px solid;
  border-radius: 5px;
  min-height: 200px;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  display: flex;
}

.news-vote-column {
  min-width: 40px;
  background-color: #d2d3d6;
  border-radius: 5px 0 0 5px;
  text-align: center;
}

.news-header {
  display: flex;
  color: #7e868d;
  h3 {
    margin: 2px 2px 2px 10px;
  }

  h5 {
    color: #cecfd1;
    margin: 5px;
  }
}

.vote-number {
  text-align: center;
  margin: 2px 2px 2px 2px;
}

.clickable-icon {
  cursor: pointer;
}

.news-content {
   margin: 10px;
}

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签