Evenly spaced image grid - css

I've been all over this site, but haven't found decent solution yet.
I'm making a photography site that has a fixed menubar div on the left and the content div flowing on the right. In the photo gallery page there should be a grid of image thumbnails with fluid margins so that the thumbnails are always evenly spaced across the right (content) div.
Here's the structure:
<body>
<div id="wrapper">
<div id="left_column">
<div class="navigation"></div>
</div>
<div id="right_column">
<div id="thumb_container" class="grayscale">
<div id="thumb_fx" ></div>
<img src="images/testimg.jpg" width="240" height="187" />
</div>
...
<div id="thumb_container" class="grayscale">
<div id="thumb_fx" ></div>
<img src="images/testimg.jpg" width="240" height="187" />
</div>
</div>
</div>
</body>
^There is a vignette roll over animation in each thumbnail.
And the CSS:
html {
height: 100%;
padding:0;
margin:0;
}
body {
height: 100%;
padding: 0;
margin: 0;
}
#wrapper {
float: left;
height: 100%;
width:100%;
padding:0;
margin:0;
}
#left_column {
position: fixed;
top: 0;
bottom: 0;
left: 0;
z-index:100;
width: 240px;
height: 100%;
overflow: hidden;
background-color:#ff0000;
}
#right_column {
background-color:#cccccc;
width:auto;
height:100%;
margin-left: 240px;
position: absolute;
}
#thumb_container {
position: relative;
max-width:50%;
min-width:240px;
height:auto;
border-color:#000000;
display: inline-block;
margin: 2%;
}
#thumb_fx {
opacity: 1;
filter: alpha(opacity=100);
-webkit-transition: opacity 0.5s linear;
transition: 0.5s;
-moz-transition: 0.5s; /* Firefox 4 */
z-index: 100;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: transparent;
box-shadow:inset 0px 0px 85px rgba(0,0,0,1);
-webkit-box-shadow:inset 0px 0px 85px rgba(0,0,0,1);
-moz-box-shadow:inset 0px 0px 85px rgba(0,0,0,1);
}
#thumb_fx:hover {
opacity: 0;
filter: alpha(opacity=0);
-webkit-transition: opacity 0.5s linear;
transition: 0.5s;
-moz-transition: 0.5s; /* Firefox 4 */
}
.grayscale img{
max-width:100%;
min-width:50%;
height:auto;
position: relative;
border:none;
z-index: -1;
position: relative;
}
The best solution so far is this: http://jsfiddle.net/VLr45/1/ but the margins go way too tight before the div is dropped to the next row. And I don't understand how to adjust them.
Any help?

When you calculate the number of boxes that will fit, add the minimum margin you would like:
Margin as pixels
var boxMinMargin = 10; // 10px
var columns = Math.floor(parent / (box + boxMinMargin));
http://jsfiddle.net/VLr45/14/
Margin as %
var boxMinMargin = box * 0.1; // 10% of box
var columns = Math.floor(parent / (box + boxMinMargin));
http://jsfiddle.net/VLr45/24/
If you prefer to set the margin with css, you can set the width in you box class
.box {
margin: 2%;
/*
or
margin-top: 2%;
margin-right: 3%;
margin-bottom: 4%;
margin-left: 5%;
*/
}
http://jsfiddle.net/VLr45/17/

Related

Adding Blur Effect On Image

For adding blur effect on image, I create another element from the same image with absolute position, low opacity and blur effect. I don't think this is efficient. What's the best approach for this situation?
<img src="./images/shopping.svg" />
<img style="position: absolute;opacity: 0.5;filter: blur(10px);" src="./images/shopping.svg" />
Preview
You can use drop-shadow filter, to achieve the desired effect. This also kills the need of using second img tag.
body{
background: #222;
}
img{
filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.5)) invert(100%);
/* Note - I used invert(100%) to invert the colors since the original svg was black.
If you want to remove it, you need to use rgba(255, 255, 255, 0.5) for white
shadow.
*/
}
<img src="https://www.svgrepo.com/show/80543/shopping-cart-outline.svg" width="300" />
blur hover effect using like this may be it's helping us:
.column {
margin: 15px 15px 0;
padding: 0;
}
.column:last-child {
padding-bottom: 60px;
}
.column::after {
content: '';
clear: both;
display: block;
}
.column div {
position: relative;
float: left;
width: 300px;
height: 200px;
margin: 0 0 0 25px;
padding: 0;
}
.column div:first-child {
margin-left: 0;
}
.column div span {
position: absolute;
bottom: -20px;
left: 0;
z-index: -1;
display: block;
width: 300px;
margin: 0;
padding: 0;
color: #444;
font-size: 18px;
text-decoration: none;
text-align: center;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
opacity: 0;
}
figure {
width: 300px;
height: 200px;
margin: 0;
padding: 0;
background: #fff;
overflow: hidden;
}
figure:hover+span {
bottom: -36px;
opacity: 1;
}
/* Blur */
.hover07 figure img {
-webkit-filter: blur(3px);
filter: blur(3px);
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.hover07 figure:hover img {
-webkit-filter: blur(0);
filter: blur(0);
}
<div class="hover07 column">
<div>
<figure><img src="https://picsum.photos/300/200?image=244" /></figure>
<span>Hover</span>
</div>
<div>
<figure><img src="https://picsum.photos/300/200?image=1024" /></figure>
<span>Hover</span>
</div>
</div>

Sliding box on mouse over - CSS

I'ld like to know if there is a better way to do this:
Also I don't think it will work smoothly in a responsive page so do you have any ideas to make it work without certain positionings like 'bottom:-45px;'.
I just wondered about this so this is not something that I'm going to use somewhere.
I know it could be done with jquery easily but I wonder if there is a chance to achieve this effect with pure CSS
.d1 {
width: 320px;
border: none;
padding: 10px;
margin: 10px 0px;position: relative;
}
.d2 {
width: 70%;
position: relative;
left: 0px;
right: 0px;
padding: 20px 0px;
margin: 10px 0px;
border: none;
}
.d3 {
width: 90%;position: relative;
left: 0px;
margin: 20px 0px;
padding: 20px 0px;
right: 0px;
border: none;
}
.d3 p, .d2 p, d1 p {
z-index:999;
position:relative;
}
.hov {
width: 40%;
padding: 20px 10px;
background-color: #300;
position:relative;
opacity:0;
bottom:-45px;left:0px;
z-index:0;
pointer-events: none;
transition: all 0.3s cubic-bezier(0.175, 1.285, 0.32, 1.275);
}
.d2 { pointer-events: none;}
.d3 { pointer-events: auto;}
.d2:hover .hov{
opacity:1;
bottom:-123px;
}
.d1:hover .hov{
opacity:1;
}
<div class="d1">
div1
<div class="d2">
<div class="hov" id="hov">
</div>
<p>
div2
</p>
<div class="d3">
<p>
div3</p>
</div>
</div>
</div>
Actually I think I managed to do it. In this case there are two elements so I placed them to top and bottom of the main container.
.d1 {
width: 320px;
padding: 10px;
margin: 10px;
position: relative;
cursor: default;
}
.d2 {
position: relative;
margin-top: -15px;
margin-bottom: 60px;
}
.d3 {
position: relative;
margin-bottom: -15px;
}
.d3 p,
.d2 p {
z-index: 999;
position: relative;
}
.hov {
width: 40%;
height: 40%;
background-color: #300;
position: absolute;
opacity: 0;
top: 0%;
left: 0px;
z-index: 0;
transition: all 0.3s cubic-bezier(0.175, 1.285, 0.32, 1.275);
}
.d3:hover+.hov {
top: 60%;
}
.d1:hover .hov {
opacity: 1;
}
<div class="d1">
<div class="d2">
<p> div2 </p>
</div>
<div class="d3">
<p> div3 </p>
</div>
<div class="hov"></div>
</div>
Generally, what you would call a 'certain positioning' would be required, but if you were to run it with a responsive page, the user, with a mobile phone, would have to click the area, before it moves, instead of hovering it. Using pure CSS would be a drag, because you have to literally loop over the codes all around.
My advice is, it's generally okay to use a specific number (i.e. -45px) as long as it's only for vertical measurements.

Issue With Overlapping Fixed Objects

Here's a fiddle:
Fiddle
CSS:
.navbar img{
background: #0066FF;
width: 50px;
position: fixed;
margin-bottom: 20%;
transition: width 0.5s;
-webkit -transition: width 0.5s;
}
.navbar img:hover{
background: #99CCFF;
width: 125px;
clear: both;
}
#1{
top: 0px;
}
#2{
top: 50px;
margin-top: 50px;
}
#3{
top: 100px;
}
#4{
top: 150px;
}
body {
margin: 0px;
}
Essentially, I just want each individual square to not overlap each other. I've been trying to use margins, but I must be doing something wrong. Any help?
if you don't need to have the fixed position you can do it this way:
http://jsfiddle.net/ry59aomd/3/
your css code can be simplified to:
.navbar img{
background: #0066FF;
width: 50px;
transition: width 0.5s;
-webkit -transition: width 0.5s;
}
.navbar a{
display:block;
float:left;
clear:both;
}
.navbar img:hover{
background: #99CCFF;
width: 125px;
}
Your html code can be simplified too:
<div class="navbar">
<img src="logo.png"/>
<img src="logo.png"/>
<img src="logo.png"/>
<img src="logo.png"/>
</div>
The fiddle above shows the output (and you could then position the whole navbar, rather than the individual elements)
.navbar {
position:fixed;
top:0;
left:0;
}

Centre combined divs

EDIT: All sorted now. Thanks to everyone that helped! :)
I am having trouble centering an element of my website. It is 3 divs mixed together to form a hexagon.
I cannot center it.
HTML:
<li>
<div class="centerhex">
<a href="#">
<div class="hexa">
<div class="hexcontainer">
<div class="vertical-align">
<span class="hextext">Lorem Ipsum Dolor</span>
</div>
</div>
</div>
</a>
</div>
</li>
CSS:
.centerhex {
left: 50%;
margin: 0 auto;
width:210px;
height:300px;
}
.hexa {
width: 100%;
min-width: 200px;
height: 0;
padding-bottom: 57.7%;
margin-top: 65px;
background-color: #4a4a4a;
/*position: absolute;*/
color: #ffffff;
font-family: 'Oswald', sans-serif;
font-size: 18px;
border-radius: 4%/20%;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-ms-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.hexa::before,
.hexa::after {
content:"";
display: block;
width: inherit;
height: inherit;
padding: inherit;
background: inherit;
z-index: 0;
position: absolute;
border-radius: inherit;
-moz-transform:rotate(60deg);
-webkit-transform:rotate(60deg);
-o-transform:rotate(60deg);
-ms-transform:rotate(60deg);
}
.hexa::after {
-moz-transform:rotate(-60deg);
-webkit-transform:rotate(-60deg);
-o-transform:rotate(-60deg);
-ms-transform:rotate(-60deg);
}
.hexcontainer {
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 100%;
z-index: 10;
}
.vertical-align {
display: table;
height: 100%;
width: 100%;
}
Also, I need help so the bottom of the shape isn't cut off.
URL: http://jackmarshallphotography.co.uk/V1/donate.html
There are few things to change in your css, I worked directly on your website with the chrome developer tool, please find below the css to center the "tag" :
.servicebox {
position: absolute;
margin-top: -77px;
width: 100%;
}
.servicebox ul {
list-style: none;
width: 100%;
text-align: center;
}
.servicebox ul li {
margin-left: 12px;
}
.centerhex {
margin: auto;
width: 210px;
height: 300px;
}
Hope it helps.
For the second issue :
you need to edit the file hexagon.css and change the margin-top property find the right value: -65px or more (line 47)
Yoann
Let me see if I can help you with a simple example.
Have a fiddle - fiddle link!
Edit! - Here is another fiddle without absolute positioning... seems like this can be achieved without it - fiddle link - no absolute positioning
Absolute positioning example:
HTML
<div id="parentOfCentered">
<div id="perfectlyCentered"></div>
</div>
CSS
#parentOfCentered {
position: relative; /* Absolutely positioned children will be positioned in relation to the parent div */
background: #CCC;
width: 400px;
height: 400px;
}
#perfectlyCentered {
width: 200px;
height: 200px;
background: #000;
position: absolute;
left: 50%;
top: 50%;
margin: -100px 0 0 -100px;
/*
- negative top margin of half the height
- negative left margin of half the width
*/
}

Slideout CSS menu needs persistent hover state

So this is where I am so far with a header menu I am trying to create.
http://jsfiddle.net/2LUSL/
It works perfectly as I want it apart from the fact that I need the divs that slideout to stay visible while I hover over them.
Forgive my lack of understanding/knowledge and also if this has been answered before.
Thanks for any help in advance.
I think where I might be going wrong is that I haven't made my elements into a list, but when I do it doesn't help.
<div id="slidecontainer">
<div id="slideout" class="zero"></div>
<div id="slideout" class="one"></div>
<div id="slideout" class="two"></div>
<div id="slideout" class="three"></div>
<div id="slideout" class="four"></div>
</div>
you should catch hover state on main container : http://jsfiddle.net/2LUSL/1
#slidecontainer {
position: relative;
top: 0px;
left: 50%;
margin-top: 0px;
margin-left: -152px;
height:150px;
width:300px;
border: 2px solid #333;
border-radius: 0 0 300px 300px;
-moz-border-radius: 0 0 300px 300px;
-webkit-border-radius: 0 0 300px 300px;
background:red;
}
#slideout {
position: absolute;
top: 95px;
left: 124px;
-webkit-transition-duration: 0.5s;
-moz-transition-duration: 0.5s;
-o-transition-duration: 0.5s;
transition-duration: 0.5s;
height:50px;
width:50px;
border: 1px solid #000;
border-radius: 100px 100px 100px 100px;
-moz-border-radius: 100px 100px 100px 100px;
-webkit-border-radius: 100px 100px 100px 100px;
background:green;
line-height:50px;
text-align:center;
}
#slideout.zero {
z-index:1;
}
#slidecontainer:hover #slideout.one {
left: 25px;
top: 45px;
}
#slidecontainer:hover #slideout.two {
left: 70px;
top: 80px;
}
#slidecontainer:hover #slideout.three {
left: 222px;
top: 45px;
}
#slidecontainer:hover #slideout.four {
left: 178px;
top: 80px;
}
Edit:
to center your container: margin:auto works fine : http://jsfiddle.net/2LUSL/2/

Resources