有一種方法可將滑塊和按鈕放在畫布旁邊?我嘗試了<div>
風格,但它將滑塊移動到頁面頂部或頁面底部。這是我的HTML代碼:HTML-將滑塊放在畫布旁邊
<body>
<div style="margin: 0px auto; width: 512px;">
<h1>Model of a Robot</h1>
<div style="margin-top: 30px; margin-bottom: 30px;">
<canvas id="gl-canvas" width="512" height="512">
Oops ... your browser doesn't support the HTML5 canvas element
</canvas>
<button id= "switchProj">Change Projection type</button>
<div>
body angle -180 <input id="bodySlider" type="range"
min="-180" max="180" step="10" value="0"
/>
180
</div>
<div>
head angle -45 <input id="headSlider" type="range"
min="-45" max="45" step="5" value="0"
/>
45
</div>
<div id="leftArmSlider">
left arm angle -90 <input id="leftArmSlider" type="range"
min="-90" max="-30" step="10" value="-30"
/>
-30
</div>
<div id="rightArmSlider">
right arm angle 30 <input id="rightArmSlider" type="range"
min="30" max="90" step="10" value="30"
/>
90
</div>
<div>
left leg angle -30 <input id="leftLegSlider" type="range"
min="-30" max="30" step="5" value="0"
/>
30
</div>
<div>
right leg angle -30 <input id="rightLegSlider" type="range"
min="-30" max="30" step="5" value="0"
/>
30
</div>
<div>
zNear .01<input id="zNearSlider" type="range"
min=".01" max="4" step="0.1" value="0.3" />
4
</div>
<div>
zFar 1<input id="zFarSlider" type="range"
min="1" max="10" step="1.0" value="5" />
10
</div>
<div>
fov 10<input id="fovSlider" type="range"
min="10" max="120" step="5" value="70" />
120
</div>
<div>
aspect 0.5<input id="aspectSlider" type="range"
min="0.5" max="2" step="0.1" value="1" />
2
</div>
</body>
您是否想過將元素放在一行中,然後將滑塊包裹在同一個div中並將它們定義爲機器人元素列旁邊的列? –
請參閱[這裏](https://en.wikipedia.org/wiki/Cascading_Style_Sheets) –
也@OP,最好的做法是隻發佈與您面臨的問題相關的代碼,即滑塊的div並且畫布 –