How to make two images responsive with fixed height and plain CSS? - html

I want to make the two images responsive with a fixed height similar to here.
I created the jsfiddle
Somehow the line break is added too soon. I tried to add width=auto however this did not work. Moreover it would be good if after a certain width it would become a single column.

It's not super clear what you're asking but there are a few ways to make images responsive with a fixed height and fluid width.
The easiest of which is to use the object-fit: cover rule. Try adding object-fit: cover to your .image element.
https://www.w3schools.com/css/css3_object-fit.asp
This should force it to fill its container without warping its dimensions.
If you want to build a 2-column grid, you need to set the width of the containers using calc, and remove the margin-right on all the even containers.
.container {
width: calc(50% - 10px);
margin-right: 20px;
float: left;
}
.container:nth-child(2n) {
margin-right: 0;
}
.image {
object-fit: cover;
height: 412px;
}
I modified your js fiddle here: https://jsfiddle.net/hnxz7co9/34/

Actually When You A image tell display block and height some value then you most declared
Width: auto
when you tell an image width some value then tell height auto.
when you break this option your image see stretch, you want one side fee height or width.
body {
font-family: sans-serif;
margin: auto;
max-width: 1280px;
}
.site-content {
position: relative;
}
.max-column {
max-width: 1200px;
margin: 0 auto;
padding: 0 40px;
}
.container {
width: 42%;
height: 412px;
display: inline-block;
overflow: hidden;
margin-bottom: 20px;
margin-right: 20px;
line-height: 0px;
position: relative;
}
.image {
opacity: 1;
display: block;
height: 412px;
width: auto;
transition: .5s ease;
backface-visibility: hidden;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.container:hover .image {
-webkit-filter: brightness(70%);
-moz-filter: brightness(70%);
-o-filter: brightness(70%);
-ms-filter: brightness(70%);
filter: brightness(70%);
opacity: 1.0;
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
.container:hover .middle {
opacity: 1;
}
.text {
color: white;
font-size: 16px;
padding: 16px 32px;
}
<div class="site-content max-column">
<div class="container">
<img src="https://images.freeimages.com/images/large-previews/10f/autumn-1-1382513.jpg" alt="Avatar" class="image">
<div class="middle">
<div class="text">
<h1>Works</h1>
<p> Is the music</p>
</div>
</div>
</div>
<div class="container">
<img src="https://images.freeimages.com/images/large-previews/e01/lrt-interior-1626389.jpg" alt="Avatar" class="image">
<div class="middle">
<div class="text">
<h1>Works</h1>
<p> Is the music</p>
</div>
</div>
</div>
<div class="container">
<img src="https://images.freeimages.com/images/large-previews/035/young-golden-retriever-1404848.jpg" alt="Avatar" class="image">
<div class="middle">
<div class="text">
<h1>Works</h1>
<p> Is the music</p>
</div>
</div>
</div>
</div>
==thanks==

The reason that your images don't go two to a line is that you haven't allowed enough room for them to do that. You have set your image width at 48%. If you add up all the horizontal margins and horizontal padding outside of your images, you'll find that they add up to more than four percent of the available width, so your second image gets bounced to the next line. I found in your jsfiddle that changing the image width to 47%, or changing your right margin to 10px, or changing your right margin to 1% allowed two images per row.
If you express a width as a percentage and your padding and margins as pixels, you have to calculate the total pixels involved and make sure that there's enough room for two images to fit on a line. To do this, you can use the calc() function as in Daniel Bernardi's answer, or if you want the margins to resize along with your image size, you can set them as percentages rather than hard pixel values.
As for changing to one image per row on smaller screens, I would start by reading about #media. This allows you to set up different CSS rules for screens of different sizes. So, if your screen is below a certain size, set the width of the image to 100% minus padding and margins.

you have to use background image instead of image
<div class="site-content max-column">
<div class="container">
<div class="image img1"></div>
<div class="middle">
<div class="text">
<h1>Works</h1>
<p> Is the music</p>
</div>
</div>
</div>
<div class="container">
<div class="image img2"></div>
<div class="middle">
<div class="text">
<h1>Works</h1>
<p> Is the music</p>
</div>
</div>
</div>
<div class="container">
<div class="image img3"></div>
<div class="middle">
<div class="text">
<h1>Works</h1>
<p> Is the music</p>
</div>
</div>
</div>
</div>
body {
font-family: sans-serif;
margin: auto;
max-width: 1280px;
}
.site-content {
position: relative;
}
.max-column {
max-width: 1200px;
margin: 0 auto;
padding: 0 40px;
}
.container {
width: 48%;
height: 412px;
display: inline-block;
overflow: hidden;
margin-bottom: 20px;
margin-right: 20px;
line-height: 0px;
position: relative;
}
.image {
opacity: 1;
display: block;
height: 412px;
width: 100%;
transition: .5s ease;
backface-visibility: hidden;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.container:hover .image {
-webkit-filter: brightness(70%);
-moz-filter: brightness(70%);
-o-filter: brightness(70%);
-ms-filter: brightness(70%);
filter: brightness(70%);
opacity: 1.0;
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
.container:hover .middle {
opacity: 1;
}
.text {
color: white;
font-size: 16px;
padding: 16px 32px;
}
.img1{
background: url('https://images.freeimages.com/images/large-previews/10f/autumn-1-1382513.jpg');
background-size: cover;
background-position: center;
}
.img2{
background: url('https://images.freeimages.com/images/large-previews/e01/lrt-interior-1626389.jpg');
}
.img3{
background: url('https://images.freeimages.com/images/large-previews/035/young-golden-retriever-1404848.jpg');
background-size: cover;
background-position: center;
}
demo

Play around with the values and you will see how effects elements.
h1 {
padding: 80px;
text-align: center;
}
.image {
width: 450px;
height: 250px;
border: 1px black solid;
}
.grid_img {
display: grid;
grid-template-columns: repeat(2, minmax(500px, 1fr));
/* you need SCSS for this:
#media (max-width: 990px) {
.grid_cards {
grid-template-columns: repeat(1, minmax(200px, 1fr));
}
*/
<div class="grid_img">
<div class="image">
<h1>Some Image here</h1>
</div>
<div class="image">
<h1>Some Image here</h1>
</div>
<div class="image">
<h1>Some Image here</h1>
</div>
<div class="image">
<h1>Some Image here</h1>
</div>
<div class="image">
<h1>Some Image here</h1>
</div>
<div class="image">
<h1>Some Image here</h1>
</div>
<div class="image">
<h1>Some Image here</h1>
</div>
<div class="image">
<h1>Some Image here</h1>
</div>
</div>

Related

How to make this page responsive for all resolutions?

I'm new and I'm having a problem--this page is not responsive for 1366, and 1280 resolutions on PC, on 1920, and on mobile it's perfect. May you please help me with this one?
I tried adding contain on object-fit, but that didn't help me, I think the problem is with the width but I can't figure out how to solve this properly without ruining it on 1920 resolution and mobile phone.
Resolution 1366
.container1 {
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
.container1>div {
padding: 0px 5px;
max-width: 100%;
height: 325px;
}
.container1 div img {
width: 100%;
height: 100%;
object-fit: cover;
}
.zgrade {
position: relative;
max-width: 100%;
margin-left: auto;
margin-right: auto;
overflow: hidden;
max-width: 745px;
min-width: 428px;
}
.zgradeimg {
width: 500px;
-moz-transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.4s ease-in-out;
}
.zgrade:hover img {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
#media screen and (max-width: 780px) {
.container1 {
flex-direction: column;
}
.container1>div {
padding: 10px 5px;
}
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="container1">
<div class="row justify-content-center">
<div class="zgrade">
<a href="zgradaA.html">
<img src="https://via.placeholder.com/800" /></a>
</div>
<br>
<div class="zgrade"><img src="https://via.placeholder.com/800" />
</div>
</div>
</div>
<div class="p-6"></div>
<div class="container1">
<div class="row justify-content-center ">
<div class="zgrade ">
<img src="https://via.placeholder.com/800" /></div>
<br>
<div class="zgrade"><img src="assets/img/szgrade/zgradaD.jpg" />
</div>
</div>
</div>
I removed Row code from the container and it's working. :) They are only used for containing columns. I don't have columns so I tried removing the row class and everything is cool right now. I hope that this will stay like this :)

Fully responsiove images in 3 div's side by side

So I want these 3 div's to work side by side and the images to be responsive. when I try to set max-width or something it breaks up. Help me out on this one.
.fl {
display: flex;
flex-wrap: no-wrap;
height: 35%;
flex-direction: row;
}
.pic {
width: 34%;
}
.caro {
/* border: 2px solid black; */
height: 100%;
width: 100%;
display: block;
/* z-index: ; */
}
.caro img {
height: 100%;
width: 100%;
filter: brightness(0.5);
transition: all .3s;
}
.caro img:hover {
filter: brightness(1);
}
<div class="fl">
<div class="pic">
<img src="https://via.placeholder.com/1920x1080.jpg" alt="">
</div>
<div class="pic">
<img src="https://via.placeholder.com/1920x1080.jpg" alt="">
</div>
<div class="pic">
<img src="https://via.placeholder.com/1920x1080.jpg" alt="">
</div>
</div>
I would suggest two things:
Use calc to get a third with calc(100% / 3), instead of setting the width to a total of (3*34=) 102%.
Use object-fit: cover on the images to make them fit. I used different sizes on the images, so it's obvious that they are scaling.
Don't use all for transition, because that can cause janky animations due to the browser having to loop through all animatable properties. Always specify what you animate; it's easier to understand the code as well.
Using percentage for height doesn't automatically take the parent's height, so I had to improvise and use vh (viewport height).
body {
margin: 0px;
min-height: 100vh;
}
.fl {
display: flex;
flex-wrap: no-wrap;
height: 100vh;
max-height: 35vh;
}
.fl > .pic {
flex-basis: calc(100% / 3);
}
.caro img {
height: 100%;
width: 100%;
object-fit: cover;
filter: brightness(0.5);
transition: filter .3s;
}
.caro img:hover {
filter: brightness(1);
}
<div class="fl">
<div class="pic">
<img src="https://picsum.photos/100/300">
</div>
<div class="pic">
<img src="https://picsum.photos/50/80.jpg" alt="">
</div>
<div class="pic">
<img src="https://picsum.photos/100/100" alt="">
</div>
</div>

The image overlay is stuck at the bottom of the image and is not moving when the user hovers over

I´m trying to overlay images with a description and when the user hovers the mouse over the overlay it will move down and show the photo that is underneath.
However the overlays seem to be stuck like this. With what looks like the overlays stuck to the bottom adn when you hover the mouse nothing happens.
please excuse the images they´re just a random photo.
my html looks like this
<div class="Portfolio_container">
<div class="Portfolio">
<div class="section group">
<div class="col span_1_of_3">
<img src="Images/Dundee.jpg" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="col span_1_of_3">
<img src="Images/Dundee.jpg" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="col span_1_of_3">
<img src="Images/Dundee.jpg" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
</div>
</div>
</div>
and my CSS
.Portfolio_container {
background-color: #847470; /* colour of the whole portfolio page */
}
.Portfolio { /* keeps the examples in the middle with the background colour matching the container that surounds it*/
width: auto;
margin-right: 5%;
margin-left: 5%;
background-color: #847470;
}
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 2%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* GRID OF THREE */
.span_3_of_3 { width: 100%; }
.span_2_of_3 { width: 66%; }
.span_1_of_3 { width: 32%; }
/* GO FULL WIDTH BELOW 480 PIXELS */
#media only screen and (max-width: 480px) {
.col { margin: 1% 0 1% 0%; }
.span_3_of_3, .span_2_of_3, .span_1_of_3 { width: 100%; }
}
.span_1_of_3 {
height: 100%;
}
.image {
max-width: 100%; /* keeps the portfolio images within their divs */
max-height: 100%;
display: block;
width: 100%;
height: auto;
}
.overlay {
bottom: 0;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height: 100%;
transition: .5s ease;
opacity: 0.5;
}
.span_1_of_3:hover .overlay {
height: 0%;
}
.text {
color: white;
font-size: 20px;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
any help would be greatly appreciated.
found the solution.
.span_1_of_3 {
height: auto;
position: relative;
}
I had to make the div that was containing the overlays to have a relative position. Hopes this helps anyone who has this problem.

Adding link to a image breaks everything else

So this is a simple line of images, with hover effects, I have it doing everything I need, except when I add a link to open up a new page
so do i need to remake everything and use a different approach or is there a way to somehow fix the issue? Thanks :)
UPDATE!
The code might not be perfect, but I added
.box-1 a {
display:contents:
}
and that solved everything !
.container-1 {
display: inline-flex;
}
.box-1 {
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
-webkit-flex: 1 1 auto;
flex: 1 1 auto;
padding: 30px;
text-align: center;
display: inline-block;
position: relative;
}
.box-1:hover img {
filter: blur(3px) brightness(85%);
}
.box-1 img {
width: 100%;
height: 100%;
transition: 0.1s;
}
.box-1 :not(img) {
position: absolute;
top: 30%;
z-index: 1;
color: #fff;
text-align: center;
width: 90%;
opacity: 0;
transition: 0.1s;
letter-spacing: 2px;
}
.box-1 h2 {
top: 50%;
}
.box-1:hover :not(img) {
opacity: 1;
}
<div class="container-1">
<div class="box-1">
<a href="c1.html" target="_blank">
<img class="candle-image" src="image/candlesp/IMG_0900.jpg"/></a>
<h2>Festivity</h2>
</div>
<div class="box-1">
<img src="image/candlesp/IMG_0903.jpg" alt="">
<h2>Cinnamon</h2>
</div>
<div class="box-1">
<img src="image/candlesp/IMG_0917.jpg" alt="">
<h2>Forest</h2>
</div>
</div>
I think you are accidentally making <a> position: absolute. Instead of using :not, why not target the h2 directly .box-1 h2 and also try giving it a width and height
You close img tag in anchor tag
<div class="container-1">
<div class="box-1">
<a href="c1.html" target="_blank">
<img class="candle-image" src="image/candlesp/IMG_0900.jpg"></a>
<h2>Festivity</h2>
</div>
<div class="box-1">
<img src="image/candlesp/IMG_0903.jpg" alt="">
<h2>Cinnamon</h2>
</div>
<div class="box-1">
<img src="image/candlesp/IMG_0917.jpg" alt="">
<h2>Forest</h2>
</div>
</div>

CSS Card Effect not working on Mobile Safari

I've built a card flip effect that seems to work on Safari Mobile regarding the "flip" aspect of the effect. However, the card is not displaying the correct image upon flipping. I'm using the effect as a "Before and After", using separate images on each side of the card. I'll post my code. Thank you.
.beforeafter {
margin: 10px auto;
text-align: center;
}
.card-container {
cursor: pointer;
height: 300px;
perspective: 600;
position: relative;
width: 300px;
display: inline-block;
}
.clientcard {
height: 100%;
position: absolute;
transform-style: preserve-3d;
transition: all .5s ease-in-out;
width: 100%;
}
.clientcard:hover {
transform: rotateY(180deg);
-webkit-transform: -webkit-translateY(180deg);
}
.clientcard .side {
backface-visibility: hidden;
border-radius: 2px;
height: 100%;
position: absolute;
overflow: hidden;
width: 100%;
}
.clientcard .back {
background: #eaeaed;
color: #0087cc;
line-height: 150px;
text-align: center;
transform: rotateY(180deg);
}
<div class="beforeafter">
<div class="card-container">
<div class="clientcard">
<div class="side"><img src="img/sean1.JPG"></div>
<div class="side back"><img src="img/sean1copy.JPG"></div>
</div>
</div>
<div class="card-container">
<div class="clientcard">
<div class="side"><img src="img/sean2.JPG"></div>
<div class="side back"><img src="img/sean2copy.JPG"></div>
</div>
</div>
<div class="card-container">
<div class="clientcard">
<div class="side"><img src="img/sean3copy.jpg"></div>
<div class="side back"><img src="img/sean3.jpg"></div>
</div>
</div>
<div class="card-container">
<div class="clientcard">
<div class="side"><img src="img/gwork.jpg"></div>
<div class="side back"><img src="img/alana2.jpeg"></div>
</div>
</div>
</div>
I believe you want to rotate on the Y axis in the negitive -180deg. I improved your code a bit and don't mind the shitty format it was translated from sass and if you want another card with flip copy and past that code
.card {
perspective: 150rem;
-moz-perspective: 150rem;
position: relative;
height: 52rem; }
.card_side {
height: 52rem;
transition: all 2s ease;
position: absolute;
top: 0;
left: 0;
width: 100%;
backface-visibility: hidden;
}
.card_side-front {
background-color: blue;
}
.card_side-back {
transform: rotateY(180deg);
}
.card_side-back-1 {
background-image: linear-gradient(to right bottom, #ffb900, #ff7730);
}
.card:hover .card_side-front {
transform: rotateY(-180deg);
}
.card:hover .card_side-back {
transform: rotateY(0);
}
.card_picture-1 {
background-color: blue;
}
<div class="row">
<div class="col-1-of-3">
<div class="card">
<div class="card_side card_side-front">
<h4 class="card_heading">
<span class="card_heading-span card_heading-span-1">card front text</span>
</h4>
</div>
<div class="card_side card_side-back card_side card_side-back-1">
<div class="card_cta">
<div class="card_price-box">
<p class="card_price-only">back text</p>
</div>
</div>
</div>
</div>
</div>