Element not following CSS grid

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

Element not following CSS grid

问题

以下是翻译好的部分:

我正在使用网格布局,并希望以下内容位于底部和中心,但它们出现在左侧:

.body {
  margin: 0;
  background-color: rgb(255, 237, 237);
  display: grid;
  grid-template-rows: 10vh 48vh 21vh 21vh;
  grid-template-columns: 98vi;
  color: white;
}

#scrolllabel {
  color: rgb(19, 1, 1);
  grid-row: 3;
  grid-column: 1;
  z-index: 100;
  font-family: Arial;
  place-content: center;
  place-self: center;
  align-self: center;
  font-size: 25px;
  border-width: 0;
}
<h2 id="scrolllabel">Scroll down to know more</h2>
<b id="the_down_arrow">&darr;</b>

但结果是:

Element not following CSS grid

英文:

I'm using gridding and want the following to be bottom and center but they are appearing at the left:

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

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

.body {
  margin: 0;
  background-color: rgb(255, 237, 237);
  display: grid;
  grid-template-rows: 10vh 48vh 21vh 21vh;
  grid-template-columns: 98vi;
  color: white;
}

#scrolllabel {
  color: rgb(19, 1, 1);
  grid-row: 3;
  grid-column: 1;
  z-index: 100;
  font-family: Arial;
  place-content: center;
  place-self: center;
  align-self: center;
  font-size: 25px;
  border-width: 0;
}

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

&lt;h2 id=&quot;scrolllabel&quot;&gt;Scroll down to know more&lt;/h2&gt;
&lt;b id=&quot;the_down_arrow&quot;&gt;&amp;darr;&lt;/b&gt;

<!-- end snippet -->

but the result is:

Element not following CSS grid

答案1

得分: 1

You can use position属性而不是grid

------ HTML---------

<div class="hero-container">
    <div>
        <h2 id="scrolllabel">向下滚动了解更多</h2>
        <b id="the_down_arrow">&darr;</b>
    </div>
</div>

------ Style ------

.hero-container {
    height: 500px; /*根据您的需求*/
    width: 100%;
    background-color: lightskyblue;

    position: relative; /*重要*/
}
.hero-container > div {
    position: absolute; /*重要*/
    bottom: 10px; /*根据您的需求*/

    /*对齐最重要的部分*/
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;

}

尝试将此代码应用到您的应用程序中。

英文:

Element not following CSS gridYou can use position attribute instead of grid.

------ HTML---------

&lt;div class=&quot;hero-container&quot;&gt;
	&lt;div &gt;
		&lt;h2 id=&quot;scrolllabel&quot; &gt;Scroll down to know more&lt;/h2&gt;
		&lt;b id=&quot;the_down_arrow&quot;&gt;&amp;darr;&lt;/b&gt;
	&lt;/div&gt;
&lt;/div&gt;

------ Style ------

.hero-container {
	height: 500px; /*as per your requirement*/
	width: 100%;
	background-color: lightskyblue;

	position: relative; /*Important*/
}
.hero-container &gt; div {
	position: absolute; /*Important*/
	bottom: 10px; /*as per your requirement*/

	/*Most important to align*/
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	width: 100%;

}

Try this code to your app.

答案2

得分: 0

请尝试以下代码。我现在有点忙,所以只分享了代码。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>测试</title>

    <style type="text/css">
        .body {
          margin: 0;
          background-color: rgb(255, 237, 237);
          display: grid;
          grid-template-rows: 10vh 48vh 21vh 21vh;
          grid-template-columns: 98vi;
          color: white;
        }
        .hero-container{
            display: grid;
        }

        #scrolllabel {
          color: rgb(19, 1, 1);
          grid-row: 3;
          grid-column: 1;
          z-index: 100;
          font-family: Arial;
          place-content: center;
          place-self: center;
          align-self: center;
          font-size: 25px;
          border-width: 0;
        }
        #the_down_arrow {
        color: rgb(19, 1, 1);
          grid-row: 4;
          grid-column: 1;
          z-index: 100;
          font-family: Arial;
          place-content: center;
          place-self: center;
          align-self: center;
          font-size: 25px;
          border-width: 0;
        }
    </style>
</head>
<body>
    <div class="hero-container">
        <h2 id="scrolllabel" >向下滚动了解更多</h2>
        <b id="the_down_arrow">&darr;</b>
    </div>
</body>
</html>
英文:

Try this code please. I am little busy now, so I shared code only.

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;meta charset=&quot;utf-8&quot;&gt;
	&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
	&lt;title&gt;Test&lt;/title&gt;

	&lt;style type=&quot;text/css&quot;&gt;
		.body {
		  margin: 0;
		  background-color: rgb(255, 237, 237);
		  display: grid;
		  grid-template-rows: 10vh 48vh 21vh 21vh;
		  grid-template-columns: 98vi;
		  color: white;
		}
		.hero-container{
			display: grid;
		}

		#scrolllabel {
		  color: rgb(19, 1, 1);
		  grid-row: 3;
		  grid-column: 1;
		  z-index: 100;
		  font-family: Arial;
		  place-content: center;
		  place-self: center;
		  align-self: center;
		  font-size: 25px;
		  border-width: 0;
		}
		#the_down_arrow {
		color: rgb(19, 1, 1);
		  grid-row: 4;
		  grid-column: 1;
		  z-index: 100;
		  font-family: Arial;
		  place-content: center;
		  place-self: center;
		  align-self: center;
		  font-size: 25px;
		  border-width: 0;
		}
	&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;div class=&quot;hero-container&quot;&gt;
		&lt;h2 id=&quot;scrolllabel&quot; &gt;Scroll down to know more&lt;/h2&gt;
		&lt;b id=&quot;the_down_arrow&quot;&gt;&amp;darr;&lt;/b&gt;
	&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

答案3

得分: 0

尝试将其放入一个容器并使用 flexbox。

<!DOCTYPE html>
<html>
<head>
  <link href="https://fonts.googleapis.com/css2?family=Nunito&display=swap" rel="stylesheet">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>order</title>
  <style>
    .body {
      margin: 0;
      overflow: hidden;
    }

    .container {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: 100vh;
      background: red;
    }
  </style>
</head>
<body>
  <div class="container">
    <h2 id="scrolllabel">向下滚动以了解更多</h2>
    <b id="the_down_arrow">&darr;</b>
  </div>
</body>
</html>
英文:

Try wrapping it in a container and using flexbox.

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;link href=&quot;https://fonts.googleapis.com/css2?family=Nunito&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;
  &lt;meta charset=&quot;utf-8&quot;&gt;
  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;&gt;
  &lt;title&gt;order&lt;/title&gt;
  &lt;style&gt;
.body {
  margin: 0;
  overflow: hidden;
}

.container {
  display:flex;
  justify-content:center;
  align-items:center;
  width: 100%;
  height: 100vh;
  background: red;
}
  &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;div class=&quot;container&quot;&gt;
  &lt;h2 id=&quot;scrolllabel&quot;&gt;Scroll down to know more&lt;/h2&gt;
  &lt;b id=&quot;the_down_arrow&quot;&gt;&amp;darr;&lt;/b&gt;
  &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

huangapple
  • 本文由 发表于 2023年7月23日 14:24:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76746882.html
匿名

发表评论

匿名网友

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

确定