I want to place image in other image as you see below
And I made it using below codes.
HTML
<div class="col col-span-1" style="position : relative">
<div>
<img style="max-width:800px; max-height:800px;
width:100%; height:100%;"
src="https://i.imgur.com/iY3x1GC.png">
</div>
<div style="position : absolute; top: 80%; left:50%; ">
<img src="https://i.imgur.com/C1uxk6Y.png"
style="width: 100%; height: 100%;">
</div>
</div>
CSS
.col-span-1 {
flex-basis: 8.3333%;
}
.col {
flex: 1 1 8%;
margin: 0 0 0.5rem 0;
padding: 0.5em 10px;
box-sizing: border-box;
}
myJSFiddle
I made div1's image responsive with width using width : 100%
But I don't know how to make div2's image scale up/down relative to div1's image.
I want to make it like this.
->(responsive)
I want to use CSS only as possible, thanks in advance.
To resize small images, putting them in small container and pushing that small container with another element is a clean solution. In my opinion tables are great for that.
Here is the code;
<div class="col col-span-1" style="position : relative">
<div>
<img style="max-width:800px; max-height:800px;width:100%; height:100%;" src="https://i.imgur.com/iY3x1GC.png">
</div>
<table style="position: absolute;top: 75%;width: 85%;">
<tbody>
<tr>
<td style=" width: 60%;"></td>
<td style=" max-width: 90px; width: 39%;">
<div style="">
<img src="https://i.imgur.com/C1uxk6Y.png" style="width:100%; height: 100%;">
</div>
</td>
</tr>
</tbody>
</table>
</div>
here is the code
html:
<div id="container">
<div id="main_image"> <img style="max-width:800px; max-height:800px; width:100%; height:100%;" src="https://i.imgur.com/iY3x1GC.png"></div>
<div id="overlay_image"> <img src="https://i.imgur.com/C1uxk6Y.png" style="
width: 100%;
height: 100%;
"></div>
</div>
css:
#container{
position: relative;
width: 100%;
height: 100%;
}
#main_image{
width: 100%;
height: 100%;
}
#overlay_image{
position: absolute;
bottom: 10px;
right: 10px;
width: auto;
height: auto;
}
#media screen and (min-width: 601px) {
#overlay_image{
width:40px;
}
}
#media screen and (max-width: 600px) {
#overlay_image{
width:20px;
}
}
Related
What i would like to achieve is that i want to change the way my boxes appear only on the mobile version of the website. I experimented with display: and flex: rules but had no luck. I want them stick to each other but Couldn't find the right CSS rule. Help.
Thanks.
Example picture of how i want them:
The way they appear on desktop version of the website:
.m-image {
border: 5px dashed black;
width: 100%;
height: 70px;
margin: 10px 0;
position: relative;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
img {
width: 100%;
height: 300px;
}
<div class="m-image">
<img srcset="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/></div>
<div class="m-image">
<img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/></div>
<div class="m-image">
<img alt="" loading="lazy" src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" /><img /></div>
.m-image {
border: 5px dashed black;
width: 100%;
height: 70px;
margin: 10px 0;
position: relative;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
img {
width: 100%;
height: 300px;
}
#media only screen and (max-width: 1000px) {
.main {
display: flex;
gap: 10px;
}
.m-image {
border: solid black 3px;
}
}
<div class = "main">
<div class="m-image">
<img srcset="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1">
</div>
<div class="m-image">
<img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1">
</div>
<div class="m-image">
<img alt="" loading="lazy" src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" />
</div>
</div>
Couple of things to think about when it comes to mobile view. When wanting certain items to display a certain way on mobile view you want to use #media only screen and (max-width: /* width of the device */. Place all the CSS rules inside of here. These rules will change the rules set above or run new rules that you have define below.
Also, when it comes to display: flex; you want to make sure you wrap it into another div. This "wrapper" or "container" will provide the structure to the way you want the images to display.
add a main container to compress the class m-image then add display flex
Ex:
<div id="main-container">
<div class="image"></div>
<div class="image"></div>
<div class="image"></div>
</div>
.main-container {
display: flex;
}
then add padding left and right to your m-image class
what you should do in this case is put your images in a single container and apply flex property in the css.
basically manipulate your html and css like this.
HTML:
<div class="image-container">
<div class="m-image">
<img srcset="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/>
</div>
<div class="m-image">
<img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/>
</div>
<div class="m-image">
<img alt="" loading="lazy" src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" /><img />
</div>
</div>
CSS:
.image-container{
display:flex;
gap: 8px;
flex-wrap: nowrap;
}
.m-image {
border: 5px dashed black;
width: 100%;
height: 70px;
margin: 10px 0;
position: relative;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
img {
width: 100%;
height: 300px;
}
This should give you your desired result for the desktop and for the mobile version you will have to apply media query into your CSS code.
hope this answers your question!
I couldn't really understand your code, So I wrote one for you suiting your needs
I hope it will fix your problem!
#content{
display: flex;
justify-content: space-around;
width: 100%;
}
.imagecontainer{
overflow: hidden;
width: 30%;
}
img{
width: 100%;
}
<div id="content">
<div class="imagecontainer"><img src="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg"></div>
<div class="imagecontainer"><img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg"></div>
<div class="imagecontainer"><img src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg"></div>
</div>
On my webpage there is an area and I'd like to add a image to it. I don't know the image's size and orientation (portrait or landscape). But I want it to fit the area as it is displayed in the picture:
So, if an image has a landscape orientation it must fill the whole width of the area. See picture 1. If the image's width is bigger that the area's width the image's width must be constrained and if its width is smaller - the image must be widened. However if the image's height is bigger than the area's one the image's height must be constrained. See picture 2.
The similar I want for the portrait image. See picture 2.
In short, what I want can be easily done with object-fit: contain;.
.wrapper {
width: 30%;
height: 400px;
overflow: hidden;
border: 1px solid black;
position: relative;
}
.img {
width: 100%;
height: 100%;
object-fit: contain;
}
.label {
position: absolute;
top: 0;
right: 0;
padding: 15px;
background-color: #cccccc;
}
<div class="wrapper">
<img class="img" src="https://images.unsplash.com/photo-1500622944204-b135684e99fd?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80" alt="">
<span class="label">Label</span>
</div>
Here is the CodePen: see the code
But the problem is that I have a label to each picture and I want it to be on the top-right corner of the picture and not the area.
Is there any way to do this with CSS only?
Any help would appreciated! Thank you in advance!
instead of the object-fit: contain; replace it with background-size:cover in the img selector css file.
You can wrap the image with a div that has a display: inline-block rule, that will force the div to fit the image scale, then, in this div add another div for the label and position it with absolute.
.cont {
width: 300px;
height: 250px;
background-size: contain;
background-repeat: no-repeat;
margin: 20px;
border: 3px solid black;
display: flex;
align-items: center;
justify-content: center;
}
div .image-cont {
display: inline-block;
position: relative;
}
img {
max-width: 300px;
max-height: 250px;
width: auto;
height: auto;
}
.label {
background-color: yellow;
padding: 5px;
position: absolute;
top: 0;
right: 0;
}
<div class="cont">
<div class="image-cont">
<img src="https://image.shutterstock.com/image-photo/beautiful-abstract-grunge-decorative-navy-260nw-539880832.jpg" />
<div class="label">Label</div>
</div>
</div>
<div class="cont">
<div class="image-cont">
<img src="https://i.pinimg.com/originals/1b/30/80/1b30806bed30a7d071752948d00e75f8.jpg" />
<div class="label">Label</div>
</div>
</div>
You can do the following:
Wrap image and .label span with another span with class e.g. .inner-wrapper and add to its css
position: relative;
height: 100%;
Remove from .wrapper css position: relative; and add
display: flex;
justify-content: center;
Replace in .img css width: 100%;height: 100%; with max-width: 100%;max-height: 100%;
Look in the snippet in full page mode and resize the window.
.wrapper,
.wrapper200 {
width: 30%;
height: 400px;
overflow: hidden;
border: 1px solid black;
/*position: relative;*/
display: flex;
justify-content: center;
}
.wrapper200 {
height: 200px;
}
.inner-wrapper {
position: relative;
height: 100%;
}
.img {
max-width: 100%;
max-height: 100%;
object-fit: contain;
}
.label {
position: absolute;
top: 0;
right: 0;
padding: 15px;
background-color: #cccccc;
}
/* for visual illustration */
.container {
display: flex;
justify-content: space-evenly;
padding: 10px;
outline: dashed red 1px;
margin-bottom: 25px;
}
<h1>Heigth: 200px</h1>
<div class="container">
<div class="wrapper200">
<span class="inner-wrapper">
<img class="img" src="https://images.unsplash.com/photo-1500622944204-b135684e99fd?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80" alt="">
<span class="label">Label</span>
</span>
</div>
<div class="wrapper200">
<span class="inner-wrapper">
<img class="img" src="https://images.unsplash.com/photo-1581622634376-ff17d073c4f7?ixlib=rb-1.2.1&auto=format&fit=crop&w=1832&q=80" alt="">
<span class="label">Label</span>
</span>
</div>
</div>
<h1>Heigth: 400px</h1>
<div class="container">
<div class="wrapper">
<span class="inner-wrapper">
<img class="img" src="https://images.unsplash.com/photo-1500622944204-b135684e99fd?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80" alt="">
<span class="label">Label</span>
</span>
</div>
<div class="wrapper">
<span class="inner-wrapper">
<img class="img" src="https://images.unsplash.com/photo-1581622634376-ff17d073c4f7?ixlib=rb-1.2.1&auto=format&fit=crop&w=1832&q=80" alt="">
<span class="label">Label</span>
</span>
</div>
</div>
You should try to use background-image instead of a single image
.wrapper {
width: 30%;
height: 400px;
overflow: hidden;
border: 1px solid black;
position: relative;
}
.img {
width: 100%;
height: 100%;
object-fit: contain;
background-size: contain;
background-repeat: no-repeat;
position: absolute;
top: 10%;
}
.label {
position: absolute;
top: 0;
right: 0;
padding: 15px;
background-color: #cccccc;
}
<div class="wrapper">
<div class="img" style="background-image:url(https://images.unsplash.com/photo-1500622944204-b135684e99fd?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80)" alt="">
<span class="label">Label</span>
</div>
</div>
I'm working hard on making a responsive image carousel but in the last stage (which I will explain) I can't get something to work. First let me give you what I have now, and then I will explain what suppose to happen.
html, body {
margin: 0;
overflow-x: hidden;
}
.vp-carousel {
width: 1000px;
height: 228px;
overflow: hidden;
margin-left: 50%;
transform: translate(-50%);
margin-top: 150px;
position: relative;
}
.carousel-wrapper {
height: 228px;
width: calc((1000px / 3) * 4);
}
.carousel-box {
display: inline-block;
width: calc(1000px / 3);
height: 100%;
margin-right: -4px;
position: relative;
}
.carousel-box img {height: 100%; width: 100%; }
.title {
position: absolute;
color: white;
z-index: 2;
height: 60px;
width: 100%;
text-align: center;
line-height: 30px;
top: calc(100% - 60px);
}
.mask {
width: 100%;;
height: 100%;
background-color: rgba(0,0,0,0.5);
position: absolute;
z-index: 1
}
#media screen and (max-width: 1080px) {
.vp-carousel {
width: calc(1000px * 0.66);
}
}
#media screen and (max-width: 700px) {
.vp-carousel {
width: calc(1000px * 0.33);
}
}
<div class="portfolio">
<div class="vp-carousel">
<div class="carousel-wrapper">
<div class="carousel-box">
<div class="title">
<p>Joomla! Website</p>
</div>
<div class="mask"></div>
<img src="http://www.hdwallpapers.in/walls/autumn_bench-HD.jpg">
</div>
<div class="carousel-box">
<div class="title">
<p>Joomla! Website</p>
</div>
<div class="mask"></div>
<img src="http://www.hdwallpapers.in/walls/autumn_bench-HD.jpg">
</div>
<div class="carousel-box">
<div class="title">
<p>Joomla! Website</p>
</div>
<div class="mask"></div>
<img src="http://www.hdwallpapers.in/walls/autumn_bench-HD.jpg">
</div>
<div class="carousel-box">
<div class="title">
<p>Joomla! Website</p>
</div>
<div class="mask"></div>
<img src="http://www.hdwallpapers.in/walls/autumn_bench-HD.jpg">
</div>
</div>
</div>
</div>
So what you see here is my simplified image carousel (to make it more clear), and in the last stage it show only one image (good!) but it's very small relative to the screen width of 700px (media query). What I want it to do is that it all increases to a bigger size (in ratio) and when the screen width gets smaller the image carousel decreases in size (in ratio).
I'm trying to make a div table with cells. Inside the cells I'd like to put another div which has circle shape. The problem which I've trying to solve is that I would like that when I resize the window of the browser, the div circle adapts to it and keeps the proportion.
As you can see in the images when I reduce the size of the window the size of the circle it's ok, but when the window it's in normal size the cirrcle it's too big and I don't know how to limit it.
https://gyazo.com/ebd2f44131dcc2e84b9d0e5cdaf12aed
reduced window
https://gyazo.com/6b8889f2d6c59b74bc7036061cf62627
https://gyazo.com/afb97aa2093e7331ae100420e1bac9c9
stylesheet.css
body,html{
height: 100%;
width: 100%;
}
.Table{
display: table;
position: relative;
margin: 0 auto 0 auto;
//border:solid;/////////////////////////////////////
// width: 100%;
// height: 100%;
background-color: yellow;
table-layout: fixed;
width:80%;
height:80%;
}
.Row{
display: table-row;
}
.Cell{
display: table-cell;
// border: 5px;
border:solid;
// border-color: black;
// border-radius: 25px;
//background-color: blue;
width: 33%;
height: 33%;
}
.circle {
width: 100%;
height:0;
padding-bottom: 100%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
background: #4679BD;
}
index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="estils.css">
</head>
<body>
<div class="Table">
<div class="Row">
<div class="Cell" >eeee</div>
<div class="Cell" >aaaaa</div>
<div class="Cell" >iiii</div>
</div>
<div class="Row">
<div class="Cell" >eeee</div>
<div class="Cell" >aaaaa</div>
<div class="Cell" >iiii</div>
</div>
<div class="Row">
<div class="Cell" >
<div class="circle" ></div>
</div>
<div class="Cell" >
<div class="circle" ></div>
</div>
<div class="Cell" >
<div class="circle" ></div>
</div>
</div>
</div>
</body>
<html>
You might want to use media-queries for that.
#media (min-width: 1000px)
.circle {
width: 100px;
height: 100px;
display: block;
margin: 0 auto;
padding: 0;
}
would do the trick. But the #media (max-width: 1000px) depends on the browser window's width.
Im trying to make an image grid for a web project what I intend to do is the following.!
Image
All the boxes will be images, i need to cover 50% of the div's width and 100% of it's height [white box]. The red boxes will cover 25% of div's width and 50% of it's height. Ive tried with image postion and with table and this i what i get
Image , i want to know if theres a better way to make this. Thanks for your help and time :)
<div class="source_miu">
<table border="1">
<tr>
<th rowspan="2"><img src="http://ns223506.ovh.net/rozne/a0983fdf5e6616a0e8515ad95ef1e10e/wallpaper-664645.jpg"></th>
<td><img src="http://ns223506.ovh.net/rozne/a039b13699e8fcfd8f6c676279355546/wallpaper-357877.jpg"></td>
<td><img src="http://ns223506.ovh.net/rozne/5c5b16fd81a613372f43fdf0f89235d4/wallpaper-988986.jpg"></td>
</tr>
<tr>
<td><img src="http://ns223506.ovh.net/rozne/1ce14f71e1b760232ddb978a60ef6383/wallpaper-664196.jpg"></td>
<td><img src="http://ns223506.ovh.net/rozne/9353f6e8133cc441f096552bbdbe8ebd/wallpaper-69508.jpg"></td>
</tr>
</table>
</div>
CSS
.source_miu{
width:100%;
padding:2%;
background-color: #3c3c3c;
}
.source_miu table{
width: 100%;
}
.source_miu table{
padding: 0;
margin: 0;
width: 100%;
}
.source_miu table th{
height: 50%;
width:50%;
}
.source_miu table td{
width: 25%;
height: 50%;
}
This should work, fiddle.
HTML
<div class="container">
<div class="left">
<img src="http://fc07.deviantart.net/fs71/f/2012/293/4/1/try_by_dranes-d5idgxw.png" />
</div>
<div class="right">
<img src="http://fc07.deviantart.net/fs71/f/2012/293/4/1/try_by_dranes-d5idgxw.png" />
<img src="http://fc07.deviantart.net/fs71/f/2012/293/4/1/try_by_dranes-d5idgxw.png" />
<img src="http://fc07.deviantart.net/fs71/f/2012/293/4/1/try_by_dranes-d5idgxw.png" />
<img src="http://fc07.deviantart.net/fs71/f/2012/293/4/1/try_by_dranes-d5idgxw.png" />
</div>
</div>
CSS
.container .left, .container .right
{
display: inline-block;
width: 50%;
float: left;
}
.container .left img
{
width: 100%;
}
.container .right img
{
display: inline-block;
width: 50%;
float: right;
}
Well you could determine the size of your pictures in pixels that way you can make sure the the 25% images are of same width and height.
50px just for the example.You can play whit it and try until you get a size that works for you.
<img src="your image.jpg" width="50px" height="50px">
This should also work, avoiding the use of display:inline-block; which doesn't work for IE7 or below -- doesn't matter if that doesn't matter though ;)
http://jsfiddle.net/H5npz/
markup:
<div class="panels">
<img class="a" src="/favicon.png" />
<img class="b" src="/favicon.png" />
<img class="b" src="/favicon.png" />
<img class="b" src="/favicon.png" />
<img class="b" src="/favicon.png" />
</div>
css:
.panels {
oveflow: hidden;
width: 400px;
height: 250px;
}
.panels .a, .panels .b {
float: left;
display: block;
margin: 0;
padding: 0;
}
.panels .a {
width: 50%;
height: 100%;
}
.panels .b {
width: 25%;
height: 50%;
}