You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调整input图片位置:使stick.png在$15正下方且与bigButton.png相邻

问题根源

两个<input type="image">默认属于行内块元素,默认对齐规则为基线对齐。你给bigButton.png设置了500px的高度,远高于stick的100px,所以stick会被挤到和大按钮底部基线对齐的位置,自然就和上方的$15标题拉开了约400px的空隙。

修复方案

如果要同时满足「stick位于$15正下方、和bigButton相邻」的布局要求,推荐用Flex布局调整结构,修改后的完整代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>$15 - Arsenal Clicker</title>
    <style>
        /* 全局样式初始化可选,避免默认边距干扰 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .page-title {
            text-align: center;
            margin: 10px 0;
        }
        .content-wrap {
            display: flex;
            align-items: flex-start; /* 两个子元素顶部对齐 */
            justify-content: center; /* 整体内容居中,可根据需求调整 */
            gap: 10px; /* 两个相邻元素的间距,可自行修改数值 */
        }
        .stick-wrap {
            text-align: center;
        }
        #stick {
            margin-top: 10px; /* 控制$15和stick的上下间距,可自行修改数值 */
        }
    </style>
</head>
<body>
    <h1 class="page-title">Arsenal Clicker</h1>
    <div class="content-wrap">
        <input type="image" id="bigButton" onclick="click()" src="Images/bigButton.png" height="500">
        <div class="stick-wrap">
            <h1>$15</h1>
            <input type="image" id="stick" onclick="purchaseStick()" src="Images/stick.png" height="100">
        </div>
    </div>
</body>
</html>

如果你不想调整DOM结构,只想快速消除400px的空白,只需要给两个图片元素添加vertical-align: top属性即可:

<input type="image" id="bigButton" onclick="click()" src="Images/bigButton.png" height="500" style="vertical-align: top;">
<input type="image" id="stick" onclick="purchaseStick()" src="Images/stick.png" height="100" style="vertical-align: top;">

内容的提问来源于stack exchange,提问作者Atramentis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 17:06:01