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.
Related
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/
I created a div with a border-radius 4% and wanted to add a div inside it. But now the border-radius is getting affected. How can I add the new div without affecting the previous border-radius.
If I add same border radius for the inner div
Without any border-radius
body {
background: #4FA2AD;
}
.upper {
background-color: #035961;
height: 30%;
}
.main {
background-color: antiquewhite;
height: 50vh;
width: 25%;
margin: 25vh auto;
border-radius: 4%;
box-shadow: 2px 2px 2px 2px rgba(0,0,0,0.2);
}
<body>
<div class="main">
<div class="upper">
</div>
</div>
</body>
Overflow hidden will cut off any content that goes outside of the parents border, including any overlap at the corners.
overflow: hidden;
This is sometimes not a viable solution (Where you require content to overflow or extend the container) however since you have a fixed size, it is valid in this case.
body {
background: #4FA2AD;
}
.upper {
background-color: #035961;
height: 30%;
}
.main {
background-color: antiquewhite;
height: 50vh;
width: 25%;
margin: 25vh auto;
border-radius: 4%;
box-shadow: 2px 2px 2px 2px rgba(0,0,0,0.2);
overflow: hidden;
}
<body>
<div class="main">
<div class="upper">
</div>
</div>
</body>
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?
I have some HTML that I cannot change, but I can change the CSS as much as I want. I need to make these:
two columns of equal width
A margin in between of 2em
They have to take all the remaining width (parent width - 2em)
The boxes need to have a padding inside
HTML:
<div class="parent">
<a href="/page1" class="box">
<img class="pic" src="/images/image1.png">
<div class="description">the description</div>
</a>
<a href="/page2" class="box">
<img class="pic" src="/images/image2.png">
<div class="description">the description</div>
</a>
</div>
I'm able to do it without any spacing between them with: box-sizing: border-box; but if I add in a margin-right, they no longer fit.
Give this a try : It makes use of the Calc() function in css.
Note: The border throws off the calculation a bit, so you will have to adjust the calc slightly. I just did it to show you how the boxes were laid out.
.parent {
position: relative;
width: 600px;
height: 300px;
border: 1px solid red;
}
.box {
border: 1px solid black;
width: calc(50% - 1.25em);
display: inline-block;
}
.box:first-child {
margin-right: 2em;
}
Fiddle
I was able to solve it:
.parent .box
{
position: relative;
width: 50%;
margin: 0em;
padding: 1em;
float: left;
font-size: 1em;
overflow: hidden;
z-index: 0;
display: block;
text-decoration: none;
box-sizing: border-box;
}
.parent .box:nth-child(odd)
{
border-right: solid 1em #ffffff;
}
.parent .box:nth-child(even)
{
border-left: solid 1em #ffffff;
}
The n-th child lets me add the spacing between them
How can the parent div auto resize it's height based on the child's height?
div#main{
width: 970px;
height: 100px;
background: rgba(255,0,0,1);
border: 5px solid rgb(251,151,117);
margin: 20px 0px 20px 0px; /* Top Right Bottom Left*/
padding: 10px
}
div#left{width: 383px;
height: 100%;
margin-right: 5px;
background: rgb(0,0,255);
float:left
}
div#description{width: 100%;
height: 50%;
background: rgb(0,0,0)
}
div#following{width: 100%;
height: 50%;
background: rgb(0,255,0)
}
div#posts{width: 577px;
height: auto;
margin-left: 5px;
background: rgb(255,255,0);
float: right
}
<div id="main">
<div id="left" class="cell">
<div id="description" class="cell">
</div>
<div id="following" class="cell">
</div>
</div>
<div id="posts" class="cell">
there are some contents here (height is set to auto)
</div>
</div>
I made a very simple example for you to see how variable parent height works.
.parent
{
height: auto;
border: 1px dashed #f00;
padding: 5px;
}
.child
{
height: 100px;
border: 1px dashed #0f0;
}
<div class="parent">
<div class="child">
</div>
</div>
Follow what is there and you'll do fine.
After looking through your code it's a float problem, you have to add a new div to the bottom with clear: both; to clear the floats and make the #main div appear filled in.
Look at example here.
div#main{
width: 970px;
background: rgba(255,0,0,1);
border: 5px solid rgb(251,151,117);
margin: 20px 0px 20px 0px; /* Top Right Bottom Left*/
padding: 10px
}
Remove height attribute
CSS3
.container {
display: inline;
position: relative;
}
Should fix it. Use inline-block if you want it to be a block with inline.