Issue With Overlapping Fixed Objects - css

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;
}

Related

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.

Emulating a specific CSS hover effect

I'm trying to emulate the hover effect you can see here:
http://www.timeout.com/newyork (When you hover on the articles.)
I understand how to make a div move on :hover, what I don't understand is how they've hidden the "read more" button until the div is hovered over.
Essentially I would like to know how to hide a div until mouse over, then have it slide out from under another.
Here is a pure CSS solution I quickly hacked up: CSS Hover Effect
h1, h2, h3, h4, h5{
margin:0px;
}
.tile{
overflow: hidden;
width: 400px;
height:350px;
}
.tile:hover > .body{
transition: all 0.5s ease;
top: -3em;
}
.body{
transition: all 0.5s ease;
background-color: #333;
margin:0px;
color: #fafafa;
padding: 1em;
position:relative;
top: -1em;
}
<div class="tile">
<img src="http://lorempixel.com/400/300">
<div class="body">
<h2>Test Header</h2>
<p>Info to display</p>
</div>
</div>
Basically, I just change the position of the text div when I hover over the main div and add a transition animation to it.
They coukd change the maxHeight ...
.read_more {
maxHeight: 2px;
overflow:hidden;
}
.read_more:hover {
maxHeight: 30px;
}
See if this simple example helps:
.main{
width: 300px;
height: 300px;
position: relative;
background:yellow;
overflow:hidden;
}
.hovered{
width: 100%;
height: 64px;
background: gray;
position: absolute;
bottom: -28px;
}
.hovered span{
background: red;
color: #fff;
display:block;
width: 100%;
padding: 5px 0;
}
.main:hover .hovered{
bottom: 0;
}
https://jsfiddle.net/4zak8bfp/
You can do it using some jQuery addClass() and removeClass() methods.
Here is an example:
HTML:
<div class="wrapper">
<div class="caption">
<H1>This is a title</H1>
<p>
This is sample contents...
</p>
<div class="read-more-wrapper">
Read More
</div>
</div>
</div>
CSS:
.wrapper{
position: relative;
width: 450px;
height: 250px;
background-color: #2f89ce;
overflow: hidden;
}
.caption{
display: block;
position: absolute;
bottom: -30px;
width: 100%;
height: auto;
background-color: #fff;
transition: all ease-in-out 0.3s;
}
.read-more-wrapper{
background-color: #d03134;
height: 30px;
}
.slidein{
bottom: 0;
transition: all ease-in-out 0.3s;
}
JQuery:
$('.wrapper').on('mouseenter', function(){
$(this).find('.caption').addClass("slidein");
}).on('mouseleave', function(){
$(this).find('.caption').removeClass('slidein');
});
Here is the fiddle:
https://jsfiddle.net/bk9x3ceo/2/
Hope that helps.

CSS transform and transition

I have a rectangle created in CSS, added a transition so when I hover, the shape shrink and disappear:
.shapeB{
background-color: #FFCC00;
width: 100px;
height: 100px;
-webkit-transition:all 1s;
}
.shapeB:hover{
height:0px;
}
<div class="shapeB"></div>
But the fact that it shrinks up is not what I want, I want it to shrink going down. Trying to stimulate liquid being consumed. Is it possible?
You could somehow missplace the div 100px down, to give that impression. Something like this:
.shapeB{
background-color: #FFCC00;
width: 100px;
height: 100px;
position: relative;
top: 0;
-webkit-transition:all 1s;
}
.shapeB:hover{
height:0px;
top: 100px;
}
<div class="shapeB"></div>
.box{
position:absolute;
width: 100px;
height: 100px;
left:50px;
top:50px;
}
.shapeB{
background-color: #FFCC00;
width: 100px;
height: 100px;
position:absolute;
bottom:0;
-webkit-transition:all 1s;
}
.shapeB:hover{
height:0px;
}
<div class="box">
<div class="shapeB"></div>
</div>

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
*/
}

Evenly spaced image grid

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/

Resources