HTML每2篇文章开始新行

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

HTML Start new row every 2 articles

问题

你好,以下是翻译好的部分:

我有这个HTML / CSS代码用于一些卡片,问题是,我需要它们在每两个'article' 区域之后开始新的一行。如何实现这一点?

这导致了一个'articles'或卡片的单行。如何在每两个卡片之后开始新的一行?(文章数量将在短期内增加)

谢谢。

英文:

I have this HTML / CSS code for some cards, thing is, I need them to start a new row every two 'article' regions.
How can achieve this?

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

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

.tiles_bodyLOB {
  display: flex;
  grid-template-columns: auto auto;
  column-gap: 1rem;
  row-gap: 1rem;
  margin-top: 0.25rem;
  @media (max-width: 700px) {
    grid-template-columns: repeat(1, 1fr);
  }
  padding: 1rem;
  border-radius: 8px;
  justify-content: space-between;
}

.tilesLOB {
  display: grid;
  grid-template-columns: auto auto;
  gap: 1rem;
  @media (max-width: 700px) {
    grid-template-columns: repeat(1, 1fr);
  }
}

.tile-styleLOB {
  background-color: red;
  min-height: 200px;
  transition: 0.25s ease;
  &amp;:hover {
    transform: translateY(-5px);
  }
  &amp;:focus-within {
    box-shadow: 0 0 0 2px var(--c-gray-800), 0 0 0 4px var(--c-olive-500);
  }
  min-width: 600px;
}

.a-tag:link {
  color: white;
}

.a-tag:hover {
  color: white;
}

.a-tag:visited {
  color: white;
}

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

&lt;div id=&quot;tile-container&quot;&gt;
  &lt;div class=&quot;tiles_bodyLOB&quot;&gt;
    &lt;article class=&quot;tile-styleLOB&quot;&gt;
      &lt;h1 style=&quot;color: white; font-size: 38px;&quot;&gt;
        &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Some Text ABC&lt;/span&gt;
      &lt;/h1&gt;
      &lt;span style=&quot;color: white; font-size: 24px&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                    Sub Text 1
                 &lt;/span&gt;
      &lt;a href=&quot;#&quot;&gt;
        &lt;div style=&quot;color: white; font-size: 18px; grid-template-columns: 1fr 1fr 1fr&quot;&gt;
          &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Case A: 1 
                       00&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
        &lt;/div&gt;
      &lt;/a&gt;
    &lt;/article&gt;

    &lt;article class=&quot;tile-styleLOB&quot;&gt;
      &lt;h1 style=&quot;color: white; font-size: 38px;&quot;&gt;
        &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Some Text ABC&lt;/span&gt;
      &lt;/h1&gt;
      &lt;span style=&quot;color: white; font-size: 24px&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                    Sub Text 1
                 &lt;/span&gt;
      &lt;a href=&quot;#&quot;&gt;
        &lt;div style=&quot;color: white; font-size: 18px; grid-template-columns: 1fr 1fr 1fr&quot;&gt;
          &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Case A: 1 
                       00&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
        &lt;/div&gt;
      &lt;/a&gt;
    &lt;/article&gt;


    &lt;article class=&quot;tile-styleLOB&quot;&gt;
      &lt;h1 style=&quot;color: white; font-size: 38px;&quot;&gt;
        &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Some Text ABC&lt;/span&gt;
      &lt;/h1&gt;
      &lt;span style=&quot;color: white; font-size: 24px&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                    Sub Text 1
                 &lt;/span&gt;
      &lt;a href=&quot;#&quot;&gt;
        &lt;div style=&quot;color: white; font-size: 18px; grid-template-columns: 1fr 1fr 1fr&quot;&gt;
          &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Case A: 1 
                       00&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
        &lt;/div&gt;
      &lt;/a&gt;
    &lt;/article&gt;

<!-- end snippet -->

This results into a single row of 'articles' or cards.
How can I start a new row every two cards? (the number of articles will increase in the short term)

Thanks

答案1

得分: 1

如果您想根据屏幕宽度包裹文章,则在CSS中向.tiles_bodyLOB添加flex-wrap: wrap;,如下所示:

.tiles_bodyLOB {
    display: flex;
    grid-template-columns: auto auto;
    column-gap: 1rem;
    row-gap: 1rem;
    margin-top: 0.25rem;
    @media (max-width: 700px) {
        grid-template-columns: repeat(1, 1fr);
    }
    padding: 1rem;
    border-radius: 8px;
    justify-content: space-between;
    flex-wrap: wrap;
 }

在片段中的其他内容保持不变。点击片段中的“full page”以查看大屏幕上的包裹效果。

英文:

If you want to wrap the articles based on screen width then add flex-wrap: wrap; to .tiles_bodyLOB in the CSS, like this

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

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

.tiles_bodyLOB {
    display: flex;
    grid-template-columns: auto auto;
    column-gap: 1rem;
    row-gap: 1rem;
    margin-top: 0.25rem;
    @media (max-width: 700px) {
        grid-template-columns: repeat(1, 1fr);
    }
    padding: 1rem;
    border-radius: 8px;
    justify-content: space-between;
	flex-wrap: wrap;
 }

.tilesLOB {
    display: grid;
    grid-template-columns: auto auto;
    gap: 1rem;
    @media (max-width: 700px) {
        grid-template-columns: repeat(1, 1fr);
        }
}

.tile-styleLOB {
 background-color: red;
  min-height: 200px;
  transition: 0.25s ease;
  &amp;:hover {
    transform: translateY(-5px);
    }
  &amp;:focus-within {
    box-shadow: 0 0 0 2px var(--c-gray-800), 0 0 0 4px var(--c-olive-500);
    }
  min-width: 600px;
}

.a-tag:link {color: white;}
.a-tag:hover {color: white;}
.a-tag:visited {color: white;}

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

&lt;div id=&quot;tile-container&quot;&gt;    
   &lt;div class=&quot;tiles_bodyLOB&quot;&gt;
        &lt;article class=&quot;tile-styleLOB&quot;&gt;
           &lt;h1 style=&quot;color: white; font-size: 38px;&quot;&gt;
             &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Some Text ABC&lt;/span&gt;
           &lt;/h1&gt;
             &lt;span style=&quot;color: white; font-size: 24px&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                Sub Text 1
             &lt;/span&gt;
           &lt;a href=&quot;#&quot;&gt;  
               &lt;div style=&quot;color: white; font-size: 18px; grid-template-columns: 1fr 1fr 1fr&quot;&gt;
                   &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Case A: 1 
                   00&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
               &lt;/div&gt;
           &lt;/a&gt;
        &lt;/article&gt;

        &lt;article class=&quot;tile-styleLOB&quot;&gt;
           &lt;h1 style=&quot;color: white; font-size: 38px;&quot;&gt;
             &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Some Text ABC&lt;/span&gt;
           &lt;/h1&gt;
             &lt;span style=&quot;color: white; font-size: 24px&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                Sub Text 1
             &lt;/span&gt;
           &lt;a href=&quot;#&quot;&gt;  
               &lt;div style=&quot;color: white; font-size: 18px; grid-template-columns: 1fr 1fr 1fr&quot;&gt;
                   &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Case A: 1 
                   00&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
               &lt;/div&gt;
           &lt;/a&gt;
        &lt;/article&gt;

        &lt;article class=&quot;tile-styleLOB&quot;&gt;
           &lt;h1 style=&quot;color: white; font-size: 38px;&quot;&gt;
             &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Some Text ABC&lt;/span&gt;
           &lt;/h1&gt;
             &lt;span style=&quot;color: white; font-size: 24px&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                Sub Text 1
             &lt;/span&gt;
           &lt;a href=&quot;#&quot;&gt;  
               &lt;div style=&quot;color: white; font-size: 18px; grid-template-columns: 1fr 1fr 1fr&quot;&gt;
                   &lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Case A: 1 
                   00&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
               &lt;/div&gt;
           &lt;/a&gt;
        &lt;/article&gt;
	&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

Click full page in the snippet to see the warping on large screens.

huangapple
  • 本文由 发表于 2023年6月6日 05:03:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76409994.html
匿名

发表评论

匿名网友

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

确定