0

I have a review slider. when there is a lot of content, I have no problem centering the content cause it is automatic, however, when there is not a lot of content, I need it to vertically center. I do know how to vertically center a single element, but not a few elements at once. any suggestions? this is my code:

jQuery(document).ready(function($){
    var $slickElement = $('.slideshowdesktop');

    $slickElement.slick({
      autoplay: true,
      dots: false,
    });

});
    *{
  outline:none;
}
/* spacer */


/* spacer ends */

/* slider styles */
.sd_master_wrapperdesktop{
    position: relative; 
    max-width:900px;
    margin:0 auto;
    padding:0;
    border-radius:10px;
    z-index:9999;
    
}


.sd_scrolldesktop {
    height: auto;
    max-height: 220px;
    overflow: hidden;
}
    
.slideshowdesktop {
    position: relative;
    min-height: 350px;
    height: auto;
    background: #transparent;
    box-shadow: 0px 18px 52.8537px rgba(215, 228, 249, 0.5);
    border-radius: 20px;
    
    background-position: top 15px left 15px, bottom 40% right 15px;
    background-repeat: no-repeat;
    background-size: 180px, 180px;
    z-index:3;
    border:3px solid white;
}
button.slick-prev.slick-arrow {
    position: absolute;
    z-index: 9999;
top:170px;
left:-100px;
opacity:0;

}
button.slick-next.slick-arrow {
    position: absolute;
    z-index:9999;
    top:190px;
    left:940px;
}
.pagingInfodesktop {
    position: absolute;
    bottom: 0;
    z-index: 999;
}
.sdCustomSliderHeadigdesktop {
    color: #fff;
    font-family: "Poppins", Sans-serif;
    font-size: 15px;
    font-weight: 400;
    line-height: 1.6em;
    text-align: center;
}
.sdCustomSliderBtndesktop{
    display: inline-block;
    text-decoration: none;
    font-family: montserrat;
    background: #E31C3A;
    color: #fff;
    padding: 12px 25px;
    margin-top: 30px;
    border-radius: 4px;
    outline: none;
    font-size: 14px;
    font-weight: 500;
}
.sdAllContentdesktop{
    width:75%;
    margin:auto;
    
}


.thumbnaildesktop img {
    height: 100px;
    width: 100px;
    border-radius: 50%;
    margin: auto;
    margin-top: 15px;
}
.contentdesktop{
    display:block !important;
    padding: 5px;

}
.SdClientNamedesktop {
    text-align: center;
    color: #fff;
    font-family: Arial;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.4em;
   
    
    
}
.SdClientDescdesktop {
    text-align: center;
    color: #fff;
    font-family: Arial;
    font-size: 14px;
    line-height: 1.4em;
    
    
    
}


/* style for moblile */
@media (max-width:576px){
.sd_scrolldesktop {
    height: auto;
    overflow: auto;
    max-height:240px;
}

.thumbnaildesktop, .btnNtxtdesktop{
    width: 100% !important;
    display: block !important;
}

}
/* scroll bar */
/* total width */
.sd_scroll::-webkit-scrollbar {
    background-color:transparent;
    width:6px;
}

/* background of the scrollbar except button or resizer */
.sd_scrolldesktop::-webkit-scrollbar-track {
    background-color:transparent;
}
.sd_scrolldesktop::-webkit-scrollbar-track:hover {
    background-color:transparent;
}

/* scrollbar itself */
.sd_scrolldesktop::-webkit-scrollbar-thumb {
    background-color:#babac0;
    border-radius:16px;
    
}
.sd_scrolldesktop::-webkit-scrollbar-thumb:hover {
    background-color:#a0a0a5;
}
<link href='https://fonts.googleapis.com/css?family=Poppins' rel='stylesheet'>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css"/>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js"></script>





<div class="sd_master_wrapperdesktop">  
    
    <div class="slideshowdesktop">
        
        <div class="contentdesktop"> <!-- slide 1 -->
         <div class="vertical-center">
            <div class="thumbnaildesktop">
                <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ7IgpAYUDwQpHDMrkOEDmx1am8kOznnFEQ11tbCa3aI8938q37GSK3mpgMjHHwGi2l8PM&usqp=CAU"> 
            </div>
            <div class="btnNtxtdesktop"> 
                <div class="sdAllContentdesktop"> 
                    
                    <div class="sd_scrolldesktop">
                    <h1 class="sdCustomSliderHeadigdesktop">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</h1> 
                    </div>
                    <p class="SdClientNamedesktop"><strong>Company's name</strong></p>
                    <p class="SdClientDescdesktop"><strong>Client's name</strong></p>
                </div>
            </div>
        </div>
    </div>  
        <div class="contentdesktop"> <!-- slide 2 -->
            <div class="thumbnaildesktop">
                <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ7IgpAYUDwQpHDMrkOEDmx1am8kOznnFEQ11tbCa3aI8938q37GSK3mpgMjHHwGi2l8PM&usqp=CAU"> 
            </div>
            <div class="btnNtxtdesktop"> 
                <div class="sdAllContentdesktop"> 
                    
                    <div class="sd_scrolldesktop">
                    <h1 class="sdCustomSliderHeadigdesktop">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</h1> 
                    </div>
                    <p class="SdClientNamedesktop"><strong>company's name</strong></p>
                    <p class="SdClientDescdesktop"><strong>client name</strong></p>
                </div>
            </div>
        </div>
    

    
        
        
    </div>
</div>  
<div class="spacerdesktop"></div>
Aman
  • 1,502
  • 1
  • 8
  • 13
John Makati
  • 81
  • 2
  • 8
  • use `flexbox` and `align-items`: `.parent { display: flex; align-items: center; }` alterntivly: `.parent { display: flex; flex-direction: column; justify-content: center; }` – tacoshy Aug 05 '21 at 11:16
  • Do i create another div that contains all of the content? or do I use flex and align items in any certain class? – John Makati Aug 05 '21 at 11:20
  • @tacoshy could you please help me? i have been trying for days now and still dont know how to do it. – John Makati Aug 05 '21 at 11:51
  • you use an element (dont have to be a div) that wraps all the other elements. Then you apply `{display: flex; flex-direction: coulmn; justify-content: center; }` to the wrapping div. However note, that the wrapping element needs a height that is larger then all the content combined: https://codepen.io/tacoshy/pen/eYWLqXO – tacoshy Aug 05 '21 at 13:17
  • @tacoshy i dont know why it is not working, I have applied what you said to the "content" class. could you take a look and tell me whats wrong? https://codepen.io/nmahtani/pen/QWvqXNj – John Makati Aug 05 '21 at 15:04
  • because it has no defined height. As such the height will be calculated to exactly fit the content. To vertical align elements within the `contentdesktop` class, that element needs to be larger then the content itself. – tacoshy Aug 05 '21 at 15:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/235662/discussion-between-john-makati-and-tacoshy). – John Makati Aug 05 '21 at 15:51
  • @tacoshy i opened a chat – John Makati Aug 05 '21 at 15:56

0 Answers0