html - 垂直对齐div中的多个文本框

标签 html css flexbox

我有多对标签和文本框,我想让标签在它们所在的位置并垂直对齐所有文本框。如果可能的话,我不想使用表格。这是我的代码:

 <div class="form-group col-md-6 well" id="votreStation" style="background-color: #19171c; border-color: #ffcc00; ">
                <br />
                <asp:Label class="label label-danger" runat="server" ID="labelVotreStation"></asp:Label>
                <br>
                <br>
                <asp:Label class="label label-warning" for="exampleTextarea" ID="labelPrixGazoleVotreStation" runat="server"> </asp:Label>
                <asp:TextBox ID="PrixGazoleStationChoisie" runat="server">1.25</asp:TextBox>
                <br>
                <asp:Label class="label label-warning" for="exampleTextarea" ID="labelPrixSP95VotreStation" runat="server"> </asp:Label>
                <asp:TextBox ID="PrixSP95StationChoisie" runat="server">1.4</asp:TextBox>
                <br>
                <asp:Label class="label label-warning" for="exampleTextarea" ID="labelPrixSP98VotreStation" runat="server"></asp:Label>
                <asp:TextBox ID="PrixSP98StationChoisie" runat="server">1.3</asp:TextBox>
                <br>
                <asp:Label class="label label-warning" for="exampleTextarea" ID="labelPrixGPLcVotreStation" runat="server"></asp:Label>
                <asp:TextBox ID="PrixGPLcStationChoisie" runat="server">0.6</asp:TextBox>
                <br>
                <asp:Label class="label label-warning" for="exampleTextarea" ID="labelPrixSP95_E10VotreStation" runat="server"></asp:Label>
                <asp:TextBox ID="PrixE10StationChoisie" runat="server">1.2</asp:TextBox>
                <br>
                <asp:Label class="label label-warning" for="exampleTextarea" ID="labelPrixE85VotreStation" runat="server"></asp:Label>
                <asp:TextBox ID="PrixE85StationChoisie" runat="server">1.3</asp:TextBox>

                <br>
            </div>

请注意,我已经为 div 准备了这个 css:

 #votreStation {
        flex: 1; 
        padding: 1em;

    }

最佳答案

使用flex垂直对齐

#votreStation {
   display:flex
   align-items:center; 
   flex-direction:column;
}

关于html - 垂直对齐div中的多个文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44130416/

相关文章:

javascript - 如何根据当前是否选择有条件地切换元素

html - 如何获得 CSS 类选择器来覆盖 input[readonly] 选择器?

html - Flex children 在较小的屏幕上被切断

Javascript,智能手机视频检测?

html - 中心 DIV 相对于菜单 DIV 旁边的父 DIV

css - 源代码中不需要的 CSS

html - 如何在内联 block 元素之间添加相等的空间?

html - 是否可以将行和列与 flexbox 混合使用?

javascript - POST请求后如何刷新表单页面?

html - 一个unicode符号的不同颜色