具有可变文本长度对齐和居中问题的Div

时间:2015-06-14 22:18:51

标签: html css inline centering

我试图:

  1. 在页面上居中两个div

  2. 同时保持内联

  3. 我可以完成一个,但由于文本长度不同,另一个不起作用。如果我将div放在中心位置,它们就会彼此脱节(如http://willhay.io/about所示错开)。我可以通过向左浮动来解决这个问题,但是它们不会居中。如果div具有可变的文本长度,我怎样才能使div居中,同时保持它们彼此内联?

    <div class="bigBox">
        <div class="aboutBox">
            <img class="icon" src="../img/location.png" width="100" height="100">
            <p>I was born and raised in Atlanta, GA, with dreams of moving to California. , heart, skills, art</p>
        </div>
    
        <div class="aboutBox">
            <img class="icon" src="../img/music.png" width="100" height="100">
            <p>
                I love all types of music, and after watching Guardians of the Galaxy, I gained a new appreciation for 70's music. Follow my Spotify playlist, or listen to it here.
            </p>
        </div>
    </div>
    

    CSS

    .aboutBox {
        width:400px;
        height:400px;
        outline:1px solid black;
        text-align:center;
        color:white;
        font-size:1.5em;
        display:inline-block;
    }
    
    .bigBox {
        text-align:center;
    }
    

1 个答案:

答案 0 :(得分:1)

在aboutBox divs上使用vertical-align: top;