0

Okay so I'm setting up the styling for a blog archive page in WP, and I'm running into a flexbox issue.

I've checked numerous similar questions but I can't seem to make heads or tails of what I'm doing wrong.

EDIT: this has been marked as a duplicate. And while it is true that there are many posts on this website detailing people having trouble using flexbox to center things, those solutions have not worked for me, and I think that it's something specific about my code that is bugging things up.

That is one reason why I explicit ask in the title if there are height, width, display, or position requirements for flexbox to function normally because I use min-width and min-height, not explicit width and height, and I think from some of the other posts that might be part of the problem but I can't find the part of the flexbox specification that details that behavior.

Here's a codepen with my code.

https://codepen.io/thedonquixotic/pen/yPGPmj

And here's the code itself:

<section class=" blog-post-section container-fluid">
        <a href="http://www.josvanriswick.com/images/apple-pear-stilllife_400.jpg">


        <div class="img-container rellax" data-rellax-speed="-4">
            <img class="section-img rellax" data-rellax-speed="-6" src="http://www.cashartblog.com/wp-content/uploads/2012/09/peppers7.jpg">
            <polygon points="345.606,107.5 324.394,128.713 418.787,223.107 0,223.107 0,253.107 418.787,253.107 324.394,347.5   345.606,368.713 476.213,238.106 " fill="#FFFFFF">
        </polygon></div>
        <div class="title-card-flex">
            <h1 class="class-study-title"> <span class="">Test Post Nietzsche</span></h1>
            <p class="blog-summary"><span>War spirit strong sexuality will play right deceptions noble prejudice noble derive chaos. Burying disgust contradict passion overcome. Chaos play evil reason hope of overcome oneself pinnacle spirit enlightenment. Will ascetic ubermensch holiest superiority sea selfish pious law. Overcome selfish chaos snare convictions truth deceptions snare reason. Self noble salvation insofar god christian joy marvelous. […]</span></p>


        </div>

            </a>
    </section>

<section class=" blog-post-section container-fluid">
        <a href="http://www.josvanriswick.com/images/apple-pear-stilllife_400.jpg">


        <div class="img-container rellax" data-rellax-speed="-4">
            <img class="section-img rellax" data-rellax-speed="-6" src="http://www.cashartblog.com/wp-content/uploads/2012/09/peppers7.jpg">
            <polygon points="345.606,107.5 324.394,128.713 418.787,223.107 0,223.107 0,253.107 418.787,253.107 324.394,347.5   345.606,368.713 476.213,238.106 " fill="#FFFFFF">
        </polygon></div>
        <div class="title-card-flex">
            <h1 class="class-study-title"> <span class="">Test Post Nietzsche</span></h1>
            <p class="blog-summary"><span>War spirit strong sexuality will play right deceptions noble prejudice noble derive chaos. Burying disgust contradict passion overcome. Chaos play evil reason hope of overcome oneself pinnacle spirit enlightenment. Will ascetic ubermensch holiest superiority sea selfish pious law. Overcome selfish chaos snare convictions truth deceptions snare reason. Self noble salvation insofar god christian joy marvelous. […]</span></p>


        </div>

            </a>
    </section>

<section class=" blog-post-section container-fluid">
        <a href="http://www.josvanriswick.com/images/apple-pear-stilllife_400.jpg">


        <div class="img-container rellax" data-rellax-speed="-4">
            <img class="section-img rellax" data-rellax-speed="-6" src="http://www.cashartblog.com/wp-content/uploads/2012/09/peppers7.jpg">
            <polygon points="345.606,107.5 324.394,128.713 418.787,223.107 0,223.107 0,253.107 418.787,253.107 324.394,347.5   345.606,368.713 476.213,238.106 " fill="#FFFFFF">
        </polygon></div>
        <div class="title-card-flex">
            <h1 class="class-study-title"> <span class="">Test Post Nietzsche</span></h1>
            <p class="blog-summary"><span>War spirit strong sexuality will play right deceptions noble prejudice noble derive chaos. Burying disgust contradict passion overcome. Chaos play evil reason hope of overcome oneself pinnacle spirit enlightenment. Will ascetic ubermensch holiest superiority sea selfish pious law. Overcome selfish chaos snare convictions truth deceptions snare reason. Self noble salvation insofar god christian joy marvelous. […]</span></p>


        </div>

            </a>
    </section>


<section class=" blog-post-section container-fluid">
        <a href="http://www.josvanriswick.com/images/apple-pear-stilllife_400.jpg">


        <div class="img-container rellax" data-rellax-speed="-4">
            <img class="section-img rellax" data-rellax-speed="-6" src="http://www.cashartblog.com/wp-content/uploads/2012/09/peppers7.jpg">
            <polygon points="345.606,107.5 324.394,128.713 418.787,223.107 0,223.107 0,253.107 418.787,253.107 324.394,347.5   345.606,368.713 476.213,238.106 " fill="#FFFFFF">
        </polygon></div>
        <div class="title-card-flex">
            <h1 class="class-study-title"> <span class="">Test Post Nietzsche</span></h1>
            <p class="blog-summary"><span>War spirit strong sexuality will play right deceptions noble prejudice noble derive chaos. Burying disgust contradict passion overcome. Chaos play evil reason hope of overcome oneself pinnacle spirit enlightenment. Will ascetic ubermensch holiest superiority sea selfish pious law. Overcome selfish chaos snare convictions truth deceptions snare reason. Self noble salvation insofar god christian joy marvelous. […]</span></p>


        </div>

            </a>
    </section>


<section class=" blog-post-section container-fluid">
        <a href="http://www.josvanriswick.com/images/apple-pear-stilllife_400.jpg">


        <div class="img-container rellax" data-rellax-speed="-4">
            <img class="section-img rellax" data-rellax-speed="-6" src="http://www.cashartblog.com/wp-content/uploads/2012/09/peppers7.jpg">
            <polygon points="345.606,107.5 324.394,128.713 418.787,223.107 0,223.107 0,253.107 418.787,253.107 324.394,347.5   345.606,368.713 476.213,238.106 " fill="#FFFFFF">
        </polygon></div>
        <div class="title-card-flex">
            <h1 class="class-study-title"> <span class="">Test Post Nietzsche</span></h1>
            <p class="blog-summary"><span>War spirit strong sexuality will play right deceptions noble prejudice noble derive chaos. Burying disgust contradict passion overcome. Chaos play evil reason hope of overcome oneself pinnacle spirit enlightenment. Will ascetic ubermensch holiest superiority sea selfish pious law. Overcome selfish chaos snare convictions truth deceptions snare reason. Self noble salvation insofar god christian joy marvelous. […]</span></p>


        </div>

            </a>
    </section>


<section class=" blog-post-section container-fluid">
        <a href="http://www.josvanriswick.com/images/apple-pear-stilllife_400.jpg">


        <div class="img-container rellax" data-rellax-speed="-4">
            <img class="section-img rellax" data-rellax-speed="-6" src="http://www.cashartblog.com/wp-content/uploads/2012/09/peppers7.jpg">
            <polygon points="345.606,107.5 324.394,128.713 418.787,223.107 0,223.107 0,253.107 418.787,253.107 324.394,347.5   345.606,368.713 476.213,238.106 " fill="#FFFFFF">
        </polygon></div>
        <div class="title-card-flex">
            <h1 class="class-study-title"> <span class="">Test Post Nietzsche</span></h1>
            <p class="blog-summary"><span>War spirit strong sexuality will play right deceptions noble prejudice noble derive chaos. Burying disgust contradict passion overcome. Chaos play evil reason hope of overcome oneself pinnacle spirit enlightenment. Will ascetic ubermensch holiest superiority sea selfish pious law. Overcome selfish chaos snare convictions truth deceptions snare reason. Self noble salvation insofar god christian joy marvelous. […]</span></p>


        </div>

            </a>

section.blog-post-section {
      width: 100%;
      position: relative;
      min-height: 450px;
      overflow: hidden;
      z-index: 2000;
      padding: 0px;
      box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);


      a {
        height: 100%;
        width: 100%;
        text-decoration: none;
        z-index: 5000;
        cursor: pointer !important;
        display: flex;
        flex: 1;


        div.overlay {
          position: absolute;
          z-index: 3000;
          width: 100%;
          height: 100%;
          box-shadow: rgba(0, 0, 0, 0.8) 3px 3px 10px inset;
          background: linear-gradient(rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.5));

        }
        //end overlay container

        div.img-container {
          position: absolute;
          display: flex;
          min-width: 50%;
          min-height: 100%;
         display: flex;
         justify-content: center;
          align-items: center;

          img.section-img {
            position: relative;
            min-width: 100%;
            min-height: calc(100% + 200px);
            z-index: 2000 !important;
            filter: blur(2px);
            top: -100px;
            right: 0;
            margin: 0 auto;

          }
          svg {
            float: right;
            background-color: black;
          }

        }


        //end image container

        div.title-card-flex {
          padding: 50px;
          position: absolute;
          height: 100%;
          width: calc(50% - 100px);
          flex-direction: column;
          justify-content: left;
          align-items: flex-start;
          z-index: 4000;
          background: white;

          h1 {
            position: relative;

            background-color: black;
            font-family: 'AllerBold', Arial, sans-serif;
            color: white;
            text-align: left;
            text-shadow: 0 2px 2px rgba(0, 0, 0, .35);
            max-width: 90vw;
            margin: 50px 10px 25px 50px;
            padding: 10px;
            z-index: 4000;
            user-select: none;
            cursor: pointer !important;
            font-size: 3.5vmax;
            font-size: 25px;

          }

          p.blog-summary {
            display: block;
            position: relative;
            padding: 5px;
            margin: 25px 10px 45px 50px;
            font-family: 'Aller', Arial, sans-serif;
            color: white;
            text-align: left;
            text-shadow: 0 2px 2px rgba(0, 0, 0, .35);
            z-index: 4000;
            user-select: none;
            cursor: pointer !important;
            line-height: 1.4;
            font-size: 18px;
            margin-bottom: 10px;

            span {
              background-color: black;
              box-shadow: 0.2em 0 0 rgba(black, 1), -0.2em 0 0 rgba(black, 1);
              display: inline;
            }

          }

          //svg {
          //  float: right;
          //  background-color: black;
          //}

        }
      }
    }

    section.blog-post-section:nth-child(even)  {
    div.img-container{
      right: 0px;


    }
    }

    section.blog-post-section:nth-child(odd) {
      div.title-card-flex {
        right: 0px;


      }
    }
Aslan French
  • 520
  • 2
  • 6
  • 23
  • What is your actual question? Which element should be centered? What have you tried? – actc Dec 01 '17 at 08:59
  • What exactly are you trying to center? And should it be *horizontally* or *vertically* centered? – UncaughtTypeError Dec 01 '17 at 09:01
  • @actc I'm trying to center the image inside of the image container. The problem is that it's centering based on the entire page and not based on the image container which should be containing it. – Aslan French Dec 01 '17 at 18:38
  • @UncaughtTypeError As I'm using justifycontent and align items center, I thought it would be communicated that I was trying to center both, but I should have been more explicit. It seems that I should have put more explanation into my original post. Sorry for the lack of clarity. – Aslan French Dec 01 '17 at 18:38
  • You're right, there are many posts on this website about how to center something using flexbox, both horizontally and vertically, and each post has several different answers on average. There is no possible way to ask a question about how to center something with CSS properties available today that has not already been answered a dozen times here. As for your situation, you haven't provided an MCVE anyway, so even if you did come up with a novel question, it hasn't been asked properly. – TylerH Dec 01 '17 at 20:00
  • To provide you at least a bit of direction, your svg image is the full width of your page, so you need to shrink it to half the page if you want it to be centered on each side. The text div is simply sitting on top of it rather than beside it. – TylerH Dec 01 '17 at 20:01
  • FYI here's a minimal repro of your setup https://codepen.io/anon/pen/EbGqar – TylerH Dec 01 '17 at 20:12
  • Just so I know for the future because I am a designer who is learning to code, my code pen and the code I provided didn't qualify as MVCE? I actually ended up figuring it out with some help for Yordan down below I ended up going with a div with a image background. I haven't yet tested it with my parallax library but I think it should work. I'm actually surprised how good the solution ended up working and it didn't even need flexbox – Aslan French Dec 01 '17 at 22:15

1 Answers1

1
/*
 * hor align
 */
align-items: center;
/*
 * vertical align
 */
justify-content: center

Maybe you want something like this.

https://codepen.io/dakata911/pen/QOzQoj

Yordan Ramchev
  • 340
  • 4
  • 14
  • Yes that is what I want in effect, but I'm trying to avoid using the background url css solution since that doesn't gel well with the WP post field system. I think I may end up using this solution thought because I'm kind of at my wits end. – Aslan French Dec 01 '17 at 18:33
  • https://codepen.io/dakata911/pen/QOzQoj?editors=1100 fix ---> its using image tag :) – Yordan Ramchev Dec 01 '17 at 18:52
  • Oh sweet, thank you Yordan, this is a much more elegant solution than what I was trying to do. Also it looks object-fit now has decent browser support! – Aslan French Dec 01 '17 at 19:03
  • Actually looks like object fit won't work for me for a couple of reasons. Main problem is that the object-fit: fill will squash the image, while the object-fit:contain will not show the image at it's full size and allow for overflow, which is even more of a problem since I'm adding parallax to these. Dang, well it was a good try! – Aslan French Dec 01 '17 at 19:14
  • Okay actually maybe cover will work. Still not sure how it will interact with parallax though. – Aslan French Dec 01 '17 at 19:17
  • I think with background image in css is the better solution. – Yordan Ramchev Dec 01 '17 at 19:23
  • Background image doesn't work with parallax. Though... maybe I could replace the img with a div, and then set the background url with cover, and have the parallax act on the div. – Aslan French Dec 01 '17 at 19:51
  • Hey Yordan, just wanted to let you know, you were right. The image background solution worked great. Thanks! – Aslan French Dec 01 '17 at 22:15