2016-08-13 57 views
0

我正在尝试创建数字鼓组。我有一个鼓组的图像,我想在每个鼓上放置圆形击打垫。当我改变视图尺寸时,我无法将触击板保持在原位。我尝试使用bootstrap来保持div的位置,但是我发现这样做不起作用,因为调整大小只是将左边的打击垫堆叠起来。随着视图大小的改变,是否有任何方法可以在鼓组背景图像顶部使用CSS来保持原来的位置?以下是我目前使用的HTML和我正在尝试放置触控板的drumset的图像。预先感谢您的任何帮助!使用CSS的粘滞div位置

<div class="container"> 
    <div class="row"> 
     <div class="col-md-12 col-sm-12"> 
      <img id="playboard" src="drums.png" alt=""> 
       <div class="row" style="height: 100px"> 
       </div> 
      <div class="row" style="height: 50px"> 
      </div> 
      <div class="row" style="height: 50px"> 
      </div> 
      <div class="row" style="height: 50px"> 
       <div class="col-md-4 col-sm-4"> 
        <button class="hit hihathit animated pulse infinite" ng-audio="hihat.mp3" start="0.1"></button> 
       </div> 
       <div class="col-md-4 col-sm-4"> 
        <button class="hit crashhit animated pulse infinite" ng-audio="crash.mp3" start="0.1"></button> 
       </div> 
       <div class="col-md-4 col-sm-4"> 
        <button class="hit ridehit animated pulse infinite" ng-audio="ride.mp3" start="0.1"></button> 
       </div> 
      </div> 
      <div class="row" style="height: 50px"> 
       <div class="col-md-6 col-sm-6"> 
        <button class="hit tomonehit animated pulse infinite" ng-audio="tomone.mp3" start="0.1"></button> 
       </div> 
       <div class="col-md-6 col-sm-6"> 
        <button class="hit tomtwohit animated pulse infinite" ng-audio="tomtwo.mp3" start="0.1"></button> 
       </div> 
      </div> 
      <div class="row" style="height: 50px"> 
      </div> 
      <div class="row" style="height: 50px"> 
       <div class="col-md-4 col-sm-4"> 
        <button class="hit snarehit animated pulse infinite" ng-audio="snare.mp3" start="0.1"></button> 
       </div> 
       <div class="col-md-4 col-sm-4"> 
        <button class="hit kickhit animated pulse infinite" ng-audio="kickdrum.mp3" start="0.1"></button> 
       </div> 
       <div class="col-md-4 col-sm-4"> 
        <button class="hit floortomhit animated pulse infinite" ng-audio="floortom.mp3" start="0.1"></button> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

Drum Set

+0

你好,你有没有尝试过使用html5 canvas元素 - 可能比使用div更好 - 非常酷的项目的方式 –

+0

我没有!我会仔细看看的。谢谢:) –

+0

我抬起头看着帆布,看起来我会遇到同样的问题。我可以使用Javascript绘制它们,但必须使用css来定位它们。 (还是)感谢你的建议。 –

回答

0

您可以尝试使用HTML表格或柔性框包含“打片”。如果您使用百分比来衡量尺寸值,我认为您可以使您的打击垫与您的背景图像一致。

+0

在调整视图大小时,flexbox的行为方式与启动方式相同吗?我一直在使用容器内的百分比,我可以让打击垫左右移动,但不能上下移动。我对此仍然很陌生,所以我仍然在思考如何定位事物。 –

1

我想通了。将容器设置为相对。将图像粘贴在宽度100%和高度自动的内部。然后将按钮div设置为绝对值,并使用顶部,右侧,左侧和底部定位。