adding Masonry style images to section of a website - html

Ive been trying to add a masonry section of images to my website. However it is not aligning correctly. It just stacks the pictures onto of each other. How could I go about creating a masonry section using css/html? Or maybe creating a table that gives the masonry effect?
MY HTML:
<div class="masonry">
<div class="item">IMAGE GOES HERE</div>
<div class="item">SECOND IMAGE </div>
THIRD IMAGE
<div class="item">FOURTH IMAGE</div>
</div>
MY CSS:
.masonry { /* Masonry container */
column-count: 4;
column-gap: 1em;
}
.item { /* Masonry bricks or child elements */
background-color: #eee;
display: inline-block;
margin: 0 0 1em;
width: 100%;
}
The picture below is what I am trying to achieve:

Here you go:
#container {
height: 100%;
width: 100%;
}
#left > img:nth-of-type(1) {
height: 25vh;
width: 35vw;
}
#left > img:nth-of-type(2) {
height: 60vh;
width: 35vw;
}
#left, #right {
display: inline-block;
}
#top-right, #bottom-right {
display: block;
}
#top-right > img:nth-of-type(1) {
width: 25vw;
height: 60vh;
}
#top-right > img:nth-of-type(2) {
width: 35vw;
height: 60vh;
}
#bottom-right > img:nth-of-type(1) {
width: 40vw;
height: 25vh;
}
#bottom-right > img:nth-of-type(2) {
width: 20vw;
height: 25vh;
}
<div id="container">
<div id="left">
<img src="Image 1">
<br>
<img src="Image 2">
</div>
<div id="right">
<div id="top-right">
<img src="Image 3">
<img src="Image 4">
</div>
<div id="bottom-right">
<img src="Image 5">
<img src="Image 6">
</div>
</div>
</div>

Related

HTML make left and right div with left-one position:fixed

I want to create page with navigation menu on left side which will be fixed there.
In the center of the screen should be main content of page.
I made this:
HTML:
<div>
<Sidepanel></Sidepanel>
<div class="content">
<div class="item">
<img src="#/assets/1.jpg">
</div>
<div class="item">
<img src="#/assets/2.jpg">
</div>
<div class="item">
<img src="#/assets/3.jpg">
</div>
<div class="item">
<img src="#/assets/4.jpg">
</div>
</div>
</div>
HTML for sidepanel:
<div class="Sidepanel">
<div>
Home
</div>
<div>
1234
</div>
<div>
Settings
</div>
</div>
CSS:
.Sidepanel {
background-color: #5555FF;
float: left;
padding: 1em;
/*width: 200px;*/
height: 100%;
overflow: auto;
position: fixed;
}
.Sidepanel div {
margin: 5% 0 5% 0;
}
a {
color: black;
font-size: calc(1em + 1vw);
}
body {
margin: 0
}
.content {
-webkit-columns: 2 200px;
-moz-columns: 2 200px;
columns: 2 200px;
}
.content img {
width: 90%;
object-fit: cover;
}
And on the resulting page right div goes under left. It works well if I remove position:fixed, but then I loose fixed menu on scroll.
You can try with grid. Pls. look at snippet below:
.Sidepanel {
background-color: #5555FF;
padding: 1em;
height: 100%;
overflow: auto;
position: fixed;
grid-column: 1;
}
.Sidepanel div {
margin: 5% 0 5% 0;
}
a {
color: black;
font-size: calc(1em + 1vw);
}
body {
margin: 0
}
.container {
display: grid;
grid-template-columns: minmax(0,200px) 1fr;
}
.content {
-webkit-columns: 2 200px;
-moz-columns: 2 200px;
columns: 2 200px;
grid-column: 2;
justify-self: start;
}
.content img {
width: 90%;
object-fit: cover;
}
#media (max-width: 500px) {
.container {
grid-template-columns:30% 1fr;
}
}
<div class="container">
<Sidepanel>
<div class="Sidepanel">
<div>
Home
</div>
<div>
1234
</div>
<div>
Settings
</div>
</div>
</Sidepanel>
<div class="content">
<div class="item">
<img src="https://picsum.photos/200">
</div>
<div class="item">
<img src="https://picsum.photos/200">
</div>
<div class="item">
<img src="https://picsum.photos/200">
</div>
<div class="item">
<img src="https://picsum.photos/200">
</div>
</div>
</div>

Scaling two different imgsto fit the screen

I'm trying to scale two images to fit a mobile screen with both keeping their original proportions without overflow. When I've tried to apply max-width it only kicks in when one image falls below screen width.
.one img {
position: absolute;
width: 200px;
height: 200px;
}
.two img {
position: absolute;
margin-left: 200px;
width: 300px;
height: 200px;
}
<div class="one"><img src="https://upload.wikimedia.org/wikipedia/commons/5/57/Distribution_H._leucocephalus.png"></div>
<div class="two"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Back_to_the_Six_Mile_Lake_eagles_%28Haliaeetus_leucocephalus%29.%22feed_me_mom%22._%2819159890706%29.jpg/800px-Back_to_the_Six_Mile_Lake_eagles_%28Haliaeetus_leucocephalus%29.%22feed_me_mom%22._%2819159890706%29.jpg"></div>
Try:
* {
margin: 0;
padding: 0;
}
.slider {
display: flex;
}
.slider .slide img {
width: 100%;
}
<div class="slider">
<div class="slide">
<img src="https://upload.wikimedia.org/wikipedia/commons/5/57/Distribution_H._leucocephalus.png" style="max-width: 200px;">
</div>
<div class="slide">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Back_to_the_Six_Mile_Lake_eagles_%28Haliaeetus_leucocephalus%29.%22feed_me_mom%22._%2819159890706%29.jpg/800px-Back_to_the_Six_Mile_Lake_eagles_%28Haliaeetus_leucocephalus%29.%22feed_me_mom%22._%2819159890706%29.jpg"
style="max-width: 300px;">
</div>
</div>
Check this:
.container {
display: flex;
}
.one img {
width: 100%;
max-width: 200px;
}
.two img {
width: 100%;
max-width: 300px;
}
<div class="container">
<div class="one"><img src="https://upload.wikimedia.org/wikipedia/commons/5/57/Distribution_H._leucocephalus.png"></div>
<div class="two"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Back_to_the_Six_Mile_Lake_eagles_%28Haliaeetus_leucocephalus%29.%22feed_me_mom%22._%2819159890706%29.jpg/800px-Back_to_the_Six_Mile_Lake_eagles_%28Haliaeetus_leucocephalus%29.%22feed_me_mom%22._%2819159890706%29.jpg"></div>
</div>
.one, .two {
width:50%; float:left
}
.one img, .two img {
width: 100%;
}
<div class="one"><img src="https://upload.wikimedia.org/wikipedia/commons/5/57/Distribution_H._leucocephalus.png"></div>
<div class="two"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Back_to_the_Six_Mile_Lake_eagles_%28Haliaeetus_leucocephalus%29.%22feed_me_mom%22._%2819159890706%29.jpg/800px-Back_to_the_Six_Mile_Lake_eagles_%28Haliaeetus_leucocephalus%29.%22feed_me_mom%22._%2819159890706%29.jpg"></div>
Can you please check this and let me know, if this is the same you are looking for.

Hidden overflow not working on image

I have tried using overflow: hidden; for each element but it does not seem to be doing anything
The html looks like this, the display is to have the 2 divs side by side (stacks ontop for smaller screens). The left side div will also be on top of the right side div. I have a screen shot and fiddle too.
.sec {
background-color: red;
min-height: 100vh;
overflow: hidden;
}
.sec2 {
background-color: blue;
min-height: 100vh;
overflow: hidden;
}
.img1 {
max-width: 100%;
position: absolute;
}
.img1 {
z-index: 1;
}
.leftCol {
z-index: 10;
width: 50%;
}
.info-row {
display: flex;
flex-direction: row;
margin-left: 10vw;
margin-right: 200px;
}
.rightCol {
width: 50%;
}
<section class="sec">
<div class="info-row">
<div class="leftCol info-column">
<h1>haheaheh</h1>
<p>teataetetat</p>
</div>
<div class='rightCol info-column'>
<img class="img1" src='https://kasonbloom.files.wordpress.com/2017/08/lamb-2.jpg' />
</div>
</div>
</section>
<section class="sec2">
<div class="info-row">
<div class="leftCol info-column">
<h1>asdfasdfasdf</h1>
<p>basfbasdfbasdfba</p>
</div>
<div class='rightCol info-column'>
</div>
</div>
</section>
https://jsfiddle.net/gtrnrd9r/2/ keep result view at a point where the image breaks through the section
Add position:relative; to your outer section .sec and it will work fine.
.sec {
background-color: red;
min-height: 100vh;
overflow: hidden;
position:relative;
}
.sec2 {
background-color: blue;
min-height: 100vh;
overflow: hidden;
}
.img1 {
max-width: 100%;
position: absolute;
}
.img1 {
z-index: 1;
}
.leftCol {
z-index: 10;
width: 50%;
}
.info-row {
display: flex;
flex-direction: row;
margin-left: 10vw;
margin-right: 200px;
}
.rightCol {
width: 50%;
}
<section class="sec">
<div class="info-row">
<div class="leftCol info-column">
<h1>haheaheh</h1>
<p>teataetetat</p>
</div>
<div class='rightCol info-column'>
<img class="img1" src='https://kasonbloom.files.wordpress.com/2017/08/lamb-2.jpg' />
</div>
</div>
</section>
<section class="sec2">
<div class="info-row">
<div class="leftCol info-column">
<h1>asdfasdfasdf</h1>
<p>basfbasdfbasdfba</p>
</div>
<div class='rightCol info-column'>
</div>
</div>
</section>
.rightCol needs his own width and height if i'm not mistaken. overflow doesn't work with the parent element.

CSS images not aligning correctly

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

Flexbox collage grid layout

Is it possible make this layout with pure css without the flexbox properties?
I try to create the photo gallery collage for the VC slider. Is it possible to use here grid properties? I use nesting flexbox, what is the best practice? flexbox gallery collage
<div class="contaner">
<div class="item">
<img src="http://www.telegraph.co.uk/content/dam/pets/2016/05/31/66900964_AR6KDA-CAT-BIRD-PETS-large_trans++XgrBd0P19THPvf9738yRPd-JR69WJ8Rdth_SfFJ_dbY.jpg" alt="" />
</div>
<div class="item item-flex">
<img class="item-flex-img-big" src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" />
<img class="item-flex-img" src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" />
</div>
<div class="item item-flex">
<img class="item-flex-img" src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" />
<img class="item-flex-img-big" src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" />
</div>
<style>
img {
width: 100%;
max-width: 100%;
object-fit: cover;
object-position:50% 50%;
height: 100%;
}
.contaner {
display: flex;
.item {
flex: 1 1 100%;
}
.item + .item {
padding-left: 10px;
}
.item-flex {
display: flex;
flex-direction: column;
}
.item-flex {
img + img {
margin-top:10px;
}
}
.item-flex-img{
height: 40%;
}
.item-flex-img-big{
height: 60%;
}
}
</style>
You may take a look at column CSS.
.contaner {
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
-webkit-column-rule-width: 5px;
-moz-column-rule-width: 5px;
column-rule-width: 5px;
height: 600px;
width: 1200px;
padding: 15px 15px 0;
overflow: hidden;
}
span {
display: block;
overflow: hidden;
height: calc(40% - 15px);
min-width: 100%;
margin: 0 0 15px;
}
span:nth-child(1) {
height: calc(100% - 15px);
}
span img {
width: 100%;
object-fit: cover;
object-position:50% 50%;
height: 100%;
}
span:nth-child(2),
span:nth-child(5) {
height: calc(60% - 15px);
}
span:nth-child(1) img {
height: 100%;
margin: 0;
object-position:10% 50%;
}
/* snippet purpose */
body {
margin: 0;
}
.contaner {
box-sizing: border-box;
height: 100vh;
width: 200vh;
}
<div class="contaner">
<span><img src="http://www.telegraph.co.uk/content/dam/pets/2016/05/31/66900964_AR6KDA-CAT-BIRD-PETS-large_trans++XgrBd0P19THPvf9738yRPd-JR69WJ8Rdth_SfFJ_dbY.jpg" alt="" /></span>
<span><img src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" /></span>
<span><img src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" /></span>
<span><img src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" /></span>
<span><img src="https://upload.wikimedia.org/wikipedia/commons/b/bf/Blue_Tiger_Im_IMG_9450.jpg" alt="" /></span>
</div>
notice: each image are wrapped in a single span all sibblings (could be figure or any tag else)