css - 我需要将以下 div 放在页面中央

标签 css

<分区>


想改进这个问题吗? 通过 editing this post 添加细节并澄清问题.

关闭 8 年前

<div id="content" style="top: 70px;">

    <div class="row">
        <div class="col-lg-12">
            <h1  style="color: #df8a13">
            Register Now
            </h1>
        </div>
    </div><br>
    <!-- /.row -->
    <form role="form" id="register_form" action="register.php" method="post">
        <div class="row">
            <div class="col-lg-3">
                <div class="form-group">
                    <input class="form-control" name="first_name" type="text" placeholder="First Name" autocomplete="off">
                </div>
            </div>
            <div class="col-lg-3">
                <div class="form-group">
                    <input class="form-control" name="last_name" placeholder="Last Name" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-3">
                <div class="form-group">
                    <input class="form-control" name="phone" id="phone" placeholder="Mobile Number" autocomplete="off">
                </div>
            </div>
            <div class="col-lg-3">
                <div class="form-group">
                    <input class="form-control" name="dob" id="dob" placeholder="Date of Birth" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-6">
                <div class="form-group">
                    <input class="form-control" name="email_id" id="email_id" placeholder="Email" autocomplete="off">                    
                </div>
            </div>
        </div>


         <div class="row">
            <div class="col-lg-2" style="width=15.667%;">
        <h3 style="color: #df8a13">Secondary school </h3>

          </div>      
            <div class="col-lg-1"> 
                <hr   width="400px" style="float:left;color:#df8a13;background-color:#df8a13;height:1px;border:none; position: relative; top: 1.0em;width: 516px;margin-left: -29px;"/>
            </div>
        </div>



        <div class="row">
            <div class="col-lg-2">
                <div class="form-group">
                    <select class="form-control" name="tenth_year" id="tenth_year"></select>  

                </div>
            </div>
            <div class="col-lg-2">
                <div class="form-group">
                    <input class="form-control" name="tenth_percent" placeholder="Percentage" autocomplete="off">
                </div>
            </div>
            <div class="form-group">
                <div class="col-lg-2">
                    <input class="form-control" name="tenth_pcm_percent" placeholder="PCM percentage" autocomplete="off">
                </div>
            </div>
        </div>


          <div class="row">
            <div class="col-lg-3" style=" width:20%">

        <h3 style="color: #df8a13">Higher secondary school</h3>

          </div>      
            <div class="col-lg-2"> 
                <hr   width="400px" style="float:left;color:#df8a13;background-color:#df8a13;height:1px;border:none; position: relative; top: 1.0em;width: 436px;"/>
            </div>
        </div>





        <div class="row">
            <div class="col-lg-2">
                <div class="form-group">
                    <select class="form-control" name="twelfth_year" id="twelfth_year"></select>  

                </div>
            </div>
            <div class="col-lg-2">
                <div class="form-group">
                    <input class="form-control" name="twelfth_percent" placeholder="Percentage" autocomplete="off">
                </div>
            </div>
            <div class="form-group">
                <div class="col-lg-2">
                    <input class="form-control" name="twelfth_pcm_percent" placeholder="PCM percentage" autocomplete="off">
                </div>
            </div>
        </div>



        <div class="row">
            <div class="col-lg-1">
                <h3 style="color: #df8a13">Graduation</h3>
            </div>      
            <div class="col-lg-3" id="hrline"> 
                <hr style="float:left;color:#df8a13;background-color:#df8a13;height:1px;border:none; position: relative; top: 1.0em;width: 594px;margin-left: 25px;"/>
            </div>
        </div>






        <div class="row">
            <div class="col-lg-2">
                <div class="form-group">
                    <select class="form-control" name="grad_year" id="grad_year" ></select>           
                </div>
            </div>
            <div class="col-lg-2">
                <div class="form-group">
                    <input class="form-control" name="grad_type" placeholder="Discipline" autocomplete="off">
                </div>
            </div>
            <div class="form-group">
                <div class="col-lg-2">
                    <input class="form-control" name="grad_percent" placeholder="Percentage" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-3">
                <button type="submit" name="register_submit" style=" padding: 0px;background-color: white;border: 0px none;width: 200px;height: 50px;margin: 0 auto;text-align:                         center;margin-left: 278px;">
                    <img src="css/images/Sign%20Up.png" height="70px" width="220px">
                </button>
            </div>
        </div>
    </form>
</div>

最佳答案

中心标记在 HTML5 中已弃用。将 block 居中的正确方法是使用

margin: 0 auto

来自 http://www.w3.org/Style/Examples/007/center.en.html

Sometimes it is not the text that needs to be centered, but the block as a whole. Or, phrased differently: we want the left and right margin to be equal. The way to do that is to set the margins to 'auto'. This is normally used with a block of fixed width, because if the block itself is flexible, it will simply take up all the available width. Here is an example:

P.blocktext {
    margin-left: auto;
    margin-right: auto;
    width: 6em
}

关于css - 我需要将以下 div 放在页面中央,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29071058/

上一篇:javascript - Css 属性没有改变(javascript)

下一篇:css - 固定css中内容的宽度

相关文章:

CSS3 列,如果宽度较小则减少数量

javascript - 获取动态文本以适应定义的框大小的麻烦

html - 如何让这些 div 在页面中央相互堆叠?

HTML 文本格式

html - 为什么其他页面上的图标不同

html - 如何拥有向下滚动时不改变大小的固定导航栏?

php - 将 CSS 类分配给第一个和第三个 html 元素

css - WordPress 子主题 CSS 未更​​新

javascript - 图像弹出在一个稳定的位置

internet-explorer - IE-9 中的 Twitter Bootstrap 崩溃问题