Home > front end >  How to make two elements always stay at the same height?
How to make two elements always stay at the same height?

Time:01-13

I have two

  • one is an image one a piece of text. I need the bottom of the text to align with the bottom of the text at a relative scale. I can make them both align with margin-top but not when I change the window size. enter image description here

  • CodePudding user response:

    If you have both elements inside a div you can simply use flexbox to align them.

    PS: you should provide us with some code in order to make your question more clear.

    Take a look at this guide to understand more how flexbox works.

    Your code should look something like this:

    HTML:

    <div >
        <img />
        <p>Something...</p>
    </div>
    

    CSS:

    .container {
        display: flex;
        align-items: center;
    }
    

    CodePudding user response:

    There are several ways to do this, one simple way would be to put both elements inside a div container and apply the following styles.

    .elements-container{
        display: flex;
        align-items: flex-end;
        justify-content: flex-start;
     }
    

    Note that you can adjust the justify content,see this link from css-tricks for more information, as well as add a width attribute to the container as per your needs. Hope this helped in some way.

    •  Tags:  
    • Related