I have a div for slick slider, product card to be exact.
It should be displayed inline, and picture should be the whole size of the card-info.
.product-card__item {
display: flex;
width: 100%;
min-height: 450px;
}
.product-card__item-preview {
flex-basis: 48.5%;
height: 100% width:100%
}
.product-card__img {
width: 100%;
height: 100%;
object-fit: cover;
}
.product-card__item-info {
width: 51.5%;
background-color: #fff;
padding: 1.2em;
}
}
```
<article class="product-card">
<div class="product-card__preview">
<img class="product-card__img" src="https://via.placeholder.com/150" alt="">
</div>
<div class="product-card__info">
<div class="product-card__info-top">
<a class="product-card__title" href="#">
One Page Resume Template
</a>
<div class="product-card__author">
<img class="product-card__avatar" src="https://via.placeholder.com/50" alt="user avatar">
<a class="product-card__top-name" href="#">
AazzTech
</a>
</div>
</div>
</div>
</article>
but with even slightly resizing the window for adaptation, picture starts doing this:
I know it could be fixed easily if I make amg as a bg for preview div, but how is it possible with img tag?
I dont have your code, but you can try this:
.container{
display:flex;
height:500px;
}
.container > div{
flex: 1 1 0;
overflow:hidden;
}
.second img{
height:100%;
}
.first{
background-color:red;
<div class="container">
<div class="first"></div>
<div class="second">
<img src="https://upload.wikimedia.org/wikipedia/commons/4/42/Shaqi_jrvej.jpg" alt="">
</div>
</div>
Related
Here is a sample image of the layout I am trying to achieve with HTML and CSS:
From what the gallery looks like,
the images are placed in a row
each row fills the width of the container
each image fills the height of the row
The height of each row looks to be slightly different (e.g. min-height: 300px; max-height: 600px;) to accomadate for the different aspect ratios of the image.
I'm trying to build this layout with html and css flexbox, but haven't really gotten too far with it:
.gallery-container {
display: block;
margin: 0 auto;
width: 50%;
}
.gallery-row {
display: flex;
min-height: 300px;
max-height: 500px;
}
.gallery-img {
position: relative;
flex-grow: 1;
max-width: 33.3%;
}
.gallery-img img {
height: 100%;
}
<div class="gallery-container">
<div class="gallery-row">
<div class="gallery-img">
<img src="https://picsum.photos/200/300"/>
</div>
<div class="gallery-img">
<img src="https://picsum.photos/300/200"/>
</div>
<div class="gallery-img">
<img src="https://picsum.photos/400/200"/>
</div>
</div>
<div class="gallery-row">
<div class="gallery-img">
<img src="https://picsum.photos/400/300"/>
</div>
<div class="gallery-img">
<img src="https://picsum.photos/100/200"/>
</div>
<div class="gallery-img">
<img src="https://picsum.photos/300/200"/>
</div>
</div>
</div>
I have multiple images which I want to show using flexbox. But the images leave a gap if the next image cannot fit in the same row.
I want these images to resize accordingly so that there is no gap left.
Example:
HTML:
<div class="ImageContainer">
<div class="ImageBlock">
<img src="https://c4.wallpaperflare.com/wallpaper/246/739/689/digital-digital-art-artwork-illustration-abstract-hd-wallpaper-thumb.jpg"
alt="">
</div>
<div class="ImageBlock">
<img src="https://c4.wallpaperflare.com/wallpaper/410/867/750/vector-forest-sunset-forest-sunset-forest-wallpaper-thumb.jpg"
alt="">
</div>
<div class="ImageBlock">
<img src="https://c4.wallpaperflare.com/wallpaper/500/442/354/outrun-vaporwave-hd-wallpaper-thumb.jpg"
alt="">
</div>
<div class="ImageBlock">
<img src="https://c4.wallpaperflare.com/wallpaper/39/346/426/digital-art-men-city-futuristic-night-hd-wallpaper-thumb.jpg"
alt="">
</div>
</div>
CSS:
.ImageContainer{
margin:40px;
display: flex;
flex-wrap: wrap;
}
.ImageBlock{
margin:10px;
}
.ImageBlock img{
max-height: 250px;
}
You will need to add flex-grow: 1; to the .ImageBlock
This will make the block expand.
.ImageBlock {
margin: 10px;
flex-grow: 1;
}
Then you will have to make the img fill the block with width: 100%;
If you don't want the image to stretch out of proportions, you can use object-fit: cover;.
.ImageBlock img {
max-height: 250px;
width: 100%;
object-fit: cover;
}
Example codepen: https://codepen.io/bj-rn-nyborg/pen/rNMVrVL
I'm trying to simulate a shelf of books so that they look like this:
photoshop_mock_up
I can get the books to align just fine, but can't figure out how to make them retain their odd heights/widths, and not all just resize to the container:
HTML:
<div class="images-outer">
<div class="image-inner">
<img src="img/_0002_aristotle__poetics_and_rhetoric.png">
</div>
<div class="image-inner">
<img src="img/_0005_david_mamet__make_believe_town.png">
</div>
<div class="image-inner">
<img src="img/_0003_david_mamet__bambi_vs_godzilla.png">
</div>
<div class="image-inner">
<img src="img/_0006_annie_dillard__pilgrim_at_tinker_creek.png ">
</div>
</div>
CSS:
.images-outer {
height: 50%;
max-height: 50%;
display: flex;
vertical-align: bottom;
}
.image-inner img {
max-height: 100%;
}
img {
max-height: 100%;
}
This makes them look like this: web_page
Ideas?
In display: flex, you should use align-items to set vertical align and justify-content for horizontal align.
.images-outer {
height: 300px;
max-height: 50%;
display: flex;
align-items:flex-end;
justify-content:center;
background: black
}
.image-inner {
max-width:30px;
padding: 0px 5px;
}
.image-inner {
object-fit: contain;
object-position: bottom;
width: 100%;
}
<div class="images-outer">
<div class="image-inner">
<img src="https://picsum.photos/30/200" />
</div>
<div class="image-inner">
<img src="https://picsum.photos/30/240" />
</div>
<div class="image-inner">
<img src="https://picsum.photos/30/180" />
</div>
<div class="image-inner">
<img src="https://picsum.photos/30/200" />
</div>
</div>
</div>
.image-inner img{
width:100%;
height:auto;}
This should help in sizing the images properly
Else, you could dive each image an individual class and give each it's individual height.
I try to center pictures in the container. I've set left and right margin to 0 and still something is not working right.
#navbut {
width: 100%;
background: red;
margin: -7px 0 0 0;
color: white;
}
.container .box {
display: inline-block;
width: 10%;
margin-left: auto;
margin-right: auto;
}
.box img.Newspaper_pic {
width: 50%;
margin-left: auto;
margin-right: auto;
}
<section id="navbut">
<div class="container">
<div class="box">
<img src="http://placehold.it/100x100" alt="News-pic" class="Newspaper_pic">
</div>
<div class="box">
<img src="http://placehold.it/100x100" alt="News-pic" class="Newspaper_pic">
</div>
<div class="box">
<img src="http://placehold.it/100x100" alt="News-pic" class="Newspaper_pic">
</div>
</div>
</section>
What I am doing wrong that I cannot center pictures in one line?
If your images are set to inline-block, you have to use
text-align:center;
. If your images are set to block,
margin: 0 auto;
will work.
Looks like your pictures are centered, but only within the .box divs, you have to center those .box divs in the .container aswell. The .container also needs to be width 100% so it spans over the whole #navbut.
Try to use flex. flex is very easy to make for these kind of layouts because of these alignment properties.
Reference Link flex
Stack Snippet
body {
margin: 0;
}
.container, .box {
display: flex;
justify-content: center;
}
.Newspaper_pic {
display: block;
max-width: 100%;
}
<section id="navbut">
<div class="container">
<div class="box">
<img src="http://lorempixel.com/400/200/sports" alt="News-pic" class="Newspaper_pic">
</div>
<div class="box">
<img src="http://lorempixel.com/400/200/sports" alt="News-pic" class="Newspaper_pic">
</div>
<div class="box">
<img src="http://lorempixel.com/400/200/sports" alt="News-pic" class="Newspaper_pic">
</div>
</div>
</section>
Put whatever you want inside the center tags, e.g:
<center>
<img src="" alt="">
</center>
HTML:
<div id="tmenu" style="direction:rtl;">
<img src="assets/imgs/menu/all.jpg"/>
<img src="assets/imgs/menu/sweets.jpg"/>
<img src="assets/imgs/menu/main meals.jpg"/>
<img src="assets/imgs/menu/ma5bozat.jpg"/>
<img src="assets/imgs/menu/moqblat.jpg"/>
<img src="assets/imgs/menu/mofrznat.jpg"/>
<img src="assets/imgs/menu/carnavals.jpg"/>
<img src="assets/imgs/menu/other.jpg"/>
</div>
Check this image
https://imgur.com/a/hsKax
The images in the top header are the problem. There's about 8 pics.
It shows which fit the width of the screen and hide the rest.
CSS:
#tmenu
{
width: max-content;
overflow-x: scroll!important;
img
{
display: inline-block;
width: 100px!important;
height: 100px!important;
}
}
How to make it scrollable?
#tmenu
{
width: max-content;
overflow-x: scroll!important;
height:100px;
overflow-y:hidden;
white-space:nowrap;
float:left;
width:400px;
font-size:0
}
img
{
display: inline-block;
width: 100px!important;
height: 100px!important;
vertical-align:middle;
}
<div id="tmenu" style="direction:rtl;">
<img src="assets/imgs/menu/all.jpg"/>
<img src="assets/imgs/menu/sweets.jpg"/>
<img src="assets/imgs/menu/main meals.jpg"/>
<img src="assets/imgs/menu/ma5bozat.jpg"/>
<img src="assets/imgs/menu/moqblat.jpg"/>
<img src="assets/imgs/menu/mofrznat.jpg"/>
<img src="assets/imgs/menu/carnavals.jpg"/>
<img src="assets/imgs/menu/other.jpg"/>
</div>
What about this?