html - CSS 居中对齐文本输入、文本区域和选择选项

标签 html css

我一直在尝试在我的 CSS 中使用文本居中对齐来对齐我的表单,但无济于事。我从下面的代码中省略了 CSS。字体样式在我想要的和我拥有的之间看起来也不同。我也不知道如何更改 CSS 中的字体样式。这是我的 html 表单:

                <!DOCTYPE html>
                <html lang="en">
                <head>
                <title>Add/Edit Supplier</title>
                <style>
                </style>
                </head>
                <body>
                <strong>Add/Edit Supplier</strong><hr>

                <?php
                echo form_open('supplier/save', array('name' => 'supplier_add'));    
                ?>

                <label>Supplier</label>
                <input type="text" name="supplier" id="supplier"> <br/>

                <label>PIN</label>
                <input type="text" name="taxpin" id="taxpin"> <br/>

                <label>Contact</label>
                <input type="text" name="contact" id="contact"> <br/>

                <label>Address</label>
                <textarea  name="addresss" id="addresss"></textarea> <br/>

                <label>City</label>
                <select name="citys" id="citys">>
                <option value="">All</option>
                <?php

                foreach($cities as $city)
                {
                echo '<option value="'.$city['cityidd'].'">'.$city['city'].'</option>';
                }
                ?>  
                </select> <br/>


                <label>Telephone</label>
                <input type="text" name="telephone" id="telephone"> <br/>

                <label>Email</label>
                <input type="text" name="email" id="email"> <br/>

                <label>Website</label>
                <input type="text" name="website" id="website"> <br/>

                <label>Payment Mode</label>
                <select name="paymentmodes" id="paymentmodes">>
                <option value="">--Please select--</option>
                <?php
                foreach($modes as $mode)
                {
                echo "<option value='".$mode['id']."'>".$mode['paymentmode']."</option>";
                }
                ?>  
                </select> <br/>

                <label>KES Account</label>
                <input type="number" name="kesaccount" id="kesaccount"> <br/>

                <label>USD Account</label>
                <input type="number" name="usdaccount" id="usdaccount"> <br/>

                <label>Bank</label>
                <select name="banks" id="banks">
                <option value="">--Please select--</option>
                <?php
                foreach($banks as $bank)
                {
                echo '<option value="'.$bank['id'].'">'.$bank['bankname'].'</option>';

                }
                ?>  
                </select> <br/>

                <label>Bank Branch</label>
                <select name="bankbranches" id="bankbranches">
                <option value=""></option>
                </select> <br/>

                <script type= text/javascript>
                $('#banks').on('change', function() {
                var bank = $(this).val();
                $.ajax({
                type: 'post',
                url: 'supplier/get_branches',
                data: { bank_id : bank },
                success: function (response) {
                $('#bankbranches').html(response); 
                }
                });
                });
                </script>

                <label>Bank Branch Code</label>
                <input type="number" name="bankcode" id="bankcode"> <br/>

                <label>SWIFT</label>
                <input type="text" name="swiftcode" id="swiftcode"> <br/>

                <label>Mobile Payment Number</label>
                <input type="number" name="mobilepaymentnumber" id="mobilepaymentnumber"> <br/>

                <label>Mobile Payment Name</label>
                <input type="number" name="mobilepaymentname" id="mobilepaymentname"> <br/>

                <label>Cheque Addressee</label>
                <input type="number" name="chequeddressee" id="chequeaddressee"> <br/>

                <label>Status</label>
                <input type="radio" name="status" value="1" checked="checked">Yes
                <input type="radio" name="status" value="0">No <br/>

                <label>Category</label>
                <select name="categorysuppliers" id="categorysuppliers">
                <option value="">--Please select--</option>
                <?php
                foreach($categories as $category)
                {
                echo '<option value="'.$category['id'].'">'.$category['supplycategory'].'</option>';
                }
                ?>  
                </select> <br/>

                <label>Staff</label>
                <select name="staff" id="staff">>
                <option value="">--Non Staff--</option>
                <?php

                foreach($staffs as $staff)
                {
                echo '<option value="">'.$staff['firstname'].' '.$staff['lastname'].'</option>';
                }
                ?>  
                </select> <br/>

                <input type="submit" name="submit" id="submit" value="Save Details" class="btn">
                <?php
                echo form_close();
                ?>
                </form>
                </body>
                </html>

这是它在网络浏览器中的样子:

How my html form looks in the browser

这就是我希望我的 html 表单的样子:

enter image description here

除了使用文本居中对齐外,我不知道如何实现这一点,到目前为止,我的 html 表单还没有达到我想要的效果。

最佳答案

在您的问题中没有解决任何其他问题,这是一个简单的示例,其中包含您表单的一小部分:

label {
  display: inline-block;
  width: 25%;
}
<label>Supplier</label>
<input type="text" name="supplier" id="supplier">
<br/>

<label>PIN</label>
<input type="text" name="taxpin" id="taxpin">
<br/>

<label>Contact</label>
<input type="text" name="contact" id="contact">
<br/>

输入下方有一个按钮:

label {
  display: inline-block;
  width: 25%;
}

button{
    margin-left: 25%;
}
<label>Supplier</label>
<input type="text" name="supplier" id="supplier">
<br/>

<label>PIN</label>
<input type="text" name="taxpin" id="taxpin">
<br/>

<label>Contact</label>
<input type="text" name="contact" id="contact">
<br/>
<br />
<button type="submit">Submit</button>

关于html - CSS 居中对齐文本输入、文本区域和选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40316922/

相关文章:

jquery - 查找可点击的世界地图

css - 为什么这个 CSS 不适合?

html - 使用相同的列组时,多个 HTML 表格具有不同的列宽

javascript - 文档与文档的区别

html - 我必须更改 html/css 中的哪些内容才能将文字与图片分开?

jquery Jscroll 不显示

html - 允许 CSS 网格随窗口垂直增长,填充剩余空间

javascript - HTML 文本框 : how to restrict input values to only numbers less than 15

html - 在容器内向上推 div

html - 将鼠标悬停在另一个上时隐藏一个 div?