How to make responsive cards as shown below? - html

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.

Related

How to stack bootstrap cards from horizontally to vertical in order to make it responsive?

I am using Bootstrap to evenly align horizontally two cards, but I want to make it responsive so mobile users can see both cards stacked one above the other (in a column). So far I tried adding '''flex-direction''' with the #media tag to the '''justify-content-center''' tag. I also tried removing '''text-center''', '''object-fit: contain;''' and changing all types of '''display'''.
I am kind of new to front end. Appreciate any help.
CSS:
.separado{
display: inline-block;
*display: inline; /* For IE7 */
zoom: 1; /* Trigger hasLayout */
width: 45%;
text-align: center;
margin-right: 5%;
margin-left: 5%;
margin-bottom: 3%;
}
.imagen_top3{
object-fit: contain;
max-height: 600px;
border: 5px solid #252727;
padding: 1px;
}
#media screen and (max-width: 980px) {
.list-images img {
width: 100%;
margin: 3%;
flex-direction: column;
}
.separado{
zoom: 1; /* Trigger hasLayout */
width: 100%;
text-align: center;
margin: 3%;
flex-direction: column;
}
}
HTML:
<div class="d-flex justify-content-center text-center">
<div class="card text-center separado" style="width: 40%; background-color: #252727;">
<img class="card-img-top imagen_top3" src="image1.jpeg" alt="Card image cap">
<div class="card-body">
<p class="card-text" style="color:whitesmoke">Hi im John</p>
</div>
</div>
<div class="card text-center separado" style="width: 40%;background-color: #252727;">
<img class="card-img-top imagen_top3" src="image2.jpeg" alt="Card image cap">
<div class="card-body">
<p class="card-text" style="color:whitesmoke">Hi im Peter</p>
</div>
</div>
</div>
There is no need for CSS, just use the bootstrap inbuilt grid;
<div class="row">
<div class="col-xxl-6 col-md-12">
<div class="card text-center">
<img class="card-img-top" src="https://source.unsplash.com/ewqfhcrLoYA" alt="Card image cap">
<div class="card-body">
<p class="card-text" style="color:whitesmoke">Hi im John</p>
</div>
</div>
</div>
<div class="col-xxl-6 col-md-12">
<div class="card text-center">
<img class="card-img-top" src="https://source.unsplash.com/Edz4CIdzpA8" alt="Card image cap">
<div class="card-body">
<p class="card-text" style="color:whitesmoke">Hi im Peter</p>
</div>
</div>
</div>
</div>
Remove all the CSS you provided except with the one for styling purpose.
Codepen: https://codepen.io/manaskhandelwal1/pen/rNMqYag

Centering an icon or button inside a responsive card image

I have this card which i am displaying in a page. I want the button or an icon to appear at the middle of the page and should be also be responsive not to stay at the same spot when the window is resized. This is the code so far
<div class="col-md-3 search_result">
<div class="col text-center">
<button>
Play Icon
</button>
</div>
<div class="card cw">
<img class="card-img-top" src="https://picsum.photos/534/313" alt="Card image cap">
<div class="card-footer"><span class=""></span> <a class="sr_fl" href="">Image of the pillar</a><br/>
<span class="badge badge-red">Source:</span>Pillar.com
</div>
</div>
</div>
This is the result https://jsfiddle.net/s8b0djc1/1/
How can i center the button or any element at the center of the card image?
I'm not sure what you wanted and I don't have the information on the classes you use (even if I think it's boostrap). Here is a code that could enlighten you on how to do it.
.card {
position: relative;
width: max-content;
}
.card button {
position: absolute;
z-index: 1;
top: 50%;
left: 50%;
transforme: translate(-50%, -50%);
}
<div class="col-md-3 search_result">
<div class="card cw">
<button></button>
<img class="card-img-top" src="https://picsum.photos/534/313" alt="Card image cap">
<aside class="card-footer"><span class=""></span> <a class="sr_fl" href="">Image of the pillar</a><br />
<span class="badge badge-red">Source:</span>Pillar.com
</aside>
</div>
</div>

how to make card deck and carousel overlapped

soo im trying to make a website that look like this
u can see theres a white background between my yellow background and my carousel. is there anyway to make the background behind my card deck not white instead the same color my carousel?
HTML
<div class="row-lg" id="backcolor">
<div class="card-deck mx-auto" id="card-deck">
<div class="card">
<img src="dummy.jpg" alt="dummy" class="card-img-top">
<div class="card-body" id="cardbody1">
<h5 class="card-title" id="cardtitle1">Card 1</h5>
<p class="card-text" id="cardtext1">Card text 1</p>
</div>
</div>
<div class="card">
<img src="dummy.jpg" alt="dummy" class="card-img-top">
<div class="card-body" id="cardbody2">
<h5 class="card-title" id="cardtitle2">Card 1</h5>
<p class="card-text" id="cardtext2">Card text 1</p>
</div>
</div>
<div class="card">
<img src="dummy.jpg" alt="dummy" class="card-img-top">
<div class="card-body" id="cardbody3">
<h5 class="card-title" id="cardtitle3">Card 1</h5>
<p class="card-text" id="cardtext3">Card text 1</p>
</div>
</div>
<div class="card">
<img src="dummy.jpg" alt="dummy" class="card-img-top">
<div class="card-body" id="cardbody4">
<h5 class="card-title" id="cardtitle4">Card 1</h5>
<p class="card-text" id="cardtext4">Card text 1</p>
</div>
</div>
<div class="card">
<img src="dummy.jpg" alt="dummy" class="card-img-top">
<div class="card-body" id="cardbody5">
<h5 class="card-title" id="cardtitle5">Card 1</h5>
<p class="card-text" id="cardtext5">Card text 1</p>
</div>
</div>
</div>
</div>
CSS
#card-deck {
padding-top: 190px;
height: 450px;
width: 1200px;
margin: 0 auto;
}
#card-deck .card {
padding-left: 20px;
padding-right: 20px;
max-width: 300px;
text-align: center;
}
#card-deck .card h5 {
color: orange;
}
Edit: We need to make your card container float over the two elements, because setting background-color to the card element, covers the background below it.
To do this, we need modify the #card-deck
position:relative so we could adjust its position according to its parent div
add top:30px; to position it 30px below its initial position
remove the height and padding properties as we're going to rely on the cards' height
add z-index:1 to position it over the other elements
Use this css for the #card-deck
#card-deck {
width: 1200px;
margin: 0 auto;
position:relative;
top:30px;
z-index:1;
}
Here's the updated fiddle;
https://jsfiddle.net/8y4ojb5t/
Its because you forgot # to background-color.
Your css:
#backcolor{
background-color: F1F0F0;
}
Use this:
#backcolor{
background-color: #F1F0F0;
}
Your image is cutting because of container-fluid 's padding left and right. So you have to remove that padding.
Try this css:
.container-fluid{
padding-left: 0;
padding-right: 0;
}

Issue aligning div's using width and float

So what I am trying to do is align these divs within a bootstrap card. My issue is, I am able to get the left half of it right, but I can't figure out how to align the far right elements. I am currently using width percentages to allow this to stay responsive, though I have one thing set as fixed due to pictures always being the same size.
<div class="card" style="width:65%;float:left;">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body clearfix text-center" style="width:100%;display:inline-block;background-color: aqua;">
<div class="cartimage" style="background-color:red;float:left">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="carttext" style="height:50%;width:75%;background-color:green;">
khjg
</div>
<div class="cartamt" style="height:50%;width:75%;background-color:yellow;">
amt
</div>
<div class="cartprice" style="height:50%;width:15%;background-color:purple;float:right">
price
</div>
<div class="cartbutton" style="height:50%;width:15%;background-color:pink;float:right">
button
</div>
</div>
</div>
You need to adjust the order and replace 15% with 25% to have a total of 100% per row. You need to also set a height to parent container to use % height with child element:
.rounded-circle {
border-radius:50%;
vertical-align:top;
}
<div class="card" style="width:65%;float:left;">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body clearfix text-center" style="width:100%;display:inline-block;background-color: aqua;height:140px">
<div class="cartimage" style="background-color:red;float:left">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="cartprice" style="height:50%;width:25%;background-color:purple;float:right">
price
</div>
<div class="carttext" style="height:50%;width:75%;background-color:green;">
khjg
</div>
<div class="cartbutton" style="height:50%;width:25%;background-color:pink;float:right">
button
</div>
<div class="cartamt" style="height:50%;width:75%;background-color:yellow;">
amt
</div>
</div>
</div>
By the way, since you are using Bootstrap V4 you can rely on flex to create your layout:
.rounded-circle {
border-radius: 50%;
vertical-align: top;
}
.cartprice {
background: red;
flex-basis: 75%;
}
.carttext {
background: green;
flex-basis: 25%;
}
.cartbutton {
background: blue;
flex-basis: 75%;
}
.cartamt {
background: yellow;
flex-basis: 25%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="card">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body text-center d-flex">
<div class="cartimage">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="d-flex flex-wrap w-100" >
<div class="cartprice">
price
</div>
<div class="carttext">
khjg
</div>
<div class="cartbutton">
button
</div>
<div class="cartamt">
amt
</div>
</div>
</div>
</div>
If you are using bootstrap4, I don't understand why using float...Use boostartp4 [Flex Utilities] classes instead to make these type of grid layout...Also for good practice try to wrap your divs into a wrapper divs
Stack Snippet
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="card">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body text-center p-0 d-flex no-gutters" style="background-color: aqua;">
<div class="cartimage" style="background-color:red;">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="d-flex flex-column" style="flex: 2;">
<div class="carttext col" style="background-color:green;">
khjg
</div>
<div class="cartamt col" style="background-color:yellow;">
amt
</div>
</div>
<div class="d-flex flex-column col">
<div class="cartprice col" style="background-color:purple">
price
</div>
<div class="cartbutton col" style="background-color:pink">
button
</div>
</div>
</div>
</div>

CSS: How to get this effect ? (Picture on top of a card, going outside it)

I'm fairly new to CSS, so I apologize if someone asked for this effect before, I don't know the name of it.
I need to create this (picture 1), I currently have this (picture 2):
I don't know hot to create this effect or what is the name of it.
I have tried playing with z-index and padding, but I don't think that this is the best solution.
Here is the code (for the picture 2):
<div class="row text-center">
<div class="col-lg-4">
<div class="card" style="width: 20rem;">
<img class="card-img-top" src="picture.png" alt="Card image cap">
<div class="card-block">
<h4 class="card-title">Mirion Jones</h4>
<p class="card-position">CEO Founder</p>
<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>
I am using Bootstrap 4.
Hope the code below helps. I set the image size to 60px by 60px, and set the margin and top accordingly, you should change them with your desired dimension.
.card-img-top {
position: absolute;
top: -30px;
left: 50%;
margin-left: -30px;
width: 60px !important;
height: 60px;
}
.card {
margin-top: 30px;
padding-top: 30px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
<div class="row text-center">
<div class="col-lg-4">
<div class="card" style="width: 20rem;">
<img class="card-img-top img-circle rounded-circle" src="https://dummyimage.com/100x100/000/fff" alt="Card image cap">
<div class="card-block">
<h4 class="card-title">Mirion Jones</h4>
<p class="card-position">CEO Founder</p>
<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>