This question already has answers here:
Bootstrap - align button to the bottom of card
(9 answers)
Closed 4 years ago.
Using Bootstrap 4, I have created a card-deck with two cards. Although both cards are the same height, elements are not in the same spot due to the length of text from other elements.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="card-deck">
<div class="card" style="margin-top: 0px">
<div class="card-body">
<a>
<img class="card-img" src="{{banner.FeatureImage0.Url}}" alt="Card image cap" style="width:200px; height: 132.531; float: right; margin-left:10px;">
</a>
<h5 class="card-title">Get to Know...FirstName LastName</h5>
<p class="card-text" style="margin-bottom: 20px;">In this interview we feature FirstName LastName, Community Relations and Social Responsibility Officer, Executive Vice President.</p>
<a class="btn btn-primary" style="color:white !important;">Read More</a>
</div>
</div>
<div class="card" style="margin-top: 0px">
<div class="card-body">
<a>
<img class="card-img" src="{{banner.FeatureImage0.Url}}" alt="Card image cap" style="width:200px; height: 132.531; float: right; margin-left:10px;">
</a>
<h5 class="card-title">Questions are more important than answers - August ethics message</h5>
<p class="card-text" style="margin-bottom: 20px;">The August ethics message comes from FirstName LastName, Wisconsin Region CEO.</p>
<a class="btn btn-primary" style="color:white !important;">Read More</a>
</div>
</div>
</div>
How can I make sure my "Read More" buttons are aligned with each other?
You can use d-flex flex-column to make the card-body flex-direction column, and then mt-auto (margin-top:auto) to push the buttons to the bottom of each card...
<div class="container">
<div class="card-deck">
<div class="card" style="margin-top: 0px">
<div class="card-body d-flex flex-column align-items-start">
<a>
<img class="card-img" src="{{banner.FeatureImage0.Url}}" alt="Card image cap" style="width:200px; height: 132.531; float: right; margin-left:10px;">
</a>
<h5 class="card-title">Get to Know...FirstName LastName</h5>
<p class="card-text" style="margin-bottom: 20px;">In this interview we feature FirstName LastName, Community Relations and Social Responsibility Officer, Executive Vice President.</p>
<a class="btn btn-primary mt-auto" style="color:white !important;">Read More</a>
</div>
</div>
<div class="card" style="margin-top: 0px">
<div class="card-body d-flex flex-column align-items-start">
<a>
<img class="card-img" src="{{banner.FeatureImage0.Url}}" alt="Card image cap" style="width:200px; height: 132.531; float: right; margin-left:10px;">
</a>
<h5 class="card-title">Questions are more important than answers - August ethics message</h5>
<p class="card-text" style="margin-bottom: 20px;">The August ethics message comes from FirstName LastName, Wisconsin Region CEO.</p>
<a class="btn btn-primary mt-auto" style="color:white !important;">Read More</a>
</div>
</div>
</div>
</div>
https://www.codeply.com/go/nxTqqN1uWC
This solution doesn't require altering the structure of the card as all content should remain in the card-body.
The content of your cards are not taking the same height. If you see, one of the headers take up 2 lines in a small window compared to the other. There are multiple ways to solve this. One way is to assign the width to the title and then put an ellipsis for the overflow. Similarly you can do this for the body. After controlling the height of everything before the button, your content will then align.
For ellipsis:
p {
width: 200px;
white-space: nowrap;
overflow: hidden;
display: inline-block;
text-overflow: ellipsis;
border: 1px solid #ddd;
margin: 0;
}
Card already has a flex so you may have to add a "text container" to padd the bottom (the button height plus some extra margin: like 2.5rem) and make the button positioned absolute to card-body bottom (same distance/size as the card-body margin : 1.5rem)
.card-body {
position: relative;
}
.card-body .emp-container {
padding-bottom: 2.5rem;
}
.card-body .btn {
position: absolute;
bottom: 1.25rem;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="card-deck">
<div class="card" style="margin-top: 0px">
<div class="card-body">
<div class="emp-container">
<a>
<img class="card-img" src="https://picsum.photos/200/300" alt="Card image cap" style="width:200px; height: 132.531; float: right; margin-left:10px;">
</a>
<h5 class="card-title">Get to Know...FirstName LastName</h5>
<p class="card-text" style="margin-bottom: 20px;">In this interview we feature FirstName LastName, Community Relations and Social Responsibility Officer, Executive Vice President., Community Relations and Social Responsibility Officer, Executive Vice President., Community Relations and Social
Responsibility Officer, Executive Vice President.</p>
</div> <a class="btn btn-primary" style="color:white !important;">Read More</a>
</div>
</div>
<div class="card" style="margin-top: 0px">
<div class="card-body">
<div class="emp-container">
<a>
<img class="card-img" src="https://picsum.photos/200/300" alt="Card image cap" style="width:200px; height: 132.531; float: right; margin-left:10px;">
</a>
<h5 class="card-title">Questions are more important than answers - August ethics message</h5>
<p class="card-text" style="margin-bottom: 20px;">The August ethics message comes from FirstName LastName, Wisconsin Region CEO.</p>
</div>
<a class="btn btn-primary" style="color:white !important;">Read More</a>
</div>
</div>
</div>
Related
I am facing a problem in which I want the content which is written on the left half of the screen should be written on the image which is on the right side when decreasing the screen size.
for reference, check the image as I want this problem image
to be like this Solution image when I decrease the size of my screen, But my screen looks like this at present. I need the solution as soon as possible.
Note: I used mostly pre-defined classes of bootstrap4 for this.
code is-
<div class="row">
<div class="col p-0 col-6 bg-creame" style="height: 100vh;">
<div class="h-100 d-flex flex-column justify-content-start pt-5">
<div class="m-5 pt-5 pr-5">
<h1 class="mb-5"><b style="font-weight: 900;"><b>Contact</b></b></h1>
<p class="m-0" style="font-weight: 900;font-size: 18px;">Email Address</p>
<p><a style="color: inherit !important;font-size: 23px;" href="mailto:support#regid.ca">support#XXX.com</a>
</p>
<p class="m-0 mt-5" style="font-weight: 900;font-size: 18px;">Mailing Address</p>
<p style="font-size: 23px;">
XXXXXX, 77 XXXX XXX X,
XXXXXX, XX XXX 6XX
</p>
<div class="d-none d-lg-block">
<button class="text-uppercase btn pr-5 pl-5 color-creame bg-orange"
style="border-radius: 50px; letter-spacing: 1px;font-size: 20px;">
Contact Us
</button>
</div>
</div>
</div>
</div>
<div class="col p-0 col-6 bg-orange" style="height: 100vh;">
<div style="position: absolute; bottom: 0; right: 0;">
<div class="h-50 bg-orange d-flex flex-column justify-content-end" style="padding-top: 14rem;">
<div class="text-center p-4">
<i class="fas fa-arrow-up bg-black" style="font-size: 2rem;"></i>
</div>
</div>
</div>
<div class="d-flex flex-column h-100">
<img height="100%" width="100%" src="./assets/img/Rectangle 8 (2).png" class="img img-responsive">
</div>
</div>
</div>
You could use z-index to push the image behind the text and do something like this
#media (max-width: 600px) {
img {
width: 100%;
z-index: -1;
}
div {
z-index: 1;
}
}
I have used the following style inside the element of my html to get rid of the extra white space on the right side of the screen:
<style>
html,body{
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
overflow-x: hidden;
}
</style>
And it worked perfectly fine. However, it sets the visibility of some of the content on of the pages to be "hidden" and I have tried using the !important attribute to overwrite but no matter what I do, they remain invisible.
<div class="col-lg-3 col-md-6 wow fadeInUp" data-wow-delay="0.2s">
<div class="box">
<div class="icon"><a href=""><i>
<img class="featurette-image img-fluid mx-auto" data-src="holder.js/500x500/auto" src="/img/yusufImg/slope%20design.png" alt="Generic placeholder image">
</i></a></div>
<h4 class="title">Slope Design</h4>
<a id="slopeButton" class="btn btn-lg btn-outline-success" style="font-weight: 900;color: white;">Read More</a>
</div>
</div>
<div style=" visibility:visible !important;" class="col-lg-3 col-md-6 wow fadeInUp" data-wow-delay="0.2s">
<div class="box">
<div class="icon"><a href=""><i>
<img class="featurette-image img-fluid mx-auto" data-src="holder.js/500x500/auto" src="/img/yusufImg/taş%20duvar.png" alt="Generic placeholder image">
</i></a></div>
<h4 class="title">Tas Duvar</h4>
<a id="tasduvarButton" class="btn btn-lg btn-outline-
success" style="font-weight: 900;color: white;">Read More</a>
</div>
Ones with the inline style for visibility have the same exact attributes and classes as the ones that don't. However, they are always rendered to be invisible when I load the page.
How can I fix this?
This question already has answers here:
Bootstrap columns stacking vertically on mobile device
(2 answers)
Closed 4 years ago.
I'm trying to get content within a Bootstrap row to scale down rather than break into single columns on mobile. How would I go about this?
Here is an example of what I have so far:
<div class="row justify-content-center">
<div class="col-xs-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;>
<h2> title </h2>
<img src="" style="width:100px; height:100px;">
</a>
</div>
<div class="col-xs-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;>
<h2> title </h2>
<img src="" style="width:100px; height:100px;">
</a>
</div>
<div class="col-xs-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;>
<h2> title </h2>
<img src="" style="width:100px; height:100px;">
</a>
</div>
</div>
When I open this up on my phone, each column is displayed as a single line on the page. I'd like all three to be on the same row on mobile.
Bootstrap-4 has removed all the variants of *-xs-* classes.
col-xs- have been dropped in Bootstrap 4 in favor of col-.
So in order to have three equal width columns on all kinds of devices, use col-4 or just col instead of col-xs-4.
https://getbootstrap.com/docs/4.1/layout/grid/#grid-options
Use p-0 class instead of the inline padding style for the a tags.
https://getbootstrap.com/docs/4.0/utilities/spacing/
Use img-fluid class instead of the inline css style for the img elements to make it responsive.
https://getbootstrap.com/docs/4.0/content/images/#responsive-images
As you may know, mobile devices have less than 414px width. But the sum of the a tags' width is more than 414px. Therefore, you should use a max-width to set their maximum width and use width: 100% or w-100 also.
The max-width CSS property sets the maximum width of an element. It prevents the used value of the width property from becoming larger than the value specified by max-width. https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
In this case, since the row has exactly 12 columns, it is unnecessary to use justify-content-center. Therefore, you better remove it.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-4 p-0">
<a class="btn btn-light" style="max-width: 200px; width:100%; height: 200px;">
<h2> title </h2>
<img src="http://via.placeholder.com/100" class="img-fluid">
</a>
</div>
<div class="col-4 p-0">
<a class="btn btn-light" style="max-width: 200px; width:100%; height: 200px;">
<h2> title </h2>
<img src="http://via.placeholder.com/100" class="img-fluid">
</a>
</div>
<div class="col-4 p-0">
<a class="btn btn-light" style="max-width: 200px; width:100%; height: 200px;">
<h2> title </h2>
<img src="http://via.placeholder.com/100" class="img-fluid">
</a>
</div>
</div>
</div>
https://codepen.io/anon/pen/djWZJj
You need to make changes in your col structure. Bootstrap 4 has changed the breakpoints.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="row justify-content-center">
<div class="col-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;">
<h2> title </h2>
<img src="" style="width:100px; height:100px;">
</a>
</div>
<div class="col-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;">
<h2> title </h2>
<img src="" style="width:100px; height:100px;">
</a>
</div>
<div class="col-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;">
<h2> title </h2>
<img src="" style="width:100px; height:100px;">
</a>
</div>
</div>
More than likely this has to do with height and width of the images your using. I would suggest just using a max-height and max-width and allow the images to scale to the screen size.
<div class="row justify-content-center">
<div class="col-xs-4" style="padding:0!important;">
<a class="btn btn-light" style="width: 200px; height: 200px;>
<h2> title </h2>
<img src="" style="max-width:100px; max-height:100px;">
</a>
</div>
I am having some problem with that black box with date. I made it but it isn't responsive.
.date
{
width: 20%;
height: 15%;
background-color: black;
z-index: 1;
position: absolute;
top: 45%;
left: 8%;
}
<div class="card up" style="width:400px height:400px">
<img class="card-img-top" src="https://placehold.it/1900x1400" alt="Card image" style="width:100%">
<div class="date">
</div>
<div class="card-body">
<h4 class="card-title">John Doe</h4>
<p class="card-text">Some example text some example text. John Doe is an architect and engineer</p>
See Profile
</div>
</div>
Use position-absolute for the card-body
Put the date inside the card-body and give it negative top value.
Fixed size
.date {
width: 50px;
height: 50px;
background-color: black;
top: -25px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-6 mx-auto ">
<div class="card up" style="width:400px height:400px">
<img class="card-img-top" src="https://placehold.it/1900x1400" alt="Card image" style="width:100%">
<div class="card-body position-relative pt-5">
<div class="date position-absolute"></div>
<h4 class="card-title">John Doe</h4>
<p class="card-text">Some example text some example text. John Doe is an architect and engineer</p>
See Profile
</div>
</div>
</div>
</div>
</div>
Relative size
.date {
width: 3.8888888889em;
height: 3.8888888889em;
background-color: black;
top: -1.9em;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-6 mx-auto ">
<div class="card up" style="width:400px height:400px">
<img class="card-img-top" src="https://placehold.it/1900x1400" alt="Card image" style="width:100%">
<div class="card-body position-relative pt-5">
<div class="date position-absolute"></div>
<h4 class="card-title">John Doe</h4>
<p class="card-text">Some example text some example text. John Doe is an architect and engineer</p>
See Profile
</div>
</div>
</div>
</div>
</div>
https://codepen.io/anon/pen/gKzQez
https://css-tricks.com/almanac/properties/p/position/
You can also do this with negative margin too.
First you have to respecify the width and height of 'card' and 'up' classes (missing semicolumn).
Then with the actual code snippet i can't clearly see what is wrong, but if you have responsive problem with absolute positioning, try to add "position: relative" to your container so the absolute elements won't overflow their parent block.
Lets understand the issue of this case first. As you have added width: 100% to the image, this has a responsive height. Therefore, .card doesn't have a fix height. When you use top: 40% (percentage value), this breaks the view.
Solution;
wrap image and .date inside another div.
<div style="position: relative;">
<img class="card-img-top" src="https://placehold.it/1900x1400" style="width: 100%;" alt="Card image">
<div class="date"></div>
</div>
And, set bottom: - 20% or appropreate value instead of top: 40% for .date class.
Hope this will fix the issue.
I'm trying to create a profile page for a site I am currently working on. When viewing this in a desktop (anything above a tablet) I need it to show two cards next to each other, but there is a minimum width set due to the buttons in the card moving out of place when shrunk.
I have some empty column's on each side to pad the page out.
So I have made it so when you are in a large desktop, it pads the page out and the two cards are next to one another which is perfect.
But when I get less than 1175px, the two cards start to overlap each other, instead of this happening, I want the right card to jump right below the left card which has the profile information in it.
I have made it so it doesn't show up in mobile too, but I also want it to show with the two column's one underneath the other for mobile too.
HTML CODE:
<div class="container-fluid pcontainer">
<div class="row">
<div class="col-2 d-none d-lg-block">
test
</div>
<div class="col-4 d-none d-md-block">
<div class="card pc mw-100">
<div class="card-title">
<img class="pp card-img-top img-fluid rounded-circle" src="img/pp.jpg" alt="Card image cap">
<h4 class="pt card-title text-left text-justify"> Ryan Edwards </h4>
<button type="button" class="btn btn-sm btnp btn-outline-info">Add Friend</button>
<button type="button" class="btn btn-sm btn-outline-success">Message</button>
</div>
<div class="card-body">
<h3> My Biography: </h3>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
</div>
<div class="col-4 d-none d-md-block">
<div class="card pc mw-100">
<div class="card-title">
<img class="pp card-img-top img-fluid rounded-circle" src="img/pp.jpg" alt="Card image cap">
<h4 class="pt card-title text-left text-justify"> Ryan Edwards </h4>
<button type="button" class="btn btn-sm btnp btn-outline-info">Add Friend</button>
<button type="button" class="btn btn-sm btn-outline-success">Message</button>
</div>
<div class="card-body">
<h3> My Biography: </h3>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
</div>
<div class="col-2 d-none d-lg-block">
test
</div>
</div>
and here is the css:
.pc {
margin: 0px;
min-width:390px;
width: auto !important;
width:390px;
}
.pp {
max-width: 125px;
width: 125px;
max-height: 125px;
height: 125px;
margin-top: 40px;
margin-right: 40px;
float: right;
}
.pt {
margin-top: 50px;
margin-left: 50px;
}
.btnp {
margin-left: 50px;
}
.btn {
padding-top: 2px;
padding-bottom: 2px;
padding-left: 8px;
padding-right: 8px;
}
Have you tried to use a script tag?
You can set the distance and add a new class for your current one. Not sure if its going to help you :)
$(document).ready(() => {
$(document).scroll(() => {
if ($('.yourclass').offset().top - $(window).scrollTop() <= 25) {
if ($(window).scrollTop() < 400) {
$('.yourclass').removeClass('currentyclass');
} else {
$('.yourclass').addClass('newestclass');
}
}
})