Putting three images side by side and fill the parent - html

I want to have three images side by side with one condition I'm unable to reach without a little bit help:
.picture-container {
position: absolute;
top: 10%;
width: 90%;
height: 70%;
left: 5%;
border-style: dotted;
}
.picture-container .img-container.three-image {
justify-items: center;
height: 100%;
gap: 20px;
display: grid;
grid-template-columns: auto auto auto;
}
.picture-container .img-container.three-image * {
height: 298px;
}
.picture-container .img-container.three-image .img-frame {
width: 100%;
height: 42%;
object-fit: cover;
}
.img-frame {
display: flex;
border: 5px solid #e8e8e8;
box-shadow: 1px 7px 20px 9px rgb(0 0 0 / 75%);
margin: 3rem auto 3rem;
flex: 1 0 45%;
border-radius: 5px;
cursor: pointer;
margin: 0.4rem;
background: #dfe4ea;
user-select: none;
transition: 0.5s;
height: 100%;
object-fit: contain;
}
<div class="picture-container">
<div class="img-container three-image ">
<img class="img-frame" src="https://images.pexels.com/photos/4876243/pexels-photo-4876243.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
<img class="img-frame" src="https://images.pexels.com/photos/1386454/pexels-photo-1386454.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
<img class="img-frame" src="https://images.pexels.com/photos/9646282/pexels-photo-9646282.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
</div>
</div>
I want these images to :
fill the whole area of the picture-container parent. they should fill the width and the height of the picture-container.
All the images should have the same dimensions. I don't want to have different sizes of them.
Note that source of the each image has its own dimensions.
The images should not be Cropped and they can be stretched...
The frame should be intact...
How can I do this?

I couldn't get it to work without wrapping the images in a DIV and setting a width and height on the images themselves.
.img-container{display:flex;max-height:100vh}
.img-container div{flex-grow:1}
.img-frame{width:calc(100% - 29px - 0.4rem);height:calc(100% - 29px - 0.4rem)}
Example:
https://jsfiddle.net/540scey8/1/

Related

How to make the div the size of its content instead of expanding to its max size?

Hello I am trying to make a system of folders which have file inside of them and the files can be dragged between them using this dragula.js.
For some reason the divs of the folder expand to their maximun size even though the content does not require this size.
css:
.folder::before {
content: "□הפרדה לקבצים בודדים";
position: relative;
top: -90%;
pointer-events: all;
background-color: white;
border-radius: 10px;
padding: 0.5%;
left: 1%;
}
.folder.clicked::before {
content: "▇מופרד לקבצים בודדים";
}
.folder {
display: flex;
flex-direction: row;
flex-wrap: wrap;
min-height: 1.5em;
min-width: var(--card-size);
background-color: #ddd;
max-width: 40vw;
justify-content: flex-start;
align-items: center;
margin: 1%;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
min-height: 15vh;
gap: 0;
clip-path: polygon(0 0, 30% 0, 34% 10%, 100% 10%, 100% 100%, 0 100%);
padding-top: 5%;
overflow: auto;
max-height: 100%;
pointer-events: none;
}
.folder * {
pointer-events: all;
}
.folder .card {
width: 14%;
height: auto;
padding: 1%;
margin: 1%;
padding: 0;
margin-bottom: 0.5%;
margin-top: 0.5%;
min-width: 4vw;
}
HTML:
<div style="background: rgb(255, 204, 203);" class="folder">
<div class="card" id="12232466521-1" style="border: 5px solid rgb(204, 0, 0);">
<img id="img10" data-magnify-src="/get_page_from_file/12232466521/1" class="card_img border border-dark zoom" alt="Doc preview not available" loading="lazy" src="/get_page_from_file/12232466521/1">
</div>
</div>
Does anyone have a clue why it does that?
Ive been sitting on this for hours and cant understand why they do that.
Any help will be greatly appreciated.
I have tried adding and removing the width property and all it does is change the possible width it can expand to but it still expands to the maximum space it can.
I tried adjusting the flex to 0 0 auto to make the flex size automatically which didn't do anything.
Try adding width: fit-content; on your .folder class. This should achieve what you're looking for. Here is the MDN on this property.

Cut off rounded rects with clip-path while maintaining border-radius and box-shadow

I have a scrollable list of divs that each have a border-radius and box-shadow. To allow an element below the list to remain visible, the list is cut off using clip-shape. I would like to keep both the shadow and border radius of the clipped rectangles. I have found several working examples for either the shadow or the radius, but I can't find anything that can do both at the same time.
#main {
background-color: lightblue;
position: relative;
height: 100vh;
width: 100vw;
overflow-y: hidden;
}
body {
margin: 0;
}
#overlay {
width: 100vw;
height: 95vh;
overflow-y: scroll;
position: absolute;
clip-path: inset(5vh 0px 0px);
padding-top: 5vh;
}
#overlay::-webkit-scrollbar {
display: none;
}
.overlay-card {
margin: 10px 10px 30px;
background-color: white;
border-radius: 10px;
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.65);
height: 500px;
padding: 30px;
}
<div id="main">
<center>root/header</center>
<div id="overlay">
<div class="overlay-card">overlay content</div>
<div class="overlay-card">overlay content</div>
</div>
</div>
Is the effect above possible? Am I approaching this problem correctly?

unable to fit three images inside their grid container

I can't figure out how to solve this problem:
.picture-container {
position: absolute;
top: 36%;
width: 90%;
left: 5%;
border: 5px dashed red;
}
.three-image-container {
display: grid;
grid-template-columns: auto auto auto;
gap: 20px;
}
.img-frame-container {
}
.img-frame {
border: 5px solid #e8e8e8;
box-shadow: 1px 7px 20px 9px rgb(0 0 0 / 75%);
border-radius: 5px;
cursor: pointer;
background: #dfe4ea;
user-select: none;
width: 250px;
height: 150px;
}
<div class="scale-container">
<div class="picture-container">
<div class="three-image-container">
<div class="img-frame-container">
<img class="img-frame" src="https://images.pexels.com/photos/4876243/pexels-photo-4876243.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
</div>
<div class="img-frame-container">
<img class="img-frame" src="https://images.pexels.com/photos/9646282/pexels-photo-9646282.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
</div>
<div class="img-frame-container">
<img class="img-frame" src="https://images.pexels.com/photos/1386454/pexels-photo-1386454.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
</div>
</div>
</div>
</div>
I want all those images and their frames to have the exact same width and height as you see above, but I want them to fit into the picture-container width and height.
Now with fixed dimensions the third image exceeds the right border of the picture-container.
How can I have all three frames inside the container?
I thought that using this:
display: grid;
grid-template-columns: auto auto auto;
would do what I want, but it seems that it doesn't work if I use an image inside the frames!
Note that the frames should be in the same sizes and did not exceed the container size and I like to be able to have more or less frames so we may need some sort of max-width or something.
You are forcing the image width to 250px.
I added max-width:100% on the .img-frame and box-sizing: border-box to make sure the width of the items include the borders.
Read more on the box-sizing property
Also the gap property should be grid-gap
.picture-container {
position: absolute;
top: 36%;
width: 90%;
left: 5%;
border: 5px dashed red;
}
.three-image-container {
display: grid;
grid-template-columns: auto auto auto;
grid-gap: 20px; /* this was fixed */
}
.img-frame-container {
}
.img-frame {
border: 5px solid #e8e8e8;
box-shadow: 1px 7px 20px 9px rgb(0 0 0 / 75%);
border-radius: 5px;
cursor: pointer;
background: #dfe4ea;
user-select: none;
width: 250px;
height: 150px;
/* these 2 lines were added */
max-width: 100%;
box-sizing: border-box;
}
<div class="scale-container">
<div class="picture-container">
<div class="three-image-container">
<div class="img-frame-container">
<img class="img-frame" src="https://images.pexels.com/photos/4876243/pexels-photo-4876243.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
</div>
<div class="img-frame-container">
<img class="img-frame" src="https://images.pexels.com/photos/9646282/pexels-photo-9646282.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
</div>
<div class="img-frame-container">
<img class="img-frame" src="https://images.pexels.com/photos/1386454/pexels-photo-1386454.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
</div>
</div>
</div>
</div>
Changed the display from grid to flex and used relative values in width (%, value depend on container or the window size ) instead of absolute values (px, value doesn't depend on container or the window size).
Use *{box-sizing: border-box} so that border padding don't take extra space and instead content space is utilized making less overflow when size equals to screen width
See here more about box-sizing
* {
box-sizing: border-box
}
.picture-container {
width: 100%;
border: 5px dashed red;
}
.three-image-container {
display: flex;
}
.img-frame-container {
width: 100%;
padding:0 10px;
}
.img-frame {
border: 5px solid #e8e8e8;
box-shadow: 1px 7px 20px 9px rgb(0 0 0 / 75%);
border-radius: 5px;
cursor: pointer;
background: #dfe4ea;
user-select: none;
width: 100%;
height: 150px;
object-fit: fill;
}
<div class="scale-container">
<div class="picture-container">
<div class="three-image-container">
<div class="img-frame-container">
<img class="img-frame" src="https://images.pexels.com/photos/4876243/pexels-photo-4876243.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
</div>
<div class="img-frame-container">
<img class="img-frame" src="https://images.pexels.com/photos/9646282/pexels-photo-9646282.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
</div>
<div class="img-frame-container">
<img class="img-frame" src="https://images.pexels.com/photos/1386454/pexels-photo-1386454.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500">
</div>
</div>
</div>
</div>
Remove the width: 90%; from .picture-container.
It's making that div take up 90% of the width of the parent (which itself fills the window) regardless of its own contents.

Position half image on top of a div

I'm trying to create this.
Unfortunately, I'm having trouble putting the image on top of the div like this.
How can I achieve this (CSS or JS)?
My current HTML:
<div className="account-container">
<img src="" alt="Avatar" id="userAvatar"/>
<div className="accountStats">
...Other Stuff
</div>
</div>
My current CSS:
#userAvatar{
border-radius: 50%;
height: 312px;
width: 312px;
object-fit: cover;
object-position: center;
}
.accountStats {
width: 760px;
height:980px;
background: #E0E0E0;
box-shadow: 9px 9px 10px rgba(0, 0, 0, 0.25);
border-radius: 18px;
}
.account-container {
top: 30%;
transform:translate(0, 30%);
}
You can give a minus value for the margin-bottom so that the image drops to the bottom. Set the margin-bottom value to half of the image's height (in this case 156px) so that only half of the image lies above the div. Check this out:
#userAvatar{
margin-bottom:-156px; /* 156px is half of #userAvatar's height */
margin-left:calc(380px - 156px); /* half of .accountStats's width - half of #userAvatar's height */
border-radius: 50%;
height: 312px;
width: 312px;
object-fit: cover;
object-position: center;
}
.accountStats {
text-align:center; /* additional */
padding-top:156px; /* half of #userAvatar's height */
width: 760px;
height:980px;
background: #E0E0E0;
box-shadow: 9px 9px 10px rgba(0, 0, 0, 0.25);
border-radius: 18px;
}
.account-container {
top: 30%;
transform:translate(0, 30%);
}
<div className="account-container">
<img src="https://w7.pngwing.com/pngs/7/618/png-transparent-man-illustration-avatar-icon-fashion-men-avatar-face-fashion-girl-heroes-thumbnail.png" alt="Avatar" id="userAvatar"/>
<div class="accountStats">
Other Stuff
</div>
</div>
Please test this:
margin-top: -156px;
Instead of manually calculating left margin to set image in center, we can use flexbox.
.user {
display: flex;
align-items: center;
justify-content: center;
}
body {
background: #efefef;
}
.account-container {
display: flex;
height: 100vh;
align-items: center;
flex-direction: column;
padding-top: 50px;
}
.card {
width: 350px;
border-radius: 5px;
box-shadow: 2px 5px 10px #ccc;
background: white;
}
.user {
display: flex;
align-items: center;
justify-content: center;
}
#userAvatar {
border-radius: 50%;
border: 3px solid #fff;
position: relative;
bottom: -50px;
object-fit: cover;
}
.accountStats {
height: 100px;
background-color: pink;
border-radius: 0px 0px 5px 5px;
}
<div class="account-container">
<div class="card">
<div class="user">
<img id="userAvatar" src="https://images.pexels.com/photos/4587979/pexels-photo-4587979.jpeg" width="100px" height="100px" />
</div>
<div class="accountStats"></div>
</div>
</div>
use the "position" atrribute
#useravatar{
position:absolute;
top:0%;
left:0%;
}

Hover Overlap Issue With a List of boxes

I am dynamically creating a bunch of cards. These cards will have an image and some text. When hovering over the image within the card, a bigger image is displayed in the middle of the page.
There are a total of 16 cards on the page. There are four rows with 4 cards in each row. The issue is: when hovering over the 1st card, all the text or images of the next 15 cards overlap the large image that appears when hovering over the small image on the 1st card. When hovering over let’s say the 3rd card, the image is only overlapped by the text/images of cards that appear after that 3rd card. If I hover over the image of the last card on the page, this issue does not occur. Therefore, all the div’s after the card that is being hovered over cause this issue of overlapping.
Things I have tried: z-index which does not work because each card is being generated dynamically. I have also tried to change the position: static or inherit to see if that would help.
Not sure what the problem is and how to fix it?
<div class="biz-card center-block">
<div class="biz-container">
<div class="biz-row">
<div class="col-sm-6">
<div class="biz-photo">
<div class="rounded biz-wrapper"></div>
</div>
</div>
<div class="col-sm-6" style="display: flex;">
<div class="biz-content">
<h6 href="#home">John Doe</h6>
<p class="left-align">Name</p>
</div>
</div>
</div>
</div>
</div>
.biz-card {
min-width: 350px;
max-width: 350px;
min-height: 250px;
max-height: 250px;
border: thin;
border-color: lightgrey;
box-shadow: 3px 6px 6px -2px rgba(0,0,0,0.58);
z-index: 1;
}
.biz-container {
padding-right: 0;
padding-left: 0;
margin-right: auto;
margin-left: auto;
height: 250px;
}
.biz-row {
display: flex;
align-items: center;
margin-left: auto;
margin-right: auto;
margin-bottom: 20px;
height: 250px;
}
.biz-photo {
position: relative;
display: block;
width: 145px;
height: 64px;
}
.biz-photodetailed {
display: none;
background: #424242;
opacity: 1;
filter: alpha(opacity=100); /* For IE8 and earlier */
z-index: 1000;
bottom: 0;
height: 848px;
width: 605px;
/*margin: auto;*/
position: fixed;
top: 50%;
left: 50%;
margin-top: -424px; /* Half the height */
margin-left: -302px; /* Half the width */
border: 2px solid #fff;
box-shadow: 10px 10px 5px #ccc;
-moz-box-shadow: 10px 10px 5px #ccc;
-webkit-box-shadow: 10px 10px 5px #ccc;
/*-khtml-box-shadow: 10px 10px 5px #ccc;*/
}
.biz-photo:hover .biz-photodetailed {
display:block;
}
Would anyone be able to help out?