如何在以下场景中将div内容与中心对齐?

时间:2014-03-12 07:39:31

标签: javascript css html

我有一个div内有两个divs,如下所示。

HTML code:

<div style="margin: 20px auto;" align="center">
        <div style="float:left;">
            <input type="button" class="myButton" value="Add"/>
            <input type="button" class="myButton" value="Modify"/>
            <input type="button" class="myButton" value="Delete"/>
        </div>        
        <div>
            <form id = "country_form" method="post">
                <select id="country_name" name = "country_name" style = "position: relative;width:60px;" onChange="return country_change();">
                    <option value="">Select</option>
                    <option value="India">India</option>
                    <option value="Australia">Australia</option>
                    <option value="Malaysia">Malaysia</option>
                    <option value="UAE">U.A.E</option>
                    <option value="Singapore">Singapore</option>
                    <option value="USA">U.S.A</option>
                    <option value="Bangladesh">Bangladesh</option>
                    <option value="Sri Lanka">Sri Lanka</option>
                    <option value="China">China</option>
                </select>&nbsp;
                <select id="country_port" name = "country_port" style = "position: relative;margin-left:5px;width:60px;">
                        <option value="">Select</option>
                        <option value="Macau">Macau</option>
                        <option value="Ningbo">Ningbo</option>
                        <option value="Beijing">Beijing</option>
                        <option value="Shanghai">Shanghai</option>
                        <option value="Guangzhou">Guangzhou</option>
                        <option value="Shenzhen">Shenzhen</option>
                </select>&nbsp;
                <input type="hidden" value="yes" name="submit_value"/>
                <input type="submit" class="myButton" value="Search"/>      
            </form>
        </div>
    </div>

当我正在向左移动到第一个内部div时,外部div将离开屏幕。

所以如何让它成为中心。

请帮助我使其成为可能

jsFiddle: DEMO

1 个答案:

答案 0 :(得分:0)

看看这有帮助.........

<div style="margin: 20px auto; width:80%;" align="center">

http://jsfiddle.net/XNdJw/