当前位置: 首页 > 知识库问答 >
问题:

如何左对齐这些引导表单项?

金霄
2023-03-14

表单包含在一个跨度为7的div中,因为我的站点有两个列--7和4列。

下面是我的HTML。如果您查看此页面http://accounts.tao.tw.shuttle.com/examples_bootstrap/basecss/forms中的“水平表单”下,您将看到标签是左对齐的,但不是绝对左对齐,因此标签的起始位置垂直相同。

<form class="form-horizontal">
    <div class="control-group">
        <label class="control-label" for="inputSaving">What are you saving for?</label>
        <div class="controls">
            <input class="span4" type="text" id="inputSaving" placeholder="e.g. Swimming Lessons, Birthday Party, College Fund, etc.">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="description">Add a short description</label>
        <div class="controls">
            <textarea class="span4" rows="4" placeholder="Describe in your own words the saving goal for this piggybank"></textarea>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="categoryselect">Choose a Category</label>
        <div class="controls">
            <select class="span4">
                <!-- Add some CSS and JS to make a placeholder value-->
                <option value="Kittens">Kittens</option>
                <option value="Keyboard Cat">Keyboard Cat</option>
                <option value="Twitter Bird">Twitter Bird</option>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="goal">Your Saving Goal</label>
        <div class="controls">
            <input type="text" class="span4" id="goal">
        </div>
    </div>
    <button class="btn btn-large btn-primary" type="button">Submit</button>
</form>

共有1个答案

麹繁
2023-03-14

就我两分钱。如果您使用的是Bootstrap3,那么我只需在您自己站点的样式表中添加一个额外的样式,它控制Control-Labeltext-left样式。

如果要将text-left添加到标签中,默认情况下会有另一种样式覆盖此.form-hollate.control-label。所以如果你加上:

.form-horizontal .control-label.text-left{
    text-align: left;
}

然后将内置的text-left样式正确地应用于标签。

 类似资料:
  • 你好,堆栈溢出成员 这是列标题的数组。我希望列1到列5左对齐(列1到列5的所有标题、子标题和表格数据单元格左对齐),而我希望列6到列8居中对齐(列1到列5的所有标题、子标题和表格数据单元格居中对齐)。请帮我解决这个问题,因为我只能使所有列居中或左对齐。 如果你能帮助我,请提供一个关于CodeSandbox的演示 这是我的标题数据

  • 问题内容: 使用典型的CSS,我可以在两列之间向左浮动另一列,并在两者之间留出一定的间距。我该如何使用flexbox? 问题答案: 您可以添加到父元素。这样做时,子级flexbox项将与相对侧对齐,并在它们之间留有空间。 您也可以添加到第二个元素以使其向右对齐。

  • 问题内容: 我一直在尝试以下操作,以使导航栏的标题保持对齐: 在文件中: 在文件中: 但我找不到解决问题的方法。我还尝试了以下在此处未显示任何内容的内容: 在文件中: 在文件中: 问题答案: 您可以使用navigationItems titleView添加具有左对齐的UILabel,然后使用自动布局设置其框架,如下所示:

  • 我正在使用bootstrap框架,试图使图像水平居中,但没有成功。。 我尝试过各种技术,例如将12个网格系统分成3个相等的块,例如 要获得相对于页面居中的图像,最简单的方法是什么?

  • 不知道如何将此按钮居中。在BS3中,我只使用中心块,但在BS4中,这不是一个选项。有什么建议吗?