“Div not taking height mentioned in the css” 的中文翻译是:CSS中未采用div的高度。

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

Div not taking height mentioned in the css

问题

我对HTML和CSS很新,并且我在练习flexbox布局以将多个div居中。但我觉得这里有些问题。

“Div not taking height mentioned in the css” 的中文翻译是:CSS中未采用div的高度。

这里contains类中的第二个div没有占用任何高度或宽度,也没有背景颜色。但当我通过检查工具应用相同的属性时,它按预期工作。

我期望这两个div都应该有50px的高度和宽度,并且背景颜色为红色。

  1. .contains {
  2. height: 100%;
  3. width: 100%;
  4. display: flex;
  5. align-items: center;
  6. justify-content: center;
  7. }
  8. .div1 {
  9. height: 50px;
  10. width: 50px;
  11. background-color: red;
  12. }
  1. <div class="contains">
  2. <div class="div1">1</div>
  3. <div clsss="div1">2</div>
  4. </div>
英文:

I am new to HTML and CSS and I was practicing flexbox layout to center multiple divs. but I think there's something wrong here.

“Div not taking height mentioned in the css” 的中文翻译是:CSS中未采用div的高度。

Here the second div inside the contains class is not taking any height or width and background color. But when I apply these same properties via inspect tool. It works as expected.

I was expecting that both the divs should have height and width of 50px and background color red.

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

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

  1. .contains {
  2. height: 100%;
  3. width: 100%;
  4. display: flex;
  5. align-items: center;
  6. justify-content: center;
  7. }
  8. .div1 {
  9. height: 50px;
  10. width: 50px;
  11. background-color: red;
  12. }

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

  1. &lt;div class=&quot;contains&quot;&gt;
  2. &lt;div class=&quot;div1&quot;&gt;1&lt;/div&gt;
  3. &lt;div clsss=&quot;div1&quot;&gt;2&lt;/div&gt;
  4. &lt;/div&gt;

<!-- end snippet -->

答案1

得分: 2

你的HTML中有个拼写错误:你写成了 clsss 而不是第二个 div 元素的 class

修复这个拼写错误会得到预期的结果:

  1. <!-- begin snippet: js hide: false console: true babel: false -->
  2. <!-- language: lang-css -->
  3. .contains {
  4. height: 100%;
  5. width: 100%;
  6. display: flex;
  7. align-items: center;
  8. justify-content: center;
  9. }
  10. .div1 {
  11. height: 50px;
  12. width: 50px;
  13. background-color: red;
  14. }
  15. <!-- language: lang-html -->
  16. <div class="contains">
  17. <div class="div1">1</div>
  18. <div class="div1">2</div>
  19. </div>
  20. <!-- end snippet -->

请注意,我只翻译了你提供的内容,不包括代码部分。

英文:

There is typo in your html: you wrote clsss instead of class for the second div.

Fixing this typo gives the intended result:

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

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

  1. .contains{
  2. height: 100%;
  3. width: 100%;
  4. display: flex;
  5. align-items: center;
  6. justify-content: center;
  7. }
  8. .div1{
  9. height: 50px;
  10. width: 50px;
  11. background-color: red;
  12. }

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

  1. &lt;div class=&quot;contains&quot;&gt;
  2. &lt;div class=&quot;div1&quot;&gt;1&lt;/div&gt;
  3. &lt;div class=&quot;div1&quot;&gt;2&lt;/div&gt;
  4. &lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月11日 00:24:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76220677.html
匿名

发表评论

匿名网友

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

确定