How to create a completely flexible piano keyboard with HTML and CSS

后端 未结 4 428
北恋
北恋 2021-01-16 06:43

I\'m trying to create a piano keyboard that will keep it\'s elements ratios using flex box, but can\'t seem to make the black notes stay the same width or height once I star

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-16 06:57

    Not sure if you need your black keys to be independent blocks but here is an example

    
     
    body {
      background: #000;
    }
    
    .note-container {
      width: 100%;
      display: flex;
      flex-flow: row nowrap;
    }
    
    .white-note {
      position: relative;
      width: 10%;
      height: 400px;
      background: #fff;
      margin: 0 2px;
    }
    
    .white-note.black-note:after {
      content: "";
      position: absolute;
      top: 0;
      right: -25%;
      width: 50%;
      height: 50%;
      background: #000;
      z-index: 1;
    }
    

提交回复
热议问题