Left-align image and centered text on same level inside of a div?

14,354

Why not just exploit CSS position? like this.

Cheers

Share:
14,354

Related videos on Youtube

Sean Anderson
Author by

Sean Anderson

Sr. Software Developer and blockchain enthusiast w/ ~8 years of full-stack experience in JavaScript and C#. Extensive open-source contributions and a part of the MarionetteJS organization. Currently full-time day trader.

Updated on June 04, 2022

Comments

  • Sean Anderson
    Sean Anderson almost 2 years
    HTML:
    <br />
        <div class="UpperTitle">
            <img src="Images/CableSolve Logo.jpg" align="absmiddle" padding-right: 10px;" /> CableSolve Web Dashboard - Version 0.1.1
        </div>
    <br />
    
    CSS:
    .UpperTitle
    {
        text-align: center;
        padding-top: 20px;
        padding-bottom: 20px;
        background-color: #CEDEF4;
        font-weight:bold;
        color: #224499;
        border-radius: 10px;
    }
    

    I have this setup currently. I would like to position the banner on the same level as the text, but I would like to have the banner on the left-hand side of the screen with the text in the center of the screen.

    It seems like my only options are either: floating the image (would need a ton of hard-coded values to make this look OK), wrapping the text in a <div> to center it specifically (which causes it to drop below the image), or centering both the image and the text -- which is what I do currently.

    I found a lot of various guides on this, but they seem to either float the image using a simple website layout, or vertically align the text, or find the center banner/text combo acceptable.

    Thoughts?

    Thanks in advance.

  • Sean Anderson
    Sean Anderson about 13 years
    I liked this one. :) Nice, simple and I understood exactly what was going on. Thanks! Nothing against Snippet's answer, I'm sure they both work relatively identically.