Austin Howard
Austin Howard

Reputation: 1124

Bootstrap card, stretch to all be the same size

I am using owl-carousel and bootstrap cards to make a rotating table of different cards to display in my webpage, the only problem I am having is that all of the cards are not equal in terms of height. i want them to have a sense of uniformity that way when i place more carousels later on its more streamlined and looks more professional. below i have included the snippet for the html, css, and javascript as well as an image of what im seeing. i realize this is likely to do somewhere in the CSS, but i cannot figure out how to get all of the cards to be the same height. in the image below note that of the cards presented 2 "look" to be of the same height but are not. depending on what is actually in the body is what makes the height apparently. in an earlier version of the webpage, i was able to acheive this, but now I cannot

I am also attaching a copy of the live webpage in which the original code resides. Please no comments on the design of the actual webpage. i am trying to develop a live resume for myself. I am only attaching the page so you can see what the code looked like before. and the look i am trying to acheive. In the webpage you can see that all of the card bodies are of the same height which is what im trying to replicate. any help greatly appreciated.

cards of differing height

$(".owl-carousel").owlCarousel({
   responsiveClass: true,
   dots: true,
   dotsContainer: false,
      loop: true,
      autoWidth: false,
     autoplay:true,
     nav:true,
     smartSpeed:1000,
     items:5,
     responsive: {
       0: {
          items:1,
          // margin: 150,
          center: true

          },

       768: {
            items:1,
            // margin:200,
            center: false
            },

       992: {
            items:2,
            // margin: 35,
            center: true
            },

       1200: {
             items:3,
             // margin:250,
             center: true
             },

                  },
 });
/* *****************Project Cards ************************ */
.projectTitle{
  color: #cdac81;
  margin-top: 4rem;
  text-align: center;
  font-size: 3rem;
}
.card{
  opacity: .90;
  background-color: #00303f;
  color: #cdac81;
  border-style: inset;
  border-color: #cdac81;
  border-width: 5px;
  border-radius: 1%;
}
.card-text{
  text-align: left;
  color: #cdac81;
}
.card-image{
  align-self: center;
  width: 90%;
}
.card-title, .card-body{
  text-align: center;
}
.card-body{
  
}
.projectCarousel{
  height: 62.5rem;
}
.projectCol{
  width:auto;
  height: auto;
}
.projectName{
  font-family: serif;
  font-size: 1.25rem;
}
#projectHeader{
  font-family: serif;
  text-align: center;
  font-size: 100px;
}
.owl-carousel{
  height: 62.5rem;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>projects</title>

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
    rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1"
    crossorigin="anonymous">

    <!-- Bootstrap Scripts -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>

    <!-- Style Sheets -->
    <link rel="stylesheet" href="css/styles.css">
    <link href ="https://cdn.boomcdn.com/libs/owl-carousel/2.3.4/assets/owl.carousel.min.css" rel="stylesheet" type="text/css">

</head>
  <body>
    <div class="container-fluid">
      <nav class="navbar fixed-top navbar-dark bg-dark">

        <a class="navbar-brand" href="#"></a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
          <ul class="navbar-nav">
            <li class="nav-item">
              <a class="nav-link active" aria-current="page" href="index.html">Home</a>
            </li>
            <li class="nav-item">
              <a class="nav-link active" href="Resume.html">Resume</a>
            </li>
            <li class="nav-item">
              <a class="nav-link active" href="Projects.html">Projects</a>
            </li>
            <li class="nav-item">
              <a class="nav-link disabled" href="skills.html" tabindex="-1" aria-disabled="true">skills</a>
            </li>
          </ul>
        </div>

      </nav>
    </div>

    <div class="container-fluid projectCarousel">
      <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12">
          <h1 class="projectTitle">Projects</h1>
        </div>
      </div>
      <!-- <div class="row pRow"> -->
        <!-- <div class="col-lg-4 col-md-6"> -->
          <div class="owl-carousel">
            <!-- <div class="row"> -->
              <div class="projectCol col-lg-4 col-md-6 col-sm-12">
                <div class="card">
                  <img class="card-image"src="Images\TipCalculator.png" class="card-img-top" alt="TipCalculator">
                  <div class="card-body">
                    <h2 class="card-title">Tip Calculator</h2>
                    <p class = "card-title">- Completed -</p>
                    <ul class="card-text">
                      <li>The calculator takes the amount of the bill, and the amount of people splitting the bill,
                        applies a 15% tip and displays to the user the amount each should be paying equally.</li>
                      <li>Uses the tkinter kit to display a simple GUI</li>
                      <ul>
                        <li>Python</li>
                      </ul>
                    </ul>
                    <a href="documents\Tip_calculator.py" class="btn btn-outline-light">Take a look at the code!</a>
                 </div>
                </div>
              </div>


            <div class="projectCol col-lg-4 col-md-6 col-sm-12">
              <div class="card">
                <img class="card-image" src="Images\TinDogPic.png" class="card-img-top" alt="TinDog">
                <div class="card-body">
                  <h2 class="card-title">Tindog</h2>
                  <p class = "card-title">- Completed -</p>
                  <ul class="card-text">
                    <li>This is a project that was part of a coding bootcamp as an introductory to Web Design</li>
                    <li>A spoof on the Website known as <a href="https://tinder.com/">tinder</a>... but for dogs. Enjoy</li>
                    <li>The website is meant as a one-page construction with no actual usage but to teach basic, to intermediate
                      bootstrap principles and techniques.</li>
                      <ul>
                        <li>Bootstrap, HTML, CSS</li>
                      </ul>
                    </ul>
                    <a href="Projects/TinDog/index.html" class="btn btn-primary">Go to the Site</a>
                </div>
              </div>
            </div>

            <div class="projectCol col-lg-4 col-md-6 col-sm-12">
              <div class="card">
                <img class="card-image" src="Images\diceGameImage.png" class="card-img-top" alt="DiceGame">
                <div class="card-body">
                  <h2 class="card-title">Dice Game Challenge</h2>
                  <p class = "card-title">- Completed -</p>
                  <ul class="card-text">
                    <li>This is a project that was part of a coding bootcamp as an introductory to Web Design</li>
                    <li>the website generates a random number from 1-6 for two sets of dice</li>
                    <li>the webiste then uses javascript to change to the appropriate image and display a winner</li>
                    <ul>
                      <li>javascript, HTML, CSS</li>
                    </ul>
                  </ul>
                  <a href="Projects\DiceChallenge\dicee.html" class="btn btn-primary">Go to the Site</a>
                </div>
              </div>
            </div>
              <div class="projectCol col-lg-4 col-md-6 col-sm-12">
                <div class="card">
                  <img class="card-image" src="Images\DrumKit.png" class="card-img-top" alt="DrumKit">
                  <div class="card-body">
                    <h2 class="card-title">Drum Kit</h2>
                    <p class = "card-title">- Completed -</p>
                    <ul class="card-text">
                      <li>This is a project that was part of a coding bootcamp as an introductory to Web Design</li>
                      <li>the website teaches foundations of event listeners, and adding audio to a webpage</li>
                      <li>it looks for keystrokes as well as a click to interpret what sound needs to be played</li>
                      <ul>
                        <li>javascript, HTML, CSS</li>
                      </ul>
                    </ul>
                    <a href="Projects\Drum Kit Starting Files\index.html" class="btn btn-primary">Go to the Site</a>
                  </div>
               </div>
             </div>
             <div class="projectCol col-lg-4 col-md-6 col-sm-12">
               <div class="card">
                 <img class="card-image" src="Images\SimonSays.png" class="card-img-top" alt="DrumKit">
                 <div class="card-body">
                   <h2 class="card-title">Simon Says</h2>
                   <p class = "card-title">- Completed -</p>
                   <ul class="card-text">
                     <li>This is a project that was part of a coding bootcamp as an introductory to Web Design</li>
                     <li>the website teaches foundations of using jQuery to perform the bulk of the background work
                       needed to play the game.</li>
                     <li>The game show's simons move's and allows the user to input in sequence the same moves.
                       if the user inputs an incorrect move a game over event will trigger.</li>
                     <ul>
                       <li>jQuery, HTML, CSS</li>
                     </ul>
                   </ul>
                   <a href="Projects\Simon\index.html" class="btn btn-primary">Demo!</a>
                 </div>
               </div>
             </div>
           </div>
         </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js" integrity="sha256-pTxD+DSzIwmwhOqTFN+DB+nHjO4iAsbgfyFq5K5bcE0=" crossorigin="anonymous"></script>
    <script src="index.js" charset="utf-8"></script>
  </body>
</html>

Upvotes: 1

Views: 823

Answers (1)

terrymorse
terrymorse

Reputation: 7096

This code will set all card heights to the maximum height found:

  // set height of all cards to max height

  // get array of all '.card' elements
  const cards = Array.from(document.querySelectorAll('.card'));

  // form array of card element heights (offsetHeight)
  const cardHeights = cards.map(card => card.offsetHeight);

  // find the maximum value of cardHeights array
  const maxCardHeight = Math.max(...cardHeights);

  // set all card `height` styles to `maxCardHeight`
  cards.forEach(card => {
    card.style.height = maxCardHeight + 'px';
  });

Upvotes: 3

Related Questions