显示内联元素

时间:2013-10-30 15:14:58

标签: html css styling

我想知道你是否可以提供帮助 我正在寻找一种简单的方法来水平显示此图片https://db.tt/w5doYPNZ中带圆圈的元素。

我试过了:

.calculator {
display: inline-block;  
}

然而,这似乎没有任何区别。我添加了HTML以供参考 提前致谢:D

<div class="calculator">
    <div class="input-group input-small">
        <h4>Adult (12+)</h4>
        <button class="btn theme-btn" id="decrease" value="Decrease Value">-</button>
        <input type="text" id="adult" value="1" class="form-control input-usmall" min="0">
        <button class="btn theme-btn" id="increase" value="Increase Value">+</button>
        <h4>Child (2-11)</h4>
        <button class="btn theme-btn" id="decreasec" value="Decrease Value">-</button>
        <input type="text" id="child" value="0" class="form-control input-usmall" min="0" >
        <button class="btn theme-btn" id="increasec" value="Increase Value">+</button>
        <p>£</p><p id="total"></p><p>.00</p><button class="btn green" onclick="myFunction()">Calculate</button>
    </div>
</div>

3 个答案:

答案 0 :(得分:1)

把这些东西放在它自己的div中:

<h4>Adult (12+)</h4>
<button class="btn theme-btn" id="decrease" value="Decrease Value">-</button>
<input type="text" id="adult" value="1" class="form-control input-usmall" min="0">
<button class="btn theme-btn" id="increase" value="Increase Value">+</button>

然后把这个东西放在它自己的div:

<h4>Child (2-11)</h4>
<button class="btn theme-btn" id="decreasec" value="Decrease Value">-</button>
<input type="text" id="child" value="0" class="form-control input-usmall" min="0" >
<button class="btn theme-btn" id="increasec" value="Increase Value">+</button>

然后这个东西就在它自己的div中:

<p>£</p><p id="total"></p>
<p>.00</p>
<button class="btn green" onclick="myFunction()">Calculate</button>

然后浮动每个div。我会让三个新创建的div都存在于同一个父div中。另外,我会避免显示:inline-block,因为它在旧浏览器中存在问题。只是漂浮,你会得到同样的效果。

答案 1 :(得分:0)

试试这个:

.input-group.input-small {
    display: inline-block;  
}

有了这个:

<div class="calculator">
                <div class="input-group input-small">
                    <h4>Adult (12+)</h4>
                    <button class="btn theme-btn" id="decrease" value="Decrease Value">-</button>
                    <input type="text" id="adult" value="1" class="form-control input-usmall" min="0">
                    <button class="btn theme-btn" id="increase" value="Increase Value">+</button>
                </div>
                <div class="input-group input-small">
                    <h4>Child (2-11)</h4>
                    <button class="btn theme-btn" id="decreasec" value="Decrease Value">-</button>
                    <input type="text" id="child" value="0" class="form-control input-usmall" min="0" >
                    <button class="btn theme-btn" id="increasec" value="Increase Value">+</button>
                    <p>£</p><p id="total"></p><p>.00</p><button class="btn green" onclick="myFunction()">Calculate</button>
                </div>
            </div>

答案 2 :(得分:0)

<强> Here's a codepen with a working model.

您尝试使用display: inline-block影响的元素不会从.calculator父元素继承该行为。您需要直接定位它们。

我会更改你的类命名和元素选择,但至少,你需要为计算器组件创建一个单独的类,将计算器结构分解为所述组件,并且需要将段落转换为跨度:

HTML:

<div class="calculator">
  <div class="calculator-submodule input-group input-small">
    <h4>Adult (12+)</h4>
    <button class="btn theme-btn" id="decrease" value="Decrease Value">-</button>
    <input type="text" id="adult" value="1" class="form-control input-usmall" min="0">
    <button class="btn theme-btn" id="increase" value="Increase Value">+</button>
  </div>
  <div class="calculator-submodule input-group input-small">
    <h4>Child (2-11)</h4>
    <button class="btn theme-btn" id="decreasec" value="Decrease Value">-</button>
    <input type="text" id="child" value="0" class="form-control input-usmall" min="0" >
    <button class="btn theme-btn" id="increasec" value="Increase Value">+</button>
  </div>
  <div class="calculator-submodule">
    <span>£</span>
    <span id="total"></span><span>.00</span><button class="btn green"     onclick="myFunction()">Calculate</button>
  </div>
</div>

CSS:

.calculator-submodule {
  display: inline-block;
  padding-left: 1em;
  text-align: center;
}