我想在一个矩形上叠加另一个矩形。

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

I want to overlay a rectangle on top of another rectangle

问题

以下是已经翻译好的部分:

I want to form something like this using CSS and typescript/JavaScript:

我想在一个矩形上叠加另一个矩形。

Can someone please help me understand how to do this?

I tried using a flex container and this is what I have got this:

我想在一个矩形上叠加另一个矩形。

I am new to front end development. Can someone please tell me what I am missing here?

英文:

I want to form something like this using CSS and typescript/JavaScript:

我想在一个矩形上叠加另一个矩形。

Can someone please help me understand how to do this?

I tried using a flex container and this is what I have got this:

我想在一个矩形上叠加另一个矩形。

I am new to front end development. Can someone please tell me what I am missing here?

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

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

.green-area {
  display: flex;
  flex-grow: 1;
  margin-right: @space-sm;
  position: relative;
}

.black-area {
  display: flex;
  flex-grow: 1;
  position: absolute;
  background: #000000;
  height: 20px;
  width: 5%;
}

.height {
  height: @space-sm;
}

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

&lt;div styleName=&quot;green-area&quot;&gt;
  &lt;div style={{ flexGrow: 10, }}&gt;
    &lt;div styleName={`height`}&gt;
      &lt;div styleName=&quot;black-area&quot;&gt;
        &lt;div style={{ flexGrow: 10, }}&gt;
          &lt;div styleName={`height`} /&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 0

就像 isherwood 提到的一样,这是一个HTML/CSS的问题。

  • 你使用了styleName来添加类,这是不正确的。应该使用className
  • 你忽略了black-area的定位。

我使用这个CodeSandbox创建了解决方案。你可以更改内联的style以控制black-area的定位。

英文:

Just like isherwood mentioned, this is an HTML/CSS issue.

  • You've added the class using styleName which is incorrect. It should be className
  • You've missed the positioning for the black-area

I created this CodeSandbox with the answer. You can change the inline style to control the positioning of the black-area

huangapple
  • 本文由 发表于 2023年2月8日 23:44:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75388245.html
匿名

发表评论

匿名网友

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

确定