按钮位置像游戏控制器css,响应

问题描述 投票:0回答:2

我想以类似于游戏控制器的方式放置这4个按钮。我得到的结果如下。它们应位于屏幕的中下部,较小且必须具有响应性。我需要改变什么?我应该使用#controls { position:relative;}吗?

Controls

HTML代码:

<head><meta name="viewport" content="width=device-width, initial-scale=1.0"/>...</head>

<body><div id="controls">
    <button id="keyboard_key_up" class="movements_control"><img src="public/img/keyboard_key_up.png"/></button>
    <button id="keyboard_key_left" class="movements_control"><img src="public/img/keyboard_key_left.png" /></button>
    <button id="keyboard_key_down" class="movements_control"><img src="public/img/keyboard_key_down.png" /></button>
    <button id="keyboard_key_right" class="movements_control"><img src="public/img/keyboard_key_right.png" /></button>

</div>...</body>

CSS代码:

#keyboard_key_up {
    position: absolute;
    right:300px;
    bottom: 500px;
    border-style: solid;
    border-color: black;
    background: white;z

}

#keyboard_key_left {
    position: absolute;
    right:575px;
    bottom: 250px;
    border-style: solid;
    border-color: black;

}

#keyboard_key_down {
    position: absolute;
    right:300px;
    bottom: 250px;
    border-style: solid;
    border-color: black;

}

#keyboard_key_right {
    position: absolute;
    right:25px;
    bottom: 250px;
    border-style: solid;
    border-color: black;

}
html css button responsive-design responsive
2个回答
1
投票

今天对flex和grid的支持应该相当不错,但是根据你的目标,这可能不起作用。

body {
  margin: 0;
  padding: 0;
}

#wrapper {
  display: flex;
  height: 100vh;
  justify-content: center;
}

#controls {
  display: inline-grid;
  grid-column-gap: 0;
  align-self: end;
}

.movements_control {
  border: solid 1px black;  
  margin: 0;
  padding: 0;
}

.movements_control img {
  width: inherit;
  height: inherit;
}

#keyboard_key_up {
  grid-column-start: 2;
}

#keyboard_key_left {
  grid-column-start: 1;
}

#keyboard_key_down {}

#keyboard_key_right {
  grid-column-start: 3;
}

@media (min-width: 721px) {
  .movements_control {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 720px) {
  .movements_control {
    width: 20px;
    height: 20px;
  }
}
<div id="wrapper">
  <div id="controls">
    <button id="keyboard_key_up" class="movements_control"><img src="public/img/keyboard_key_up.png"></button>
    <button id="keyboard_key_left" class="movements_control"><img src="public/img/keyboard_key_left.png"></button>
    <button id="keyboard_key_down" class="movements_control"><img src="public/img/keyboard_key_down.png"></button>
    <button id="keyboard_key_right" class="movements_control"><img src="public/img/keyboard_key_right.png"></button>
  </div>
</div>

0
投票

试试这个CSS:

#controls {
position: relative;
bottom: 10px;
margin: 0 auto;
}

如果这不起作用,您能否使用plunker或codepen发送您的代码?

© www.soinside.com 2019 - 2024. All rights reserved.