Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Vertically centering images within flex items

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #284969
    bigdesignmachine
    Participant

    I have four divs sitting inside a parent flexbox.

    What is confusing me is how I can get the images within the flex items to center vertically and horizontally. I thought the following would do it:

    justify-content: center;
    align-items: center;

    Adding these to the flexbox parent would work but it doesnt seem to have the effect I am looking for.

    My CSS is as follows:

    .flex-container {
    display: flex;
    flex-wrap: nowrap;
    width: 650px;
    }

    .flex-container > div {
    width: 100px;
    margin: 10px;
    text-align: center;
    line-height: 75px;
    font-size: 30px;
    align-items: center;
    justify-content: center;
    }

    .div-1 {
    flex: 2;
    }

    .div-2 {
    flex: 1;
    }

    .div-3 {
    flex: 1;
    }

    .div-4 {
    flex: 1;
    }

    .img {
    height: 55px;
    }

    .bookit_button {
    background-color: #4CAF50;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
    }

    My HTML is as follows:

    Ultimately, the goal is to end up with this:

    http://thelavender.net/_fades/images/sample.png

    #284974
    bigdesignmachine
    Participant

    I needed to add display: flex; do .flex-container > div

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘CSS’ is closed to new topics and replies.