英文:
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 -->
<div styleName="green-area">
  <div style={{ flexGrow: 10, }}>
    <div styleName={`height`}>
      <div styleName="black-area">
        <div style={{ flexGrow: 10, }}>
          <div styleName={`height`} />
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 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 
styleNamewhich is incorrect. It should beclassName - 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论