Element not following CSS grid

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

Element not following CSS grid

问题

以下是翻译好的部分:

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

  1. .body {
  2. margin: 0;
  3. background-color: rgb(255, 237, 237);
  4. display: grid;
  5. grid-template-rows: 10vh 48vh 21vh 21vh;
  6. grid-template-columns: 98vi;
  7. color: white;
  8. }
  9. #scrolllabel {
  10. color: rgb(19, 1, 1);
  11. grid-row: 3;
  12. grid-column: 1;
  13. z-index: 100;
  14. font-family: Arial;
  15. place-content: center;
  16. place-self: center;
  17. align-self: center;
  18. font-size: 25px;
  19. border-width: 0;
  20. }
  1. <h2 id="scrolllabel">Scroll down to know more</h2>
  2. <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 -->

  1. .body {
  2. margin: 0;
  3. background-color: rgb(255, 237, 237);
  4. display: grid;
  5. grid-template-rows: 10vh 48vh 21vh 21vh;
  6. grid-template-columns: 98vi;
  7. color: white;
  8. }
  9. #scrolllabel {
  10. color: rgb(19, 1, 1);
  11. grid-row: 3;
  12. grid-column: 1;
  13. z-index: 100;
  14. font-family: Arial;
  15. place-content: center;
  16. place-self: center;
  17. align-self: center;
  18. font-size: 25px;
  19. border-width: 0;
  20. }

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

  1. &lt;h2 id=&quot;scrolllabel&quot;&gt;Scroll down to know more&lt;/h2&gt;
  2. &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---------

  1. <div class="hero-container">
  2. <div>
  3. <h2 id="scrolllabel">向下滚动了解更多</h2>
  4. <b id="the_down_arrow">&darr;</b>
  5. </div>
  6. </div>

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

  1. .hero-container {
  2. height: 500px; /*根据您的需求*/
  3. width: 100%;
  4. background-color: lightskyblue;
  5. position: relative; /*重要*/
  6. }
  7. .hero-container > div {
  8. position: absolute; /*重要*/
  9. bottom: 10px; /*根据您的需求*/
  10. /*对齐最重要的部分*/
  11. display: flex;
  12. flex-direction: column;
  13. justify-content: center;
  14. align-items: center;
  15. width: 100%;
  16. }

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

英文:

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

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

  1. &lt;div class=&quot;hero-container&quot;&gt;
  2. &lt;div &gt;
  3. &lt;h2 id=&quot;scrolllabel&quot; &gt;Scroll down to know more&lt;/h2&gt;
  4. &lt;b id=&quot;the_down_arrow&quot;&gt;&amp;darr;&lt;/b&gt;
  5. &lt;/div&gt;
  6. &lt;/div&gt;

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

  1. .hero-container {
  2. height: 500px; /*as per your requirement*/
  3. width: 100%;
  4. background-color: lightskyblue;
  5. position: relative; /*Important*/
  6. }
  7. .hero-container &gt; div {
  8. position: absolute; /*Important*/
  9. bottom: 10px; /*as per your requirement*/
  10. /*Most important to align*/
  11. display: flex;
  12. flex-direction: column;
  13. justify-content: center;
  14. align-items: center;
  15. width: 100%;
  16. }

Try this code to your app.

答案2

得分: 0

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

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>测试</title>
  7. <style type="text/css">
  8. .body {
  9. margin: 0;
  10. background-color: rgb(255, 237, 237);
  11. display: grid;
  12. grid-template-rows: 10vh 48vh 21vh 21vh;
  13. grid-template-columns: 98vi;
  14. color: white;
  15. }
  16. .hero-container{
  17. display: grid;
  18. }
  19. #scrolllabel {
  20. color: rgb(19, 1, 1);
  21. grid-row: 3;
  22. grid-column: 1;
  23. z-index: 100;
  24. font-family: Arial;
  25. place-content: center;
  26. place-self: center;
  27. align-self: center;
  28. font-size: 25px;
  29. border-width: 0;
  30. }
  31. #the_down_arrow {
  32. color: rgb(19, 1, 1);
  33. grid-row: 4;
  34. grid-column: 1;
  35. z-index: 100;
  36. font-family: Arial;
  37. place-content: center;
  38. place-self: center;
  39. align-self: center;
  40. font-size: 25px;
  41. border-width: 0;
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <div class="hero-container">
  47. <h2 id="scrolllabel" >向下滚动了解更多</h2>
  48. <b id="the_down_arrow">&darr;</b>
  49. </div>
  50. </body>
  51. </html>
英文:

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

  1. &lt;!DOCTYPE html&gt;
  2. &lt;html&gt;
  3. &lt;head&gt;
  4. &lt;meta charset=&quot;utf-8&quot;&gt;
  5. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  6. &lt;title&gt;Test&lt;/title&gt;
  7. &lt;style type=&quot;text/css&quot;&gt;
  8. .body {
  9. margin: 0;
  10. background-color: rgb(255, 237, 237);
  11. display: grid;
  12. grid-template-rows: 10vh 48vh 21vh 21vh;
  13. grid-template-columns: 98vi;
  14. color: white;
  15. }
  16. .hero-container{
  17. display: grid;
  18. }
  19. #scrolllabel {
  20. color: rgb(19, 1, 1);
  21. grid-row: 3;
  22. grid-column: 1;
  23. z-index: 100;
  24. font-family: Arial;
  25. place-content: center;
  26. place-self: center;
  27. align-self: center;
  28. font-size: 25px;
  29. border-width: 0;
  30. }
  31. #the_down_arrow {
  32. color: rgb(19, 1, 1);
  33. grid-row: 4;
  34. grid-column: 1;
  35. z-index: 100;
  36. font-family: Arial;
  37. place-content: center;
  38. place-self: center;
  39. align-self: center;
  40. font-size: 25px;
  41. border-width: 0;
  42. }
  43. &lt;/style&gt;
  44. &lt;/head&gt;
  45. &lt;body&gt;
  46. &lt;div class=&quot;hero-container&quot;&gt;
  47. &lt;h2 id=&quot;scrolllabel&quot; &gt;Scroll down to know more&lt;/h2&gt;
  48. &lt;b id=&quot;the_down_arrow&quot;&gt;&amp;darr;&lt;/b&gt;
  49. &lt;/div&gt;
  50. &lt;/body&gt;
  51. &lt;/html&gt;

答案3

得分: 0

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

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link href="https://fonts.googleapis.com/css2?family=Nunito&display=swap" rel="stylesheet">
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <title>order</title>
  8. <style>
  9. .body {
  10. margin: 0;
  11. overflow: hidden;
  12. }
  13. .container {
  14. display: flex;
  15. justify-content: center;
  16. align-items: center;
  17. width: 100%;
  18. height: 100vh;
  19. background: red;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div class="container">
  25. <h2 id="scrolllabel">向下滚动以了解更多</h2>
  26. <b id="the_down_arrow">&darr;</b>
  27. </div>
  28. </body>
  29. </html>
英文:

Try wrapping it in a container and using flexbox.

  1. &lt;!DOCTYPE html&gt;
  2. &lt;html&gt;
  3. &lt;head&gt;
  4. &lt;link href=&quot;https://fonts.googleapis.com/css2?family=Nunito&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;
  5. &lt;meta charset=&quot;utf-8&quot;&gt;
  6. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;&gt;
  7. &lt;title&gt;order&lt;/title&gt;
  8. &lt;style&gt;
  9. .body {
  10. margin: 0;
  11. overflow: hidden;
  12. }
  13. .container {
  14. display:flex;
  15. justify-content:center;
  16. align-items:center;
  17. width: 100%;
  18. height: 100vh;
  19. background: red;
  20. }
  21. &lt;/style&gt;
  22. &lt;/head&gt;
  23. &lt;body&gt;
  24. &lt;div class=&quot;container&quot;&gt;
  25. &lt;h2 id=&quot;scrolllabel&quot;&gt;Scroll down to know more&lt;/h2&gt;
  26. &lt;b id=&quot;the_down_arrow&quot;&gt;&amp;darr;&lt;/b&gt;
  27. &lt;/div&gt;
  28. &lt;/body&gt;
  29. &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:

确定