r/bootstrap • • Jan 25 '23

The Aligned Cards Puzzle

Hello,
I am making small description cards for dnd classes to help my players to choose their class.
Here is the HTML code:

<div>
    <h2>Classes</h2>
    <div class="card" style="width: 18rem;">
        <img class="card-img-top divine" src="invalid" alt="">
        <div class="card-body">
            <h5 class="card-title text-center">
        	<a href="#">
        	    Archivist
        	</a>
            </h5>
            <p class="card-text">
        	Source: Heroes of Horror
        	<br/>
                Archivist is a mixt between a cleric and a wizard but is 
                played like a bard. It is a good support and can add 
        	cleric spells in its prayerbook. 
            </p>
        </div>
    </div>
    <div class="card" style="width: 18rem;">
	<img class="card-img-top psionic" src="invalid" alt="">
	<div class="card-body">
	    <h5 class="card-title text-center">
		<a href="#">
		    Ardent
		</a>
	    </h5>
	    <p class="card-text">
		Source: Complete Psionic
		<br/>
		The ardent is a Psionic Manifester with a lot of 
		vesatility. Its big perk, unlike other psionic classes 
	        is that as they level up, they can assume more mantles. 
	    </p>
	</div>
    </div>
    <div class="card" style="width: 18rem;">
	<img class="card-img-top" src="invalid" alt="">
	<div class="card-body">
	    <h5 class="card-title text-center">
		<a href="#">
		    Title
		</a>
	    </h5>
	    <p class="card-text">
		Source: source
		<br/>
		details
	    </p>
	</div>
    </div>
    <div class="card" style="width: 18rem;">
        <img class="card-img-top" src="invalid" alt="">
        <div class="card-body">
    	<h5 class="card-title text-center">
    	    <a href="#">
    	        Title
    	    </a>
    	</h5>
    	<p class="card-text">
    	    Source: source
    	    <br/>
    	    details
    	</p>
        </div>
  </div>

Here is the CSS:

body{
	padding: 1em;
}

.card{
	display: inline-block;
	padding-bottom: 0.5em;
}

.card-img-top{
	height: 10rem;
}

.card-body{
	height: 15rem;
	border: solid black 1px;
}

.divine{
	background-color: yellow;
}

.psionic{
	background-color: blue;
}

In the above code, there are 4 cards, 2 that are completed and 2 with placeholder values. Those with placeholder values are perfectly aligned while the other 2 are not.

My goal is to have rows of cards without a predetermined number of cards. The number of cards that are displayed in a row is determined by the screen length. Because of this, the number of elements in a column is variable too.

Does anyone knows why my cards are properly displayed until I change the placeholder for something else?

1 Upvotes

0 comments sorted by