grid-template-column 未显示出来

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

grid-template-column not showing up

问题

Sure, here's the translated portion of your text:

为什么我的网格列不起作用?我正在制作这个圣诞匹配游戏项目,我正在尝试使用网格模板列来制作其他卡片列,但其他的3列没有显示出来。它们应该显示在“Time: 100”的旁边,但却没有显示出来。我已经检查了拼写和一切,但什么都不起作用。我漏掉了什么?

英文:

Why isn't my grid column working? I'm making this Christmas matching game project and I am trying to make the other card columns using grid template columns but the other 3 columns aren't showing up. They should show up right next to "Time: 100" but aren't. I've checked my spelling and everything yet nothing is working. What am I missing?

<!DOCTYPE html>
<html lang="en">
<head>
<link href="style.css" rel="stylesheet">
<title>Santa's Matching Game</title>

</head>
<body>

    <h1 class="page-title">Santa's Matching Game</h1>
    <!-- Game Stuff Besides Cards -->
    <div class="game-container">
        <div class="game-info-container">
            <div class="game-info">
                Time: <span id="time-remaining">100</span>
            </div>
            <div class="game-info">
                Flips: <span id="flips">0</span>
            </div>
    <!-- Cards -->
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>
            <div class="card"></div>

        </div>
    </div>

</body>  

</html>
@font-face {
    font-family: "Dancing-Bold";
    src: url("Assets/Fonts/Dancing-Bold.ttf") format('truetype');

}


@font-face {
    font-family: "MofC-Bold";
    src: url("Assets/Fonts/MofC-Bold.ttf") format('truetype');

}


* {
    box-sizing: border-box;
}


html {
    min-height: 100vh;
}

body {
    margin: 0;
    background: radial-gradient(#f2f3f8,#58b69b);
}

.page-title {
    color:aliceblue;
    font-family: MofC-Bold, serif;
    font-weight: normal;
    text-align: center;
    font-size: 6em;
}

.game-info {
    color: aliceblue;
    font-size: 4em;
    font-family: Dancing-Bold, serif;
}

.game-container {
    display: grid;
    grid-template-columns: repeat(4, auto);
    grid-gap: 10px;
}

.card {
    background-color: #d33943;
    height: 175px;
    width: 125px;
}

Hopefully I did this right, I've never used Stack overflow before.

答案1

得分: 1

Grid与子元素配合使用,目前您的网格只有一个子元素game-info-container,请移除该元素,网格将正常工作。

<h1 class="page-title">Santa's Matching Game</h1>
<!-- 游戏信息除了卡片之外的内容 -->
<div class="game-container">
  <div class="game-info">
    时间: <span id="time-remaining">100</span>
  </div>
  <div class="game-info">
    翻牌数: <span id="flips">0</span>
  </div>
  <!-- 卡片 -->
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
  <div class="card"></div>
</div>

上述代码是要移除的game-info-container元素之后的网格和相关内容。

英文:

Grid works with child elements, currently your gird only has one child wich is game-info-container, remove that element and the grid will work

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

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

@font-face {
  font-family: &quot;Dancing-Bold&quot;;
  src: url(&quot;Assets/Fonts/Dancing-Bold.ttf&quot;) format(&#39;truetype&#39;);

}


@font-face {
  font-family: &quot;MofC-Bold&quot;;
  src: url(&quot;Assets/Fonts/MofC-Bold.ttf&quot;) format(&#39;truetype&#39;);

}


* {
  box-sizing: border-box;
}


html {
  min-height: 100vh;
}

body {
  margin: 0;
  background: radial-gradient(#f2f3f8, #58b69b);
}

.page-title {
  color: aliceblue;
  font-family: MofC-Bold, serif;
  font-weight: normal;
  text-align: center;
  font-size: 6em;
}

.game-info {
  color: aliceblue;
  font-size: 4em;
  font-family: Dancing-Bold, serif;
}

.game-container {
  display: grid;
  grid-template-columns: repeat(4, auto);
  grid-gap: 10px;
}

.card {
  background-color: #d33943;
  height: 175px;
  width: 125px;
}

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

&lt;h1 class=&quot;page-title&quot;&gt;Santa&#39;s Matching Game&lt;/h1&gt;
&lt;!-- Game Stuff Besides Cards --&gt;
&lt;div class=&quot;game-container&quot;&gt;
  &lt;div class=&quot;game-info&quot;&gt;
    Time: &lt;span id=&quot;time-remaining&quot;&gt;100&lt;/span&gt;
  &lt;/div&gt;
  &lt;div class=&quot;game-info&quot;&gt;
    Flips: &lt;span id=&quot;flips&quot;&gt;0&lt;/span&gt;
  &lt;/div&gt;
  &lt;!-- Cards --&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;card&quot;&gt;&lt;/div&gt;

&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月21日 01:17:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76296470.html
匿名

发表评论

匿名网友

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

确定