Image gallery block with CSS with different image dimension? - css

I was trying to achieve the below layout with CSS. Here is the layout snap:
https://archive.org/details/Untitled1_20161122
Without masonry as this is not possible with masonry I guess (row/column width/height both changes which is not the case in masonry, I might be wrong though). Is there a nice pure CSS solution. It would be much appreciated. I have been searching for a CSS solution for quite long. www.bata.com for example have similar result in their homepage if that helps to explain the purpose, and without masonry as far as I am concerned.
Here is my code:
.gallery {
width: 70%;
margin: 0 auto;
background: crimson;
position: relative;
}
.col-20 {
width: 20%;
float: left;
/*border: 1px solid red;*/
}
.col-40 {
width: 40%;
float: left;
/*border: 1px solid red;*/
}
.col-60 {
width: 60%;
float: left;
/*border: 1px solid red;*/
}
div {
overflow: hidden;
}
img {
width: 100%;
height: auto;
}
<div class="gallery">
<div class="col-40">
<img src="1.png" alt="">
</div>
<div class="col-20">
<img src="2.jpg" alt="">
</div>
<div class="col-20">
<img src="3.jpg" alt="">
</div>
<div class="col-20">
<img src="4.png" alt="">
</div>
<div class="col-20">
<img src="2.jpg" alt="">
</div>
<div class="col-20">
<img src="3.jpg" alt="">
</div>
</div>
Thank you in advance.

If you are fine with a static layout, you could use a table with a fixed layout and no borders.
https://css-tricks.com/fixing-tables-long-strings/
Set your images as backgrounds for the table with background-size: cover;
Then using width, colspan and rowspan, create a fixed layout on your table.

Related

Create 6 boxes with css

I really need some help with some easy css that I just can't get my head around.
I want to create boxes like in the link below.
I guess I could have the code for just one of them, and then use it over and over again, but how do I create the boxes so that they don't mind the other stuff around them?
Example here: http://s23.postimg.org/qypbfvv0r/boxes.jpg
Here: I have figured out a way of doing this. I hope that this helps you in some way in helping you figure out how to finish your task.
HTML:
<div class="containers">
<p class="heading">Heading</p>
<div class="inner1"></div>
<div class="inner2"></div>
</div>
<div class="containers">
<p class="heading">Heading</p>
<div class="inner1"></div>
<div class="inner2"></div>
</div>
<div class="containers">
<p class="heading">Heading</p>
<div class="inner1"></div>
<div class="inner2"></div>
</div>
CSS:
.containers {
width: 300px;
height: 150px;
border: 1px solid black;
margin-bottom: 10px;
overflow: hidden;
position: relative;
}
.inner1 {
margin-left: 5px;
width: 135px;
height: 80px;
border: 1px solid black;
background-color: blue;
}
.inner2 {
position: relative;
float: right;
top: -60%;
margin-left: 5px;
margin-right: 5px;
width: 135px;
height: 80px;
border: 1px solid black;
background-color: red;
}
.heading {
padding-left: 20px;
}
You can start off using this code. After this you can give border styles and colors to the individual divs.
<div>
<div style="float:right"> Content </div>
<div style="float:left"> Content </div>
</div>
<div style="padding-top:10px">
<div style="float:right"> Content </div>
<div style="float:left"> Content </div>
</div>
<div style="padding-top:10px">
<div style="float:right"> Content </div>
<div style="float:left"> Content </div>
</div>
Hope this helps

CSS div position gets messed up on zooming the browser

I'm developing a website for Facebook application which is based on grid image layout. The following code works fine for me but when i zoom my browser everything gets messed up. browser with 100% zoom view works. please help me to find some other code if possible or fix the following code.
<style>
div.img {
margin: 5px;
padding: 5px;
border: 1px solid #0000ff;
height: auto;
width: auto;
float: left;
text-align: center;
}
div.img img {
display: inline;
margin: 5px;
border: 1px solid #ffffff;
}
div.img a:hover img {
border: 1px solid #0000ff;
}
div.desc {
text-align: center;
font-weight: normal;
width: 120px;
margin: 5px;
}
</style>
HTML:
<div class="img">
<a target="_blank" href="klematis_big.htm"><img src="image1.jpg" alt="PHOTO" width="110" height="90"></a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis2_big.htm"><img src="image2.jpg" alt="PHOTO" width="110" height="90"></a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis3_big.htm"><img src="image3.jpg" alt="PHOTO" width="110" height="90"></a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis4_big.htm"><img src="image4.jpg" alt="PHOTO" width="110" height="90"></a>
<div class="desc">Add a description of the image here</div>
</div>
I updated the fiddle of Sdghasemi. Added fallback for older browsers without width calculation function and set the image width to 100% and cleaned up the Html a little (closing image tags etc)
The reason that images where flowing out of the container div was the width and height attributes in the HTML. I set it now to 100% of the container. Meaning 100% -2px because of the border. Same with the image caption.
<div class="img">
<a target="_blank" href="klematis_big.htm">
<img src="http://lorempixel.com/110/90/" alt="PHOTO"/>
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis2_big.htm">
<img src="http://lorempixel.com/110/90/" alt="PHOTO"/>
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis3_big.htm">
<img src="http://lorempixel.com/110/90/" alt="PHOTO"/>
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis4_big.htm">
<img src="http://lorempixel.com/110/90/" alt="PHOTO"/>
</a>
<div class="desc">Add a description of the image here</div>
</div>
css:
div.img {
margin: 5px;
padding: 5px;
border: 1px solid #0000ff;
height: auto;
width: 24%;
width: calc(25% - 22px);
float: left;
display: block;
overflow: hidden;
text-align: center;
font-size: 100%;
}
div.img a:hover img {
border: 1px solid #0000ff;
}
div.img img{
width: 99%;
width: calc(100% - 2px);
border: 1px solid #fff;
}
div.desc {
text-align: center;
font-weight: normal;
width: 100%;
width: calc(100% - 10px);
margin: 5px;
}
http://jsfiddle.net/or2ua75e/5/
In this case you have to use CSS's calc() function to calculate the right width of every image on page resize or zoom:
width: calc(24.9% - 22px);
the reason i used 22px: 2 * (margin + border.width + padding) for every image.
and use 24.9% instead of 25 for sure.
See working FIDDLE here

Responsive Square Parent, with responsive square background image

What I need is simple, but I'm striking out.
I need to create three divs that are a perfect responsive square using vws.
Inside those div's I need div's with a background image that are also perfect squares when you scale your browser.
The catch is that I need the background image to always be a square as well, and resize accordingly so that none of the image is clipped off.
Here's a fiddle:
http://jsfiddle.net/Lm7qd/2/
<div class="image-wrapper">
<div class="image">
</div>
</div>
<div class="image-wrapper">
<div class="image">
</div>
</div>
<div class="image-wrapper">
<div class="image">
</div>
</div>
.image-wrapper {
width: 90vw;
height: 90vw;
border: 1px solid #ccc;
}
.image {
background-image: url('http://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Square_on_plane.svg/200px-Square_on_plane.svg.png');
background-repeat: no-repeat;
background-size:contain;
background-position:center;
background-size: 100%;
margin-bottom: 30px;
padding: 100px;
}
html
<div class="image-wrapper">
<div class="image">
<img src="http://3.bp.blogspot.com/--7gtJQo5mHE/UGMKHZapqmI/AAAAAAAAWGU/5X26Pgj_St4/s1600/funny-cat-pictures-017-005.jpg"/>
</div>
<div class="image">
<img src="http://3.bp.blogspot.com/--7gtJQo5mHE/UGMKHZapqmI/AAAAAAAAWGU/5X26Pgj_St4/s1600/funny-cat-pictures-017-005.jpg"/>
</div>
<div class="image">
<img src="http://3.bp.blogspot.com/--7gtJQo5mHE/UGMKHZapqmI/AAAAAAAAWGU/5X26Pgj_St4/s1600/funny-cat-pictures-017-005.jpg"/>
</div>
css
.image-wrapper {
width: 90vw;
height: 90vw;
border: 1px solid #ccc;
}
.image {
margin-bottom: 30px;
width: 100%;
}
.image img {
width: 100%;
}
http://jsfiddle.net/Lm7qd/12/
I'm not sure if this is what you are looking for because the only square i see here is the image-wrapper. Please check this out.
Fiddle
if this is not what you are looking for, can you post some of the images of your desired output.

How to Align Vertically the image in a div?

How to display the image as vertical align in div container?
The image "setting.png" placed in last column in the code i attached. please advice solution please.
.table{
width: 100%;
margin: 20px 0px 20px 0px;
background-color: #EEEEEE;
}
.tableRow{
width: 100%;
clear: both;
height: 40px;
line-height: 40px;
border-bottom: 1px solid #cccccc;
}
.tableCol{
float: left;
height: 40px;
line-height: 40px;
}
<div class="table">
<div class="tableRow">
<div class="tableCol" style="width:10%; text-align:center;">1</div>
<div class="tableCol" style="width:40%">Michael</div>
<div class="tableCol" style="width:40%">webexp#gmail.com</div>
<div class="tableCol" style="width:10%;">
<a href="" ><img src="images/icons/setting.png" alt="Setting" align="absmiddle" /></a>
</div>
</div>
</div>
Just add (space before a link)
<div class="table">
<div class="tableRow">
<div class="tableCol" style="width:10%; text-align:center;">1</div>
<div class="tableCol" style="width:40%">Michael</div>
<div class="tableCol" style="width:40%">webexp#gmail.com</div>
<div class="tableCol" style="width:10%;">
<a href="" ><img src="images/icons/setting.png" alt="Setting" align="absmiddle" /></a>
</div>
</div>
</div>
better solution:
add this to css:
img {
margin-top:10px;
}
Here, this should work:
Add this to your div which contains the image that should be centered.
display:table-cell;
vertical-align:middle;
This should center the image vertically no matter the dimensions of your div or the image that it contains.
You can do this with position: absolute; if you know the dimensions of the settings.png image (20px x 20px for this example).
Add class tableColSettings to the <a> around the settings image. Then add CSS;
.tableColSettings{
position: absolute;
display: block;
top: 50%;
left: 50%;
margin: -10px 0 0 -10px; /* Half image dimensions */
width: 20px;
height: 20px;
line-height: 0;
}
.tableColSettings img{
width: 100%;
}
The settings image will always stay in the center of the element, no matter the height. Here's a working fiddle: http://jsfiddle.net/384pa/
Hope this helps!
Css is having a tag name
"vertical-align" may be you will get your solution

css multi column issue

can you please help me with some css magic.
I am trying to achieve a flixable multi column layout. something like this http://masonry.desandro.com/demos/basic-multi-column.html can I achive this with Blueprint and no javascript.
the thing with blueprint now is that is added lots of white space (see attachment)
Following is just sample one.. You just change width/height according to your requirement. Hope this helps.
CSS
----
.content {
float: left;
display: block;
width: 1000px;
background: red;
}
.sub-content {
float:left;
width: 200px;
background: blue;
margin: 10px;
}
Sample HTML
-----------
<div class="content">
<div class="sub-content" style="width: 500px; height: 300px;">
DIV 1
</div>
<div class="sub-content" style="width: 200px; height: 100px;">
DIV 2
</div>
<div class="sub-content" style="width: 500px; height: 300px;">
DIV 3
</div>
<div class="sub-content" style="width: 250px; height: 300px;">
DIV 4
</div>
</div>

Resources