【问题标题】:trying to get the output of a form to display on same line as <p> element html试图让表单的输出显示在与 <p> 元素 html 相同的行上
【发布时间】:2016-02-11 00:13:40
【问题描述】:

我正在尝试将此表单的某些元素显示在同一行:我希望表单的输出显示在与“总计:$”相同的行-(我仍然希望每lb(在本例中为 $1.00)显示在上面的行中,数字微调器显示在右侧)。我试图将整个东西包装在 &lt;span&gt; 中,我将 CSS 设置为 display:inline 但它没有用(我也尝试了一些其他的东西也没有用)。 这是我的代码选择:
HTML:

 <div class="caption">
<form onsubmit="return false" oninput="amount.value = (quantity.valueAsNumber * (1))">
<legend>$1.00</legend>
<span class="quant"><p><label for="quant">QTY</label>
 <input type="number" min="1" max="5" id="quantity" name="quantity"></p></span>
<span class="inline"><p>Total:$<output name="amount" for="quantity"></output></p></span>
</form>
</div>

CSS:

legend { float: left;
         margin-top: 35px;
         padding-top: 20px;
         margin-bottom: 5px;
}
.inline { display: inline; }
.quant { text-align: right;
            max-width: 30em;
            float: right;
            margin-top: 25px;
            padding-bottom: 5px;
            margin-bottom: 10px;
}

【问题讨论】:

    标签: html css forms layout


    【解决方案1】:

    legend { float: left;
            
    }
    .inline { display: inline; }
    .quant { text-align: right;
                max-width: 30em;
                float: right;
              
    }
    form > * { border:1px solid red; line-height:2em }
    <div class="caption">
        <form onsubmit="return false" oninput="amount.value = (quantity.valueAsNumber * (1))">
            <legend>$1.00</legend>
            <span class="quant">
               
                    <label for="quant">QTY</label>
                    <input type="number" min="1" max="5" id="quantity" name="quantity">
               
            </span>
            <span>Total:$<output name="amount" for="quantity"></output></span>
        </form>
    </div>

    摆脱您的p 标签。尽量不要使用可有可无的容器和类。您的代码将更具可读性。您可以更改form &gt; *line-height

    【讨论】:

    • 谢谢,@Pcodea Xonos(我更像是一个 JS 人,只是想让我的 html 达到标准,需要 2 从模型中制作)- 摆脱

      标签起到了将“总计”与总计 # 放在同一行的技巧。我还没有为表单设置样式 - 行高是与数字代码和“数量”在同一行上对齐的部分(也只是为了了解以供将来参考)?感谢您的帮助!

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 2011-04-27
    相关资源
    最近更新 更多