您不需要使用太多的代碼。這可以通過CSS Flexbox輕鬆完成。
HTML
<div id="container">
<div class="player">
<div id="video-controls">
<div class="volumeControl">
<input type="range" id="volume-bar" class="volumeRange"
min="0" max="1" step="0.1" value="1" />
</div>
<div class="muteButton">
<button type="button" id="mute">Mute</button>
</div>
</div><!-- end #video-controls -->
</div><!-- end .player -->
</div><!-- end #container -->
CSS
#container {
display: flex;
justify-content: center;
align-items: center;
}
.player {
display: flex;
justify-content: center;
align-items: flex-end;
width: 226px;
height: 426px;
background-color: blue;
}
#video-controls {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.volumeControl { background: red; }
.muteButton { background: green; }
#volume-bar { width: 120px; }
UPDATED FIDDLE DEMO
注意Flexbox將被所有主流瀏覽器,支持except IE 8 & 9。
刪除單獨的div並將滑塊和按鈕放在主控件div內。使用跨度代替div http://jsfiddle.net/yak613/8u506jy6/ – TricksfortheWeb
檢查更新的小提琴:http://jsfiddle.net/tusharkhatiwada/en0r1Lgu/4/ 這就是你想要的? –