html - Changing div's order with CSS with dynamic height, text vertical align middle -


here's html code:

<ul>   <li>     <div class="imgbox"><img 1></div>     <div class="txtbox">text 1</div>   </li>   <li>     <div class="imgbox"><img 2></div>     <div class="txtbox">text 2</div>   </li>   <li>     <div class="imgbox"><img 3></div>     <div class="txtbox">text 3</div>   </li>   <li>     <div class="imgbox"><img 4></div>     <div class="txtbox">text 4</div>   </li> <ul> 

the expected result in desktop is:

_____________________ |  img 1  |  txt 1  | _____________________ |  txt 2 |   img2   | _____________________ |  img 3  |  txt 3  | _____________________ |  txt 4  |  img 4  | _____________________ 

each block width:50%, images width:100% box, auto height; text in middle of box, display:table-cell; text-align:center; vertical-align:middle;

and expected result on mobile is:

___________ |  img 1  | ___________ |  txt 1  | ___________  |  img 2  | ___________ |  txt 2  | ___________  |  img 3  | ___________ |  txt 3  | ___________  |  img 4  | ___________ |  txt 4  | ___________ 

everything width:100% page

if set display:flex li, can change order of row's, however, don't find way make text box 100% height, text align center. https://jsfiddle.net/wesleywai/phcgmopo/10/

if use display:table lia nd display:table-cell div, can make 100% height native table cell don't find way change order: https://jsfiddle.net/wesleywai/amm5mmvm/2/

i've tried direction: rtl; , direction: ltr; , doesn't seem working on case.

please help.

drop height: 100% on div rule

you can drop vertical-align:middle; since has no effect in case, , if want vertical center text, added new rule

.txtbox {   display:flex;   justify-content: center;   align-items: center; } 

ul{    display:block;    margin:0;    padding:0;  }  li{    display:flex;    width:100%;    height:auto;  }  div{    display:block;    width:50%;    text-align:center;    background:#fcc;  }  .txtbox {    display:flex;    justify-content: center;     /*  horizontal - when flex row */    align-items: center;         /*  vertical   - when flex row */  }  li:nth-child(even) .imgbox{    order:2;  }  img{    width:100%;    height:auto;    display:block;  }  @media screen , (max-width: 68px) {    li{      display:block;    }    div{      width:100%     }    .txtbox{      padding:20px;      width:calc(100% - 40px);    }  }
<ul>    <li>      <div class="imgbox">        <img src='https://images.pexels.com/photos/27714/pexels-photo-27714.jpg?h=350&auto=compress'>      </div>      <div class="txtbox">        flower 1      </div>    </li>    <li>      <div class="imgbox">        <img src='https://images.pexels.com/photos/132419/pexels-photo-132419.jpeg?h=350&auto=compress'>      </div>      <div class="txtbox">        flower 2      </div>    </li>    <li>      <div class="imgbox">        <img src='https://images.pexels.com/photos/103573/pexels-photo-103573.jpeg?h=350&auto=compress'>      </div>      <div class="txtbox">        flower 3      </div>    </li>    <li>      <div class="imgbox">        <img src='https://images.pexels.com/photos/132474/pexels-photo-132474.jpeg?w=940&h=650&auto=compress&cs=tinysrgb'>      </div>      <div class="txtbox">        flower 4      </div>    </li>  </ul>


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -