Button under images or on the images *ngFor loop - css

From *ngFor loop I can populate images but I want to add a button below the image or on the image. I'm not familiar with CSS below is my code.
Html code
<div class="container">
<div *ngFor="let img of imageData">
<p [hidden]="true">{{img.Id}}</p>
<img class="original" [alt]="img.Name"
src="https://localhost:44349/{{img.ImagePath}}"
width="350" height="350"/>
<button type="submit" (click)="deleteImage()" class="btn btn-danger"><i
class="far fa-trash-alt"></i>
Remove
</button>
</div>
</div>
CSS
.container {
position: relative;
text-align: center;
}
.original {
width: 250px;
height: 250px;
float: left;
margin: 1.66%;
transition-duration: 0.3s;
border-radius: 15px;
}

Hope this is what you are looking for.
.container {
/* position: relative;*/
text-align: center;
display: flex;
flex-direction: column;
}
.original {
width: 250px;
height: 250px;
float: left;
margin: 1.66% auto;
transition-duration: 0.3s;
border-radius: 15px;
}
.content {
display: flex;
flex-direction: column;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<div class="container">
<div class="content">
<p>Image Id</p>
<img class="original" src="https://www.w3schools.com/bootstrap/cinqueterre.jpg" width="350" height="350" />
<button type="submit" class="btn btn-danger"><i class="far fa-trash-alt"></i>
Remove
</button>
</div>
<div class="content">
<p>Image Id</p>
<img class="original" src="https://www.w3schools.com/bootstrap/cinqueterre.jpg" width="350" height="350" />
<button type="submit" class="btn btn-danger"><i class="far fa-trash-alt"></i>
Remove
</button>
</div>
</div>
For angular with dynamic image your template will be like.
<div class="container">
<div class="content" *ngFor="let img of imageData">
<p [hidden]="true">{{img.Id}}</p>
<img class="original" src="https://localhost:44349/{{img.ImagePath}}" width="350" height="350" />
<button type="submit" class="btn btn-danger"><i class="far fa-trash-alt"></i>
Remove
</button>
</div>
</div>

Related

how to overlap images CSS and make them look cut?

so im doing a front end challenge and basically i gotta do this and half way through images to move the images but i cant seem to make the cut/overlap
```
:root {
--clr-bggrad-violet: hsl(273, 75%, 66%);
--clr-bggrad-blue: hsl(240, 73%, 65%);
--clr-text-dark: hsl(238, 29%, 16%);
--clr-text-red: hsl(14, 88%, 65%);
--clr-divider: hsl(240, 5%, 91%);
--ff-kumbh: 'Kumbh Sans', sans-serif;
}
/* "*" helps the code to be vieweble on all broswers */
/* Box sizing rules */
*,
*::before,
*::after {
box-sizing: border-box;
}
/* Remove default margin */
* {
margin: 0;
padding: 0;
}
body {
min-height: 100vh;
text-rendering: optimizeSpeed;
line-height: 1.5;
font-family: var(--ff-kumbh);
font-weight: 400;
font-size: 0.8rem;
color: var(--clr-text-dark);
display: flex;
flex-flow: column nowrap;
align-items: center;
justify-content: center;
background: linear-gradient(var(--clr-bggrad-violet), var(--clr-bggrad-blue));
}
main {
position: relative;
background: url(images/bg-pattern-mobile.svg) no-repeat top center;
background-color: white;
display: flex;
flex-flow: column nowrap;
align-items: center;
border-radius: 1rem;
padding: 1rem;
width: 100%;
margin-bottom: 1rem;
box-shadow: 0 10px 40px -15px var(--clr-text-dark);
}
.title {
padding: 1rem;
margin: 1rem;
font-weight: 700;
}
/* Make images easier to work with */
img,
picture {
max-width: 100%;
height: auto;
display: block;
}
.hero-images {
width: 100%;
height: 100%;
display: flex;
flex-flow: column nowrap;
align-items: center;
margin-bottom: 7rem;
}
.hero {
position: absolute;
top: -7rem;
width: min(80%, 255px);
}
.box {
display: none;
}
#media (min-width: 900px) {
main {
width: 870px;
display: grid;
grid-template-columns: 50% 50%;
background-image: unset;
background-color: white;
padding: 0;
}
.hero-images {
position: relative;
display: flex;
align-items: flex-start;
justify-content: flex-start;
background-image: url(images/illustration-woman-online-desktop.svg),
url(images/bg-pattern-desktop.svg);
background-repeat: no-repeat;
background-size: 90%, 120%;
background-position: -4.8rem 5rem, -12rem -2rem;
margin: unset;
}
.box {
width: 150px;
position: absolute;
display: unset;
top: 12rem;
left: -5.5rem;
z-index: 1;
}
.hero {
display: none;
}
}
```
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Kumbh+Sans:wght#400;700&display=swap" rel="stylesheet" />
<link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png" />
<link rel="stylesheet" href="style.css" />
<title>Frontend Mentor | FAQ Accordion Card</title>
</head>
<body>
<main>
<picture class="box">
<img src="images/illustration-box-desktop.svg" alt="TheBox" aria-hidden="true" />
</picture>
<section class="hero-images">
<picture class="hero">
<source media="(max-width: 900px)" srcset="images/illustration-woman-online-mobile.svg"
alt="you see this first" />
<img src="images/illustration-woman-online-desktop.svg" alt="ShrinkUseeThis" aria-hidden="true" />
</picture>
</section>
<section>
<h1 class="title">FAQ</h1>
<div>
<button class="btn dropBtn" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample"
aria-expanded="false" aria-controls="collapseExample">
How many team members can I invite?<img src="images/icon-arrow-down.svg" alt="IconArrow" aria-hidden="true" />
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
You can invite up to 2 additional users on the Free plan. There is
no limit on team members for the Premium plan.
</div>
</div>
</div>
<div>
<button class="btn dropBtn" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample"
aria-expanded="false" aria-controls="collapseExample">
What is the maximum file upload size?<img src="images/icon-arrow-down.svg" alt="IconArrow"
aria-hidden="true" />
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
No more than 2GB. All files in your account must fit your allotted
storage space.
</div>
</div>
</div>
<div>
<button class="btn dropBtn" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample"
aria-expanded="false" aria-controls="collapseExample">
How do I reset my password?<img src="images/icon-arrow-down.svg" alt="IconArrow" aria-hidden="true" />
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
Click “Forgot password” from the login page or “Change password”
from your profile page. A reset link will be emailed to you.
</div>
</div>
</div>
<div>
<button class="btn dropBtn" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample"
aria-expanded="false" aria-controls="collapseExample">
Can I cancel my subscription?<img src="images/icon-arrow-down.svg" alt="IconArrow" aria-hidden="true" />
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
Yes! Send us a message and we’ll process your request no questions
asked.
</div>
</div>
</div>
<div>
<button class="btn dropBtn" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample"
aria-expanded="false" aria-controls="collapseExample">
Do you provide additional support?<img src="images/icon-arrow-down.svg" alt="IconArrow" aria-hidden="true" />
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
Chat and email support is available 24/7. Phone lines are open
during normal business hours.
</div>
</div>
</div>
<p>
<a class="btn btn-primary" data-bs-toggle="collapse" href="#multiCollapseExample1" role="button"
aria-expanded="false" aria-controls="multiCollapseExample1">Toggle first element</a>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#multiCollapseExample2"
aria-expanded="false" aria-controls="multiCollapseExample2">Toggle second element</button>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target=".multi-collapse"
aria-expanded="false" aria-controls="multiCollapseExample1 multiCollapseExample2">Toggle both
elements</button>
</p>
<div class="row">
<div class="col">
<div class="collapse multi-collapse" id="multiCollapseExample1">
<div class="card card-body">
Some placeholder content for the first collapse component of this multi-collapse example. This panel is
hidden by default but revealed when the user activates the relevant trigger.
</div>
</div>
</div>
<div class="col">
<div class="collapse multi-collapse" id="multiCollapseExample2">
<div class="card card-body">
Some placeholder content for the second collapse component of this multi-collapse example. This panel is
hidden by default but revealed when the user activates the relevant trigger.
</div>
</div>
</div>
</div>
</section>
</main>
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.11.6/dist/umd/popper.min.js"
integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/js/bootstrap.min.js"
integrity="sha384-IDwe1+LCz02ROU9k972gdyvl+AESN10+x7tBKgc9I5HFtuNz0wWnPclzo6p9vxnk"
crossorigin="anonymous"></script>
</body>
</html>
```
i have tried to use krita and just crop and upload the images as one but it loses resolution(it looks pixelated).i have been thinking using the bodyBG and make that a png but the white box is there in the middle.
edit2: so the images were in .svg couldnt uploaded to imgur so i have to change it to .png i think i might have scramble the snippet cuz the images are everywhere sorry it is my first time doing this XD. also i tried the left: -15%;width: 50%;height: auto; and nothing happen
this is what i see on my computer:
compu
edit3: so i found out about content-visibility CSS and i am trying to see that instead of a cut i will try to make the image half invisible
edit4: so it was "picture" HTML i found a guy that use it on the challenge i cant find him anymore and i still dont understand how is making the cut butt it works sooooo whatever thx anyway

Make the images same size in grid card

I made some card using grid and flexbox for the content. The image is not the same size each cards. I use the display grid for the wrapper and flexbox for the card content. I tried to use flex-grow and flex-basis in the trackcard_header class, but nothing works. I attach the sample of my code result below, please take a look to the snippet too.
Here is the screenshot:
And this is my snippet:
.createpl_card_wrapper {
margin-top: 2rem;
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-column-gap: 2rem;
grid-row-gap: 1rem;
}
.trackcard {
display: flex;
flex-direction: column;
justify-content: space-between;
border-radius: 1rem;
background-color: rgba(0, 0, 0, 0.2);
width: 100%;
padding: 1rem 0.5rem;
position: relative;
}
.trackcard_header {
width: 80%;
margin: auto;
}
.trackcard_header img {
max-width: 100%;
height: auto;
border-radius: 1rem;
}
.trackcard_body {
padding: 1rem;
flex-grow: 1;
text-align: center;
}
.trackcard_body h2 {
font-size: 1.5rem;
}
.trackcard_body h4 {
font-size: 1rem;
}
.trackcard_footer {
width: 80%;
margin: auto;
}
.trackcard_btn {
width: 100%;
padding: 0.25rem 0;
background-color: #1db954;
border-radius: 0.5rem;
border: 1px solid #1db954;
color: #fff;
}
.trackcard_btn:hover {
background-color: #18a349;
}
<!DOCTYPE html>
<html>
<head>
<title>Parcel Sandbox</title>
<meta charset="UTF-8" />
</head>
<link rel="stylesheet" href="./src/styles.css" />
<body>
<div class="createpl_card_wrapper">
<div class="trackcard">
<div class="trackcard_header">
<img
src="https://i.scdn.co/image/ab67616d0000b2738c0defcb336a0296eb7d704a"
alt="name"
/>
</div>
<div class="trackcard_body">
<h2>GANADARA (Feat. IU)</h2>
<h4>
Jay Park - GANADARA
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
<div class="trackcard">
<div class="trackcard_header">
<img
src="https://i.scdn.co/image/ab67616d0000b273c63be04ae902b1da7a54d247"
alt="name"
/>
</div>
<div class="trackcard_body">
<h2>eight(Prod.&Feat. SUGA of BTS)</h2>
<h4>
IU - eight
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
<div class="trackcard">
<div class="trackcard_header">
<img
src="https://i.scdn.co/image/ab67616d0000b27315cf3110f19687b1a24943d1"
alt="name"
/>
</div>
<div class="trackcard_body">
<h2>Good day</h2>
<h4>
IU - REAL
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
<div class="trackcard">
<div class="trackcard_header">
<img
src="https://i.scdn.co/image/ab67616d0000b2734ed058b71650a6ca2c04adff"
alt="name"
/>
</div>
<div class="trackcard_body">
<h2>Celebrity</h2>
<h4>
IU - IU 5th Album 'LILAC'
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
<div class="trackcard">
<div class="trackcard_header">
<img
src="https://i.scdn.co/image/ab67616d0000b273a1d785640d9421ec17ea8fe6"
alt="name"
/>
</div>
<div class="trackcard_body">
<h2>BBIBBI</h2>
<h4>
IU - BBIBBI
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
</div>
<script src="src/index.js"></script>
</body>
</html>
I want to make the images is in the same size, both vertically and horizontally. Could anyone give me solution? Thank you in advance.
You need to give the divs an actual size, in your code, they only have % values and no parent static value to take the %age out of. I've given the .trackcard class a width of 30vw. In order to make the images square, you also need to give it a height that's not dependent on other height values, but have the same value as the width, so I gave it a placeholder of 24vw which is 80% of the .trackcard. You need to use object-fit: contain to not stretch. You can refer to the docs I linked and use the one you prefer.
.createpl_card_wrapper {
margin-top: 2rem;
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-column-gap: 2rem;
grid-row-gap: 1rem;
}
.trackcard {
display: flex;
flex-direction: column;
justify-content: space-between;
border-radius: 1rem;
background-color: rgba(0, 0, 0, 0.2);
width: 30vw;
padding: 1rem 0.5rem;
position: relative;
}
.trackcard_header {
width: 80%;
margin: auto;
}
.trackcard_header img {
width: 24vw;
height: 24vw;
object-fit: contain;
border-radius: 1rem;
}
.trackcard_body {
padding: 1rem;
flex-grow: 1;
text-align: center;
}
.trackcard_body h2 {
font-size: 1.5rem;
}
.trackcard_body h4 {
font-size: 1rem;
}
.trackcard_footer {
width: 80%;
margin: auto;
}
.trackcard_btn {
width: 100%;
padding: 0.25rem 0;
background-color: #1db954;
border-radius: 0.5rem;
border: 1px solid #1db954;
color: #fff;
}
.trackcard_btn:hover {
background-color: #18a349;
}
<!DOCTYPE html>
<html>
<head>
<title>Parcel Sandbox</title>
<meta charset="UTF-8" />
</head>
<link rel="stylesheet" href="./src/styles.css" />
<body>
<div class="createpl_card_wrapper">
<div class="trackcard">
<div class="trackcard_header">
<img
src="https://i.scdn.co/image/ab67616d0000b2738c0defcb336a0296eb7d704a"
alt="name"
/>
</div>
<div class="trackcard_body">
<h2>GANADARA (Feat. IU)</h2>
<h4>
Jay Park - GANADARA
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
<div class="trackcard">
<div class="trackcard_header">
<img
src="https://i.scdn.co/image/ab67616d0000b273c63be04ae902b1da7a54d247"
alt="name"
/>
</div>
<div class="trackcard_body">
<h2>eight(Prod.&Feat. SUGA of BTS)</h2>
<h4>
IU - eight
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
<div class="trackcard">
<div class="trackcard_header">
<img
src="https://i.scdn.co/image/ab67616d0000b27315cf3110f19687b1a24943d1"
alt="name"
/>
</div>
<div class="trackcard_body">
<h2>Good day</h2>
<h4>
IU - REAL
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
<div class="trackcard">
<div class="trackcard_header">
<img
src="https://i.scdn.co/image/ab67616d0000b2734ed058b71650a6ca2c04adff"
alt="name"
/>
</div>
<div class="trackcard_body">
<h2>Celebrity</h2>
<h4>
IU - IU 5th Album 'LILAC'
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
<div class="trackcard">
<div class="trackcard_header">
<img
src="https://i.scdn.co/image/ab67616d0000b273a1d785640d9421ec17ea8fe6"
alt="name"
/>
</div>
<div class="trackcard_body">
<h2>BBIBBI</h2>
<h4>
IU - BBIBBI
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
</div>
<script src="src/index.js"></script>
</body>
</html>
That can be achieved with some JavaScript.
First you select all the elements with querySelectorAll. You then make an array of its height with offsetHeight. Math.max returns the largest sum of the input parameter.
In a for loop, you can set the elements minHeight with Math.max. It keeps looping until it finds the length and then applies the styling. Keep in mind this will apply the height of the largest image as min-height on all of your images.
And while we're at it, I did the same thing for the h2-elements, so they're aligned equally in all the cards. I separated the JS so it is easier to read and understand. The only gotcha is you have to reload the page if you drag the screen size, as the min-height will be a bit off.
As for CSS I used grid-template-columns: repeat(5, minmax(200px, 1fr)); instead. This way there will always be 5 columns that are atleast 200px wide, so they have an equal size. If you want a responsive effect, just edit the 5 out with auto-fit, this way they will wrap on smaller screens.
Like so:
grid-template-columns: repeat(5, minmax(auto-fit, 1fr));
If you want to change the width or height of your images, I suggest using max-width and max-height for a responsive effect. If you don't change the width, they will look a bit stretched.
You can apply object-fit: cover; on the images also, this way the image won't be stretched, but a bit of the image will be cut off instead.
I hope this helps you!
Snippet below will not work properly, check Codepen: https://codepen.io/sigurdmazanti/pen/qBpLGXe
let img = document.querySelectorAll(".trackcard_header img");
let text = document.querySelectorAll(".trackcard_body h2");
// Image
let imgLength = Array.from(img).map(e => e.offsetHeight);
let maxLength = Math.max(...imgLength);
// H2
let textLength = Array.from(text).map(e => e.offsetHeight);
let maxTextLength = Math.max(...textLength);
// Image for loop
for (let i = 0; i < img.length; i++) {
img[i].style.minHeight = maxLength + "px";
}
// H2 for loop
for (let i = 0; i < text.length; i++) {
text[i].style.minHeight = maxTextLength + "px";
}
.createpl_card_wrapper {
margin-top: 2rem;
display: grid;
/*grid-template-columns: repeat(5, 1fr); */
grid-template-columns: repeat(5, minmax(200px, 1fr));
grid-column-gap: 2rem;
grid-row-gap: 1rem;
}
.trackcard {
display: flex;
flex-direction: column;
justify-content: space-between;
border-radius: 1rem;
background-color: rgba(0, 0, 0, 0.2);
width: 100%;
padding: 1rem 0.5rem;
position: relative;
}
.trackcard_header {
width: 80%;
margin: auto;
}
.trackcard_header img {
max-width: 100%;
height: auto;
border-radius: 1rem;
/* Consider this */
object-fit: cover;
}
.trackcard_body {
padding: 1rem;
flex-grow: 1;
text-align: center;
}
.trackcard_body h2 {
font-size: 1.5rem;
}
.trackcard_body h4 {
font-size: 1rem;
margin-top: auto;
}
.trackcard_footer {
width: 80%;
margin: auto;
}
.trackcard_btn {
width: 100%;
padding: 0.25rem 0;
background-color: #1db954;
border-radius: 0.5rem;
border: 1px solid #1db954;
color: #fff;
}
.trackcard_btn:hover {
background-color: #18a349;
}
<!DOCTYPE html>
<html>
<head>
<title>Parcel Sandbox</title>
<meta charset="UTF-8" />
</head>
<link rel="stylesheet" href="./src/styles.css" />
<body>
<div class="createpl_card_wrapper">
<div class="trackcard">
<div class="trackcard_header">
<img src="https://i.scdn.co/image/ab67616d0000b2738c0defcb336a0296eb7d704a" alt="name" />
</div>
<div class="trackcard_body">
<h2>GANADARA (Feat. IU)</h2>
<h4>
Jay Park - GANADARA
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
<div class="trackcard">
<div class="trackcard_header">
<img src="https://i.scdn.co/image/ab67616d0000b273c63be04ae902b1da7a54d247" alt="name" />
</div>
<div class="trackcard_body">
<h2>eight(Prod.&Feat. SUGA of BTS)</h2>
<h4>
IU - eight
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
<div class="trackcard">
<div class="trackcard_header">
<img src="https://i.scdn.co/image/ab67616d0000b27315cf3110f19687b1a24943d1" alt="name" />
</div>
<div class="trackcard_body">
<h2>Good day</h2>
<h4>
IU - REAL
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
<div class="trackcard">
<div class="trackcard_header">
<img src="https://i.scdn.co/image/ab67616d0000b2734ed058b71650a6ca2c04adff" alt="name" />
</div>
<div class="trackcard_body">
<h2>Celebrity</h2>
<h4>
IU - IU 5th Album 'LILAC'
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
<div class="trackcard">
<div class="trackcard_header">
<img src="https://i.scdn.co/image/ab67616d0000b273a1d785640d9421ec17ea8fe6" alt="name" />
</div>
<div class="trackcard_body">
<h2>BBIBBI</h2>
<h4>
IU - BBIBBI
</h4>
</div>
<div class="trackcard_footer">
<button type="button" class="trackcard_btn">
Select
</button>
</div>
</div>
</div>
<script src="src/index.js"></script>
</body>
</html>

Bootstrap vertically push to the bottom

html
<div class="container">
<div id="movies" class="well">
<div class="col-md-3">
<div class="well text-center">
<img src="#">
<h5>title</h5>
<a class="btn btn-primary" href="#">Detail</a>
</div>
</div>
<div class="col-md-3">
<div class="well text-center">
<img src="#">
<h5>title</h5>
<a class="btn btn-primary" href="#">Detail</a>
</div>
</div>
</div>
</div>
css
#movies img, #movie img{
width: 100%;
}
#media(min-width:960px){
#movies .col-md-3 .well{
height: 390px;
}
#movies .col-md-3 img{
height: 240px;
}
}
img As you can see in the image, the Detail buttons are not in the same horizontal line. I would like to push the first one down.
You can use flexbox to achieve this. Try this (View it in "full page" mode).
#movies img, #movie img {
width: 100%;
}
#media(min-width:960px) {
#movies .col-md-3 .well {
height: 350px;
display: flex;
flex-direction: column;
align-items: center;
}
#movies .col-md-3 img {
height: 240px;
}
#movies .btn {
margin-top: auto;
}
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<div class="container">
<div id="movies" class="row well">
<div class="col-md-3">
<div class="well text-center">
<img src="https://via.placeholder.com/260">
<h5>Qui minim nulla veniam.</h5>
<a class="btn btn-primary" href="#">Detail</a>
</div>
</div>
<div class="col-md-3">
<div class="well text-center">
<img src="https://via.placeholder.com/260">
<h5>Ut reprehenderit cillum occaecat sint voluptate</h5>
<a class="btn btn-primary" href="#">Detail</a>
</div>
</div>
</div>
</div>

Flexbox adjust height of the img after div rotate

Here is my codepen : https://codepen.io/Johngtrs/pen/oNWLYEw
When I click on the rotate button the div img container rotate, but the image overlap on the other row.
How it's possible to adjust the height of the img if needed ?
CSS:
.row-documents {
display: flex;
flex-direction: row;
align-items: center;
}
.row-documents img {
width: 615px;
}
.img-document {
transition: all 0.3s ease;
}
.rotate-button {
margin: 0 10px;
width: 50px;
display: flex;
justify-content: center;
}
HTML:
<div>
<div class="row-documents">
<div class="img-document">
<img src="https://picsum.photos/1300/740" class="img-responsive">
</div>
<div class="rotate-button">
<button class="btn btn-default btn-rotate">
Rotate
</button>
</div>
<div class="img-document">
<img src="https://picsum.photos/1300/740" class="img-responsive">
</div>
<div class="rotate-button">
<button class="btn btn-default btn-rotate">
Rotate
</button>
</div>
</div>
<hr />
<div class="row-documents">
<div class="img-document">
<img src="https://picsum.photos/1300/740" class="img-responsive">
</div>
<div class="rotate-button">
<button class="btn btn-default btn-rotate">
Rotate
</button>
</div>
<div class="img-document">
<img src="https://picsum.photos/1300/740" class="img-responsive">
</div>
<div class="rotate-button">
<button class="btn btn-default btn-rotate">
Rotate
</button>
</div>
</div>
</div>
For the moment you cannot do this with Css only
you can check if your image is on the portrait format and change height of the parent when it is so
$('.btn-rotate').on('click', function () {
let $img = $(this).parent().prev();
let width = $img.width();
let height = $img.height();
let angle = ($img.data('angle') + 90) || 90;
let scale = height < width ? height / width : width / height;
if (angle % 180) {
$img.css({'transform': 'rotate(' + angle + 'deg) scale('+ scale +')'});
$img.data('angle', angle);
}
else {
$img.css({'transform': 'rotate(' + angle + 'deg) scale(1)'});
$img.data('angle', angle);
}
})
.row-documents {
display: flex;
flex-direction: row;
align-items: center;
}
.row-documents img {
max-width: 215px;
max-height: 200px;
}
.img-document {
transition: all 0.3s ease;
transform-origin: center center;
display: flex;
justify-content: center;
}
.rotate-button {
margin: 0 10px;
width: 50px;
display: flex;
justify-content: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div>
<div class="row-documents">
<div class="img-document">
<img src="https://picsum.photos/1300/740" class="img-responsive">
</div>
<div class="rotate-button">
<button class="btn btn-default btn-rotate">
Rotate
</button>
</div>
<div class="img-document">
<img src="https://picsum.photos/740/1300" class="img-responsive">
</div>
<div class="rotate-button">
<button class="btn btn-default btn-rotate">
Rotate
</button>
</div>
</div>
<hr />
<div class="row-documents">
<div class="img-document">
<img src="https://picsum.photos/1300/740" class="img-responsive">
</div>
<div class="rotate-button">
<button class="btn btn-default btn-rotate">
Rotate
</button>
</div>
<div class="img-document">
<img src="https://picsum.photos/1300/740" class="img-responsive">
</div>
<div class="rotate-button">
<button class="btn btn-default btn-rotate">
Rotate
</button>
</div>
</div>
</div>

Button Class Get not the full length of div?

I have tried to give the full length of div . But button could not get the full length . Please help me to fix out the errors.
<div class="col-md-3 col-sm-6 text-center card">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
<span class="icon">
<img src="{{ URL::asset('frontAssets/assets/images/classroutine1.png')}}"
alt="Classroutine" style="width:50%;
height: 93.3px; padding-top: 15px; padding-bottom: 25px">
</span>
<div style=" padding-bottom: 10px; padding-top: 20px">
<h3>Class <br> Routine</h3>
</div>
</button>
</div>
Try to update css:
.card {
padding-right: 0px;
padding-left: 0px;
}
.block {
display: block;
width: 100%;
}
And the button has already taken full width of parent div, if you want to make div wider, try to adjust bootstrap column size, for example col-md-3 to col-md-6:
<div class="col-md-6 col-sm-6 text-center card">
Because in bootstrap, the column have padding-right: 15px; and padding-left: 15px; by default. So if you want your button to get the full width of the column, you can overwrite these css or add the css below to your button:
Demo:
.block {
margin-right: -15px;
margin-left: -15px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="col-md-3 col-sm-6 text-center card">
<button type="button" class="block" data-toggle="modal" data-target="#myModal">
<span class="icon">
<img src="{{ URL::asset('frontAssets/assets/images/classroutine1.png')}}"
alt="Classroutine" style="width:50%;
height: 93.3px; padding-top: 15px; padding-bottom: 25px">
</span>
<div style=" padding-bottom: 10px; padding-top: 20px">
<h3>Class <br> Routine</h3>
</div>
</button>
</div>
Use display: inline-block in both "span" and next "div" tag.
Remove padding to the column div:
.card{ padding:0px}
Here is the snippet:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
.card{ padding:0px}
</style>
</head>
<body>
<script src="script.js"></script>
<div class="col-md-3 col-sm-6 text-center card">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
<span class="icon">
<!-- <img src="{{ URL::asset('frontAssets/assets/images/classroutine1.png')}}"
alt="Classroutine" style="width:50%;
height: 93.3px; padding-top: 15px; padding-bottom: 25px"> -->
</span>
<div style=" padding-bottom: 10px; padding-top: 20px">
<h3>Class <br> Routine</h3>
</div>
</button>
</div>
</body>
</html>
All Bootstrap columns (.col-*) have padding-x (padding-right: 15px; and padding-left: 15px;) by default.
If the button is the only child element of that column, and you don't want to override the class's styles, you can use the px-0 or p-0 class on the column to override the padding of only that column:
<div class="col-md-3 col-sm-6 text-center card px-0">
...
</div>
<div class="col-md-3 col-sm-6 text-center card">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal" style="width:100%">
<span class="icon">
<img src="{{ URL::asset('frontAssets/assets/images/classroutine1.png')}}"
alt="Classroutine" style="width:50%;
height: 93.3px; padding-top: 15px; padding-bottom: 25px">
</span>
<div style=" padding-bottom: 10px; padding-top: 20px">
<h3>Class <br> Routine</h3>
</div>
</button>
</div>
Use width:100% as style or add it in any class and then apply that class to the button
Just use padding zero .
<div class="col-md-3 col-sm-6 text-center card px-0" style="padding: 0px ">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#classRoutine" style="width:100%">
<span class="icon">
<img src="{{ URL::asset('frontAssets/assets/images/classroutine1.png')}}"
alt="Classroutine" style="width:50%;
height: 93.3px; padding-top: 15px; padding-bottom: 25px">
</span>
<div style=" padding-bottom: 10px; padding-top: 20px">
<h3>Class <br> Routine</h3>
</div>
</button>
</div>

Resources