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

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

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的高度和宽度,并且背景颜色为红色。

.contains {
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.div1 {
  height: 50px;
  width: 50px;
  background-color: red;
}
<div class="contains">
  <div class="div1">1</div>
  <div clsss="div1">2</div>
</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 -->

.contains {
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.div1 {
  height: 50px;
  width: 50px;
  background-color: red;
}

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

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

<!-- end snippet -->

答案1

得分: 2

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

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

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

<!-- language: lang-css -->
.contains {
    height: 100%;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.div1 {
    height: 50px;
    width: 50px;
    background-color: red;
}

<!-- language: lang-html -->
<div class="contains">
    <div class="div1">1</div>
    <div class="div1">2</div>
</div>

<!-- 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 -->

.contains{
    height: 100%;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.div1{
    height: 50px;
    width: 50px;
    background-color: red;
}

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

&lt;div class=&quot;contains&quot;&gt;
    &lt;div class=&quot;div1&quot;&gt;1&lt;/div&gt;
    &lt;div class=&quot;div1&quot;&gt;2&lt;/div&gt;
&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:

确定