简体   繁体   English

在3格的容器内居中的文本

[英]text centering inside a container with 3 divs

I have the following HTML: 我有以下HTML:

<div id="Container">

    <input type="button" value="button" id="button1" />

    <div id="text1">
        some text here
    </div>

    <div id="TheButtons">
        <input type="button" value="button" class="MyButtons" id="button2" />
        <input type="button" value="button" class="MyButtons" id="button3" />
        <input type="button" value="button" class="MyButtons" id="button4" />
        <input type="button" value="button" class="MyButtons" id="button5" />
    </div>

</div>

And the following CSS: 以及以下CSS:

#Container{
    background:red;
    width:500px;
    height:50px;}

#button1{
    margin:7px;
    float:left;}

#text1{
    margin:7px;
    text-align:center;
    float:left;}

#TheButtons{
    float:right;
    margin:7px;}

.MyButtons{
    margin:0px 3px;
    float: left;}

As you can see in the JsFiddle here, the text is aligned to the left. 如您在此处的JsFiddle中所看到的,文本向左对齐。 The buttons on the right will have different text for different languages so I can't explicitly define the width of the third div TheButtons . 右侧的按钮将针对不同的语言使用不同的文本,因此我无法明确定义第三个div TheButtons的宽度。 How can I get the text to be centered between button1 and TheButtons ? 如何使文本位于button1TheButtons之间的中心?

Thanks. 谢谢。

Place the theButtons div before the text1 div in your HTML. theButtons div放在HTML中的text1 div之前。 Then remove the float from text1 and add overflow:auto to your Container div. 然后从text1删除浮点数,并将overflow:auto添加到您的Container div中。

jsFiddle example jsFiddle示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM