Skip to main content
Known Participant
January 1, 2018
Answered

Can not center thumbs in FlexBox row.

  • January 1, 2018
  • 3 replies
  • 1533 views

I have 3 rows (each with a flex class) of which each row contains 4 columns with a thumb container in each column.

Appearance currently visually acceptable, but I find that with all thumbs aligned/floated left, as the md and lg breakpoints it begins to leave more empty space to right than I would prefer.

I have tried several approaches found thru forum and discussion groups, but have only managed to blow up the page a couple of times due to my unfamiliarity with flex.

Guidance would be appreciated.

Page located at: Equity 2 Gain Property Listings

Thank You

    This topic has been closed for replies.
    Correct answer osgood_

    Dont think it needs to be anywhere near as complex as that. The OP doesn't understand why they are getting more space to the right of the thumbnail sections when reducing the width of the browser, that's because they are mixing Bootstrap 3 and Flex - like half Float and half Flex, which tells me that's nuts.

    I have no idea why the OP is using 3 Flex sections of 4 thumbnails (probably because of lack of understanding - obviously the 1st image in the 2nd section cannot move up to sit next to the last image in the 1st section, the 1st image in the 3rd section cannot move up to sit next to the last image in the 2nd section, hence also the huge gap to the right once the browser window gets narrowed.

    This is a no brainer simple layout achievable with simple Flexbox. The question might well be why is the OP using Flexbox anyway as the layout can work perfectly ok without it just using the Bootstrap 3 float classes. The only thing Flexbox adds is its nice if the link buttons line up, plus if youre a bit of a code snob as I am its a better solution than using floats.

    Why use a sledge hammer to crack a nut - I'm losing the will to live.....the whole web-development scene is packed full of 'nutty professors' who like to complicate the simplest of procedures.

    3 replies

    B i r n o u
    Legend
    January 1, 2018

    well if you really want to get 3 rows containing each 4 cols... you'll have to nest flexbox...

    generate the HTML, so paste the code below in between the BODT tag

    article.global>(section[class="row$"]>(div>img[src="https://placeholdit.co//i/200x130"]+p>lorem20)*4)*3

    hit TAB just at the end of the line (no space in between the 3 and the TAB)

    add a STYLE tag on the HEAD

    to get the first global container being a flexbox add this one to the style sheet

    .global {
        width:94%; 
        margin:0 auto;
        display: flex; 
        flex-direction: column;  
    }

    we change the flex-direction to get what we look for

    now if you want to figureout... just for testing and developping mode, add color to your rows...

    .row1 {
       background-color: lightblue;
    }    
    .row2 {    
        background-color: lightgray;  

    .row3 {  
        background-color: lightgreen;  
    }

    now to get each child of this first container being flexbox themselves add this one

    .global section { 
         display: flex; 
         flex-wrap: wrap; 
    }

    we need to control the way the child of the child grows and shrink... so add this one

    .global section div{   
         flex:1;  
    }

    all of the above are strict minimum to make it works... but it certainly need adjustement for fits the real life and your needs...

    B i r n o u
    Legend
    January 1, 2018

    woaw formatting and mixing code and text is a pure headlock

    Legend
    January 1, 2018

    Problem is that you are combining Bootstrap 3 classes with flex, which is not a good idea. Bootstrap 3 does NOT navtively support flex - Bootstrap 4 does.

    Integrating Flex with Bootstrap 3 is simple - you just ignore the Bootstrap 3 classes. This is how simple it is.

    See newly reformated code  below - get rid of all the unecessary containers <div class="col-sm-4 col-lg-3">  </div> which wrap your 'thumbnail '<divs> -

    they are excess to requirement and just bloat the html mark-up. Get rid of the 'row' class from <div class="flex-row row">

    You should have just the one <div class="flex-row"> </div> NOT 2 and all your thumbnail <divs> go inside it, as many as you want.

    <!--BEGIN 1ST (ONLY!) FLEX ROW-->

    <div class="flex-row">

    <div class="thumbnail">

    <img src="http://greenlightinvestmentproperty.com/images/property-images/615 Frank.jpg" width="300" height="225" alt=""/>

    <div class="caption">

    <h2>615 Frank</h2>

    <ol style="text-align:left;">

    <li>SFR</li>

    <li>Rent:$550.00</li>

    <li>Sale: $34,500.00</li>

    <li>Item Four</li>

    <li>SFR</li>

    <li>Rent:$550.00</li>

    <li>Sale: $34,500.00</li>

    <li>Item Four</li>

    </ol>

    </div>

    <!-- /.caption -->

    <p><a class="btn btn-primary" href="#">Link</a></p>

    </div>

    <!-- /.thumbnail -->

    <div class="thumbnail ">

    <img src="http://greenlightinvestmentproperty.com/images/property-images/619 Frank.jpg" width="300" height="225" alt=""/>

    <div class="caption">

    <h2>619 Frank</h2>

    <ol>

    <li>SFR</li>

    <li>Rent:$550.00</li>

    <li>Sale: 34,500.00</li>

    <li>Item Four</li>

    </ol>

    </div>

    <!-- /.caption -->

    <p> <a class="btn btn-primary" href="#">Link</a> </p>

    </div>

    <!-- /.thumbnail -->

    <div class="thumbnail">

    <img src="http://greenlightinvestmentproperty.com/images/property-images/722 Perry.jpg" width="300" height="225" alt=""/>

    <div class="caption">

    <h2>722 Perry</h2>

    <ol>

    <li>SFR</li>

    <li>Rent:$725.00</li>

    <li>Sale:$47,500.00</li>

    <li>Item Four</li>

    </ol>

    </div>

    <!-- /.caption -->

    <p><a class="btn btn-primary" href="#">Link</a> </p>

    </div>

    <!-- /.thumbnail -->

    <div class="thumbnail">

    <img src="http://greenlightinvestmentproperty.com/images/property-images/1821 Court.jpg" width="300" height="225" alt=""/>

    <div class="caption">

    <h2>1821 Court</h2>

    <ol>

    <li>Multi Unit</li>

    <li>Rent:1925.00</li>

    <li>Sale:119,000.00</li>

    <li>Item Four</li>

    </ol>

    </div>

    <!-- /.caption -->

    <p><a class="btn btn-primary" href="#">Link</a></p>

    </div>

    <!-- /.thumbnail -->

    <div class="thumbnail">

    <img src="http://greenlightinvestmentproperty.com/images/property-images/2468 Thomas.jpg" width="300" height="225" alt=""/>

    <div class="caption">

    <h2>2468 Thomas</h2>

    <ol>

    <li>Item One</li>

    <li>Item Two</li>

    <li>Item Three</li>

    <li>Item Four</li>

    </ol>

    </div>

    <!-- /.caption -->

    <p><a class="btn btn-primary" href="#">Link</a></p>

    </div>

    <!-- /.thumbnail -->

    <div class="thumbnail ">

    <img src="http://greenlightinvestmentproperty.com/images/property-images/2501 Plainfield.jpg" width="300" height="225" alt=""/>

    <div class="caption">

    <h2>2501 Plainsfield</h2>

    <ol>

    <li>Item One</li>

    <li>Item Two</li>

    <li>Item Three</li>

    <li>Item Four</li>

    <li>Item One</li>

    <li>Item Two</li>

    <li>Item Three</li>

    <li>Item Four</li>

    </ol>

    </div>

    <!-- /.caption -->

    <p> <a class="btn btn-primary" href="#">Link</a> </p>

    </div>

    <!-- /.thumbnail -->

    <div class="thumbnail">

    <img src="http://greenlightinvestmentproperty.com/images/property-images/2508 Beta.jpg" width="300" height="225" alt=""/>

    <div class="caption">

    <h2>2508 Beta</h2>

    <ol>

    <li>Item One</li>

    <li>Item Two</li>

    <li>Item Three</li>

    <li>Item Four</li>

    </ol>

    </div>

    <!-- /.caption -->

    <p><a class="btn btn-primary" href="#">Link</a> </p>

    </div>

    <!-- /.thumbnail -->

    </div>

    <!--END 1ST (ONLY!) FLEX ROW-->

    Add the css styling to your page (see below): (this is fully responsive and your 'link' buttons will line up no matter how little or how much text you have in the columns). Obviously you still have the Bootstrap 3 css and js files linked to the page so it can style the 'thumbnail/caption' classes etc. You're really just picking which bits of the page are styled with Bootstrap and which bits you are styling youself - a win, win situation.

    <style>

    .flex-row {

    display: flex;

    flex-wrap: wrap;

    width: 90%;

    margin: 0 auto;

    }

    .flex-row img {

    max-width: 100%;

    height: auto;

    }

    /* 4 columns default */

    .thumbnail {

    display: flex;

    flex-direction: column;

    width: 22%;

    margin: 0 1.5% 30px 1.5%;

    }

    /* 3 columns at screen width 1000px */

    @media screen and (max-width: 1000px) {

    .thumbnail {

    width: 30.33%;

    }

    }

    /* 2 columns at screen width 768px */

    @media screen and (max-width: 768px) {

    .thumbnail {

    width: 47%;

    }

    }

    /* 1 column at screen width 480px */

    @media screen and (max-width: 480px) {

    .thumbnail {

    width: 100%;

    margin: 0 0 30px 0;

    }

    }

    /* Push link to the foot of column */

    .caption {

    flex: 1;

    }

    /* line up link with h2 */

    .thumbnail p {

    margin: 0 0 15px 10px;

    }

    </style>

    THATS IT - SIMPLE!

    Don't forget when you have your construction the way you require it to be and you have used Flex you need to prefix the Flex css so it's compatible with older browsers.

    Go to:

    Autoprefixer CSS online

    Copy any css selector you have used with Flex and paste it in the prefixer window - .flex-row will give you the below combination, so that is what you need to use for your css.

    .flex-row {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    width: 90%;
    margin: 0 auto;
    }

    Of course this is easier if you use a workflow like SASS or LESS as it will automate the css prefixing. Personally I don't as I think SASS or LESS is overkill purely for css prefixing - css prefixing is something that needs addressing in DW to make it a simpler workflow beacuse its NOT something which is optional.

    B i r n o u
    Legend
    January 1, 2018

    can't you nest two flex container

    each row being a flex container containing the four