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%;
}
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>
I have a responsive container and one image within it. It works good. The container and the image are resizing when the window-size changes. But, I need not only one, but more images which exactly overlap each other (all of them have the same size). How can I achieve this with HTML and CSS?
.pageCenter {
display: block;
max-width: 980px;
margin: 0 auto;
width: auto;
float: none;
border: 5px solid red;
}
.imageContainer img {
display: block;
margin: 0 auto;
width: auto;
}
img {
position: relative;
}
<div class="pageCenter">
<div class="imageContainer">
<img src="https://placeimg.com/400/200/nature" style="width:100%;" />
</div>
</div>
You could use grid in order to specify what row and column you want all images to sit in. They will then overlap and adjust to your container (do note the images I am using are all the same picture, but if you inspect, the 3 images are on-top of eachother:
.pageCenter {
display: block;
max-width: 980px;
margin: 0 auto;
width: auto;
float: none;
border: 5px solid red;
}
.imageContainer{
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 1fr;
margin: 0 auto;
width: auto;
}
img {
position: relative;
grid-row: 1;
grid-column: 1;
}
<div class="pageCenter">
<div class="imageContainer">
<img src="http://www.fillmurray.com/800/400" style="width:100%;" />
<img src="http://www.fillmurray.com/800/400" style="width:100%;" />
<img src="http://www.fillmurray.com/800/400" style="width:100%;" />
</div>
</div>
Also note that grid isn't supported by all old browser
.imageContainer {
position:relative;
}
.imageContainer .img-1 {
position:absolute;
top:0;
left:0;
}
.imageContainer .img-2 {
float:left;
}
.clearfix {
clear:both;
}
<div class="pageCenter">
<div class="imageContainer">
<img src="https://wow.olympus.eu/webfile/img/1632/x=1024/oly_testwow_stage.jpg" class="img-1" />
<img src="https://wow.olympus.eu/webfile/img/1632/x=1024/oly_testwow_stage.jpg" class="img-1" />
<img src="https://wow.olympus.eu/webfile/img/1632/x=1024/oly_testwow_stage.jpg" class="img-1" />
<img src="https://wow.olympus.eu/webfile/img/1632/x=1024/oly_testwow_stage.jpg" class="img-2" />
<div class="clearfix"></div>
</div>
</div>
You need to set the parent to position:relative; and the images (.child) to position:absolute;
Updated with images, they overlap.
Updated again with your code.
Update #3: You need to set one image to position:absolute and one to float and add a clearfix element.
I'm having a problem with my CSS, I assume. I want the picture of the lipstick to align with the face image and have the nail one underneath both of them.
HTML
<center>
<div id="homepage-image preventOverflow homepageHero {{ section.settings.height }} {{ section.settings.color }} index-section">
<div id="left">
<img width=600px type="image/jpeg" src="{{ 'lipstickpink.jpg' | asset_url}}" />
<!-- <img width=600px type="image/jpeg" src="{{ 'shadow.jpg' | asset_url}}" /> -->
</div>
<div id="right">
<div id="top-right">
<img width=900px type="image/png" src="{{ 'faceglam.png' | asset_url}}" />
</div>
<div id="bottom-right">
<img width=600px type="image/jpeg" src="{{ '11_Vertigo_1024x1024.jpg' | asset_url}}" />
</div>
</div>
</div> </center>
CSS
#container {
height: 100%;
width: 100%;
padding-top: $gutter*3;
padding-bottom: $gutter*2;
}
#left > img:nth-of-type(1) {
height: 85vh;
width: 70vw;
}
#left > img:nth-of-type(2) {
height: 65vh;
width: 49vw;
}
#left, #right {
display: inline-block;
}
#top-right, #bottom-right {
display: block;
}
#top-right > img:nth-of-type(1) {
width: 100vw;
height: 100vh;
}
#top-right > img:nth-of-type(2) {
width: 35vw;
height: 60vh;
}
#bottom-right > img:nth-of-type(1) {
width: 60vw;
height: 60vh;
}
#bottom-right > img:nth-of-type(2) {
width: 20vw;
height: 25vh;
}
I have also provided an image of the problem:
It's not completely clear how (i.e in which direction) you want them aligned.
You have a lot of seemingly unnecessary divs - i wondered why.. so I have adjusted both HTML and CSS (used own images from internet)
If I got them in the wrong order, just adjust the images. I adjusted heights (re-adjustable obviously)- but hope you get the general gist!
Hope this helps
#container {
height: 100%;
width: 100%;
margin: 0;
padding-top: $gutter*3;
padding-bottom: $gutter*2;
}
#left{
margin-left:10%;
margin-right:10%;
}
#left > img:nth-of-type(1) {
max-height:200px;
padding:5px;
height:auto;
}
#left > img:nth-of-type(2) {
max-height:300px;
padding:5px;
height: 60vh;
}
#left,
#right {
display: inline-block;
}
#right > img:nth-of-type(1) {
max-height:300px;
height: auto;
margin-left:18vw;
margin-right:18vw;
}
<div id="container">
<div id="left">
<img src="https://lh3.googleusercontent.com/czZtMqTum5GQOYL1NxogiEVZ57Zr5LG0chnil-p3YFTjl3WIQdrADqpaaATmyN-JGjey=h900" alt="face" />
<img src="http://bpc.h-cdn.co/assets/16/38/480x480/gallery-1474299136-urban-decay-vice-pink-lipstick.jpg" alt="lipstick" />
</div>
<div id="right">
<img src="http://www.vipera.com.pl/wp-content/uploads/2016/08/20zestawy_lakier__w_do_artystycznego_zdobienia_paznokci________artistic_manicure_set___219.jpg" alt="nails" />
</div>
</div>
Fiddle
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;
}
}
I want to have a div with two images on the left, some centered text and some text on the right.
One of the many attempts:
http://jsfiddle.net/yu8bz4h4/
The problem is that I cant figure out how to get the p elements in the same line while keeping center and right the alignments
HTML:
<div class="outer">
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<p class="center" >centered</p>
<p class="right" >right</p>
</div>
CSS:
.outer {
height: 50px;
width: 800px;
}
.icon {
width: 44px;
height: 44px;
}
.outer p {
margin 0;
}
.center {
text-align: center;
width: auto;
}
.right {
text-align: right;
width: auto;
}
Replace all p with div.Then write css code.The text comes in one line.
Hope this works.
.outer {
height: 50px;
width: 800px;
}
.icon {
width: 44px;
height: 44px;
}
.outer p {
margin 0;
}
.center {
margin-left:50%;
width: auto;
position:absolute
}
.right {
margin-left:100%;
width: auto;
position: absolute;
}
<div class="outer">
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<div class="center" >centered</div>
<div class="right" >right</div>
</div>
I am pretty much sure you wanted something like this. Though your question is not clear. Never forget to write codes with semantic meaning. Here's your solution following more semantic way: codepen.
Or here:
.outer {
height: 50px;
width: 800px;
overflow: hidden;
}
.column {
width: 33.33%;
float: left;
}
.icon {
width: 44px;
height: 44px;
margin-right: 10px;
}
.center {
text-align: center;
}
.right {
text-align: right;
}
<div class="outer">
<div class="column">
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
</div>
<div class="column">
<p class="center">centered</p>
</div>
<div class="column">
<p class="right">right</p>
</div>
</div>
Revised code in response to OP's comments:
.outer {
height: 50px;
width: 300px;
position: relative;
}
.icon {
width: 44px;
height: 44px;
float: left;
}
.center {
text-align: center;
width: 100%;
position: absolute;
left: 0;
}
.right {
position: absolute;
right: 0;
width: auto;
}
<div class="outer">
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<p class="center">centered</p>
<p class="right">right</p>
</div>