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>
Related
The problem is shown in this GIF:
https://gifyu.com/image/B5nC
I'm using Bootstrap 5 to have a carousel inside a card. Although the images are shown properly, the card resizes as the images change. I want to prevent that and have a constant size for all the images.
Here's the relevant code:
<div class="col">
<div class="card h-100">
<div class="card-img-top w-100">
<div id="carouselExampleControls" class="carousel slide >
<div class="carousel-inner">
<div class="carousel-item active
<img src="1.png" class="d-block w-100 " alt="..." >
</div>
<div class="carousel-item active
<img src="2.png" class="d-block w-100 " alt="..." >
</div>
<div class="carousel-item active
<img src="3.png" class="d-block w-100 " alt="..." >
</div>
</div>
<Button stuff, not so important...>
</div>
</div>
<div class="card-body">
<h5 class="card-title">a title</h5>
<p class="card-text">Some text.</p>
</div>
<div class="card-footer">
Some Text here.
</div>
</div>
</div>
Any ideas?
What you'd want to do, is add a fixed height or width to the image.
Add some css to the img tag. With that you can adjust the height of the image and center the image.
Something like so:
.carousel img {
height: 220px;
width: 100%;
object-fit: cover;
object-position: center;
}
The object-fit: cover; makes it so that the image will fit and not being stretched out. With object-position: center; it centers the image of the view. In this case it centers image on the height of 220px.
Here's a working example: https://www.codeply.com/p/y86ZKljAZS
This question already has answers here:
How to overlay images
(11 answers)
Closed 3 years ago.
I have a container that has an image and on top of that image a button, but inside the container some "extra" space was created, at the right. I need to remove this extra space because its taking too much space. 3 horizontal images are aligned at the center, all while using a flex display. Using bootstrap.
There are no sizes in width or height, it is only the image behind this button.
<br>
<h1 class="text-center">¿Qué temas te interesan?</h1>
<div class="row justify-content-around">
<div class="d-flex align-content-center flex-wrap container-img-intereses">
<br> <img src="/btn-desarrollo-ing.png" width="350px"/>
<button type="button" class="btn btn-primary" id="wrapper-button">Carreras</button>
</div>
<div class="d-flex align-content-center flex-wrap">
<a href="#"> <br>
<img src="/btn-diseno-ux.png" width="350px"/></a>
</div>
<div class="d-flex align-content-center flex-wrap">
<a href="#"><br>
<img src="/btn-mkt.png" width="350px"/></a>
</div>
</div>
<div class="row justify-content-around">
<div class="d-flex align-content-center flex-wrap">
<a href="#"> <br>
<img src="/btn-negocios.png" width="350px"/></a>
</div>
<div class="d-flex align-content-center flex-wrap">
<a href="#"> <br>
<img src="/btn-comunidad.png"width="350px"/></a>
</div>
<div class="d-flex align-content-center flex-wrap">
<a href="#"> <br>
<img src="/btn-produccion-aud.png"width="350px"/></a>
</div>
</div>
<br>
<div class="d-flex justify-content-center flex-wrap">
<img src="/btn-crecimiento-prof.png"width="350px"/>
</div>
.container-img-intereses {
border: 1px solid black;
display: inline-flex;
align-items: center;
text-align: center;
}
.container-img-intereses > img {
position: absolute;
z-index: -1;
}
.btn {
right: 80px;
top: 40px;
position: relative;
z-index: 1;
}
https://imgur.com/a/JEo68bF i have to repeat this and make it into a process so a button is always on top of these rectangles.
Actually if you need to show the button up the image you are using position relative to button. So button will be take it's width.
Position relative: If you set to position relative, elements take up the same amount of space at the same exact position it was supposed to take as if its position was static.It can however, appear to be pushed to a different location visually. So that's why it's taking sapce around the image.
Position absolute: Position absolute takes the document out of the document flow. This means that it no longer takes up any space like what static and relative does.
So You need to add position absolute on button and position relative to it's container container-img-intereses
Not sure this works for you since it isn't clear what you want to do with that button. You could give the parent div a position of relative and make the button absolutely positioned with the div, and then adjust your HTML and CSS accordingly, see Snippet:
.container-img-intereses {
display: inline-flex;
align-items: center;
text-align: center;
position: relative;
}
.container-img-intereses>img {
position: absolute;
z-index: -1;
}
.btn {
position: absolute;
left: 50%;
bottom: 0px;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha256-YLGeXaapI0/5IgZopewRJcFXomhRMlYYjugPLSyNjTY=" crossorigin="anonymous" />
<h1 class="text-center">¿Qué temas te interesan?</h1>
<div class="row justify-content-around">
<div class="d-flex align-content-center flex-wrap container-img-intereses">
<img src="/btn-desarrollo-ing.png" width="350px" />
<button type="button" class="btn btn-primary" id="wrapper-button">Carreras</button>
</div>
<div class="d-flex align-content-center flex-wrap">
<img src="/btn-diseno-ux.png" width="350px" />
</div>
<div class="d-flex align-content-center flex-wrap">
<img src="/btn-mkt.png" width="350px" />
</div>
</div>
<div class="row justify-content-around">
<div class="d-flex align-content-center flex-wrap">
<img src="/btn-negocios.png" width="350px" />
</div>
<div class="d-flex align-content-center flex-wrap">
<img src="/btn-comunidad.png" width="350px" />
</div>
<div class="d-flex align-content-center flex-wrap">
<img src="/btn-produccion-aud.png" width="350px" />
</div>
</div>
<br>
<div class="d-flex justify-content-center flex-wrap">
<img src="/btn-crecimiento-prof.png" width="350px" />
</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 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>
I am struggling with creating a responsive image gallery. I am using CSS and bootstrap, i tried with tag and as background, I couldnt get it to work.
so, this is what I want to achieve:
https://www.socialprintstudio.com/products/
image grid without image warp or overlapping
When you make your browser smaler, image aspect ratio stays the same, only the size changes and later on you get 2 per row, that I can do with col-lg-4 col-md-6 etc...
I would also prefer if I could do this with img tag as I think it is easier to fade one image to another on hover.
this is my HTML
<div class="item " data-categoryid="2">
<div class="item-image">
<div class="img-bg" style="background: url("http://laravel.dev/images/bon2.jpg"); display: none;"></div>
<div class="img-bg" style="background: url("http://laravel.dev/images/bon.jpg");"></div>
</div>
<div class="item-name">Some name</div>
<div class="item-price">price €</div>
<div class="item-button">
Button.
</div>
</div>
As you said, using bootstrap's .col classes is the way to go here:
Here's a resizable jsfiddle: https://jsfiddle.net/aL1ndzgg/1/
Images, by default, will keep their aspect ratio, unless you specify both the width and the height.
For the hover effect you can have only one of the images for each box set as as position: absolute;; that way, the other image will set the size of the box.
.single-image-container {
margin-bottom: 20px;
position: relative;
}
.single-image-container img {
width: 100%;
}
.blocker {
position: relative;
overflow: hidden;
}
.hover-image {
position: absolute;
top: 0;
left: 0;
opacity: 0;
transition: opacity 125ms ease-in-out;
}
.single-image-container:hover .hover-image {
opacity: 1;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-xs-6 col-md-4 single-image-container">
<div class="blocker">
<img src="http://placehold.it/400x400" alt="img">
<img class="hover-image" src="http://placehold.it/400x400/f00" alt="img2">
</div>
</div>
<div class="col-xs-6 col-md-4 single-image-container">
<div class="blocker">
<img src="http://placehold.it/400x400" alt="img">
<img class="hover-image" src="http://placehold.it/400x400/f00" alt="img2">
</div>
</div>
<div class="col-xs-6 col-md-4 single-image-container">
<div class="blocker">
<img src="http://placehold.it/400x400" alt="img">
<img class="hover-image" src="http://placehold.it/400x400/f00" alt="img2">
</div>
</div>
<div class="col-xs-6 col-md-4 single-image-container">
<div class="blocker">
<img src="http://placehold.it/400x400" alt="img">
<img class="hover-image" src="http://placehold.it/400x400/f00" alt="img2">
</div>
</div>
<div class="col-xs-6 col-md-4 single-image-container">
<div class="blocker">
<img src="http://placehold.it/400x400" alt="img">
<img class="hover-image" src="http://placehold.it/400x400/f00" alt="img2">
</div>
</div>
</div>
</div>
To make your images responsive add the following CSS:
.item img {
max-width: 100%;
width: 100%;
height: auto;
}
So as long as the image source is square the image will resize to its bootstrap grid
You can also try the following: CSS Tricks: Responsive Images