css transform open div to right like a "book" cover - css

Hi for a webshop i want the product block to open like a book. and show a image on de inside-left (when opened)
i tried to do this. It works ok but i want the black div to open to the left. this one will contain the image. When i put a negivate -180 degrees it does not seem to work ok.
.left,
.right {
width: 100%;
height: 200px;
float: left;
color: white;
position: absolute;
}
.left {
background: red;
-webkit-border-top-left-radius: 100px;
-webkit-border-bottom-right-radius: 100px;
-moz-border-radius-topleft: 100px;
-moz-border-radius-bottomright: 100px;
border-top-left-radius: 100px;
border-bottom-right-radius: 100px;
height: 250px;
padding: 0;
border: 10px solid #10832d;
}
.right {
background: black;
-webkit-border-top-left-radius: 100px;
-webkit-border-bottom-right-radius: 100px;
-moz-border-radius-topleft: 100px;
-moz-border-radius-bottomright: 100px;
border-top-left-radius: 100px;
border-bottom-right-radius: 100px;
height: 250px;
padding: 0;
border: 10px solid #10832d;
}
.wrapper {
perspective: 1000px;
perspective-origin: 100%;
100%;
;
-webkit-perspective: 1000px;
-webkit-perspective-origin: 100%;
100%;
;
}
.wrapper:hover .right {
transform: rotate3d(0, 1, 0, -180deg);
transform: rotateY(180deg);
transform-origin: 100%;
0;
transition: transform 1s;
-webkit-transform: rotateY(180deg);
-webkit-transform-origin: 100%;
0;
-webkit-transition: -webkit-transform 1s;
}
<div style="width:50%">
<div class="col-md-3 wrapper" style="position:relative;min-height:250px;">
<div class="left">sdfsdf</div>
<div class="right">sdfdsfds</div>
</div>
</div>

Your problem with transform-origin not with rotation degree, in your case:
-webkit-transform-origin: 100%; 0;
// ^ X ^ Y
That means x-axis offset 100% of div (full offset on x-axis)
No problem, Now just reset the origin to zero ( to start rotation from begin of div ) like this :
-webkit-transform-origin: 0;
Also don't forget float: right because the div will open to the left.
CSS / HTML :
.left,.right {
width:100%;
height:200px;
color:#FFF;
position:absolute;
}
.left {
background:red;
-webkit-border-top-left-radius:100px;
-webkit-border-bottom-right-radius:100px;
-moz-border-radius-topleft:100px;
-moz-border-radius-bottomright:100px;
border-top-left-radius:100px;
border-bottom-right-radius:100px;
height:250px;
border:10px solid #10832d;
padding:0;
}
.right {
background:#000;
-webkit-border-top-left-radius:100px;
-webkit-border-bottom-right-radius:100px;
-moz-border-radius-topleft:100px;
-moz-border-radius-bottomright:100px;
border-top-left-radius:100px;
border-bottom-right-radius:100px;
height:250px;
border:10px solid #10832d;
padding:0;
}
.wrapper {
perspective:1000px;
perspective-origin:100%;
-webkit-perspective:1000px;
-webkit-perspective-origin:100%;
}
.wrapper:hover .right {
transform:rotateY(180deg);
transform-origin:0;
transition:transform 1s;
-webkit-transform:rotateY(-180deg);
-webkit-transform-origin:0;
-webkit-transition:0 1s;
}
<div style="width:50%; float:right">
<div class="col-md-3 wrapper" style="position:relative;min-height:250px;">
<div class="left">left side</div>
<div class="right">right side</div>
</div>
</div>

Related

CSS to create an acute isosceles triangle with curved edges

I am trying to create a triangle using purely CSS which has curved edges.
Is this possible without it being totally over the top?
I've added an example below of what I'm trying to achieve (the curved lines - not the straight lines).
So far I have been working with the following code but it's not quite what I'm looking for.
#inner {
transform: rotate(45deg);
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-o-transform: rotate(45deg);
-moz-transform: rotate(45deg);
background-color: silver;
width: 100px;
height: 100px;
top: 20px;
left: -50px;
position: relative;
-moz-border-radius: 20px;
border-radius: 20px;
}
#outer {
position: absolute;
width: 70px;
height: 140px;
top: 20px;
left: 50px;
overflow: hidden;
border: 1px solid red;
}
<div id="outer">
<div id="inner"> </div>
</div>
How about an svg solution?
<svg width="200" height="200" viewBox="-2 0 252 212">
<path fill="rosybrown" d="M125 0 c-81.6 60 -113.3 130 -125 200 c83.3 40 166.6 40 250 0 c-11.7 -70 -43.4 -140 -125 -200" fill="none" stroke-width="2" stroke="black" />
</svg>
Just another posibility, without using any rotation. Just clipping different circles.
.triangle {
position: relative;
width: 200px;
height: 200px;
border-radius: 50%;
background-color: lightblue;
overflow: hidden;
}
.triangle div {
position: absolute;
width: 100%;
height: 100%;
top: 31%;
left: 16%;
background-color: lightyellow;
border-radius: 50%;
overflow: hidden;
}
.triangle div:after {
content: "";
position: absolute;
width: 100%;
height: 100%;
right: 30%;
background-color: red;
border-radius: 50%;
}
<div class="triangle">
<div></div>
</div>
The light colors are there just to make the construction of the triangle more visible
solution 1: Using two elements
The first example is not perfect, but does sort of answers your question:
.wrapper{
/*overflow:hidden;*/
width:0;
border-top:100px solid transparent;
border-left:100px solid red;
position:relative;
margin:50px;
transform:rotate(135deg);
}
.triangle{
width:20px;
height:100px;
background:red;
border-radius:50%;
transform:translate(-110px);
position:absolute;
top:-100px;
left:0;
}
.triangle:after{
content:"";
width:100px;
height:20px;
background:red;
border-radius:50%;
transform:translate(0px);
position:absolute;
top:90px;
left:10px;
}
.triangle:before{
content:"";
width:140px;
height:20px;
background:red;
border-radius:50%;
transform:rotate(225deg);
position:absolute;
top:40px;
left:-10px;
}
<div class="wrapper">
<div class="triangle"></div>
</div>
Please note This isn't an equilateral triangle, more of an isosceles one and could be edited into a better one no doubt!!
Solution 2: Using a single element
I was trying to create this shape using a single div element, but i was only able to generate two sides of the triangle. So, from this, I deduced that using css along requires two elements:
Two sides Of the Triangle Shown:
div {
border-left: 100px solid transparent;
border-bottom: 126px solid blue;
border-right: 100px solid transparent;
width: 0;
border-radius:50%;
position: relative;
}
div:after,
div:before {
content: "";
position: absolute;
height: 130px;
width: 20px;
border-radius: 50%;
top: -15px;
background: blue;
}
div:after {
left: -50px;
transform: rotate(40deg);
}
div:before {
left: 30px;
transform: rotate(-40deg);
}
<div></div>
I am guessing that svg may be a better option (note: I do not know svg, that seems like #chipChocolate.pys's area of expertise). So using 'just pseudo effects', I think you're looking to use two elements (but I'd like to see be proved wrong!). The 'single element' doesn't quite seem right, but may or may not be perfect for you
Pure CSS
Using different transforms.
I created three sectors using transform: rotate(30deg); and transform-origin: 0% 100%; Then I transformed their parent containers (scaleX: -1; for the left side). Done.
This can be done with just one pair of #cont and #circ elements, but I used different tags just for demonstrating better.
#cont {
height: 300px;
width: 300px;
overflow: hidden;
position:relative;
}
#circ {
height: 300px;
width: 300px;
background: black;
border-radius: 0 300px 0 0;
transform: rotate(30deg);
transform-origin: 0% 100%;
}
#cont:nth-of-type(2){
top: -300px;
transform: scaleX(-1);
}
#cont:nth-of-type(3){
top: -600px;
transform: rotate(30deg);
transform-origin: 0% 100%;
}
#cont:nth-of-type(3) > #circ {
border-radius: 0 0 300px 0;
transform-origin: 0% 0%;
}
<div id="cont">
<div id="circ">
</div>
</div>
<div id="cont">
<div id="circ">
</div>
</div>
<div id="cont">
<div id="circ">
</div>
</div>
Note: For a real website, almost always use SVG. But creating shapes with CSS is an art which mustn't be killed.
Here is my attempt at this. I think this is the best way to do it, using 1 element and :before :after.
Using the div as the base element (the bottom) we can line up the other 2 above it keeping the size and shape equal.
div {
width: 120px;
height: 60px;
background: red;
border-radius: 50%;
position: relative;
margin: 100px;
}
div:before, div:after {
content: "";
display: block;
background: red;
border-radius: 50%;
position: absolute;
width: 60px;
height: 120px;
top: -70px;
}
div:before {
transform: rotate(30deg);
left: 8px;
}
div:after {
transform: rotate(-30deg);
right: 8px;
}
<div></div>
Edit:
Another Attempt, slight tweaking from the first.
div {
width: 100px;
height: 50px;
background: red;
border-radius: 50%;
position: absolute;
top: 10px;
left: 70px;
margin: 100px;
}
div:before,
div:after {
content: "";
display: block;
background: red;
border-radius: 50%;
position: absolute;
width: 36px;
height: 106px;
top: -65px;
}
div:before {
transform: rotate(28deg);
left: 8px;
border-right: 10px solid red;
}
div:after {
transform: rotate(-28deg);
right: 8px;
border-left: 9px solid red;
}
<div></div>
I like the challenge :)
I recently have come to love the more complex border radius variations. I'm sure with some more fiddling and decent math calculations you can get rid of the rough edges where the different sides meet. No time for it now unfortunately.
.triangle {
position: absolute;
top: 100px;
left: 100px;
border-left: 25px solid transparent;
border-bottom: 40px solid blue;
border-right: 25px solid transparent;
width: 0;
border-bottom-right-radius: 80px 70px;
border-bottom-left-radius: 0 0;
transform: rotate(160deg);
}
.triangle:after {
content: '';
position: absolute;
border-left: 25px solid transparent;
border-bottom: 40px solid CornflowerBlue;
border-right: 25px solid transparent;
width: 0;
left: -54px;
top: -12px;
border-bottom-right-radius: 80px 70px;
border-bottom-left-radius: 0 0;
transform: rotate(120deg);
}
.triangle:before {
content: '';
position: absolute;
border-left: 25px solid transparent;
border-bottom: 40px solid darkblue;
border-right: 25px solid transparent;
width: 0;
top: -30px;
left: -29px;
border-bottom-right-radius: 80px 70px;
border-bottom-left-radius: 0 0;
transform: rotate(240deg);
}
<div class="triangle"></div>

3D transform issue in firefox

I have a JSFiddle showing a flipping card, It works in chrome as I would expect but the depth perspective in firefox is flat and I'm not sure where the issue is.
I have tried adding:
transform-style: preserve-3d;
and
perspective: 1000;
to all classes (like card) I could with no luck.
The HTML structure is:
<div id="card-container">
<button id="card-flip">Flip the card</button>
<div id="card">
<div class="front card-surface"><!-- front -->
<p>The front</p>
</div>
<div class="back card-surface"><!-- back -->
<p>The back</p>
</div>
</div>
</div>
The simplified CSS is:
#card-container{
position: relative;
background-color:#888;
width: 300px;
height: 450px;
margin:0 auto;
}
#card-flip{
display:none;
}
#card{
margin:10px auto;
width: 100%;
height: 400px;
}
.card-surface{
margin-top:5px;
width: 280px;
height: 180px;
padding:10px;
}
.front{
background-color:#7B78E8;
}
.back{
background-color:#78AFE8;
}
/* Only apply 3d effects if they exist in the browser */
#card-container.threed{
height: 250px;
perspective: 1000;
}
.threed #card-flip{
background-color:transparent;
position:relative;
top:220px;
width:100%;
height:40px;
background-color:#99E5FF;
}
.threed #card-flip:focus{
outline:0;
}
.threed #card-flip:hover{
background-color:#49A5BF;
}
#card-flip:hover + #card .card-surface{
box-shadow: 0 0px 50px rgba(0,0,0,0.9);
transition: all .8s ease-in-out;
}
.threed #card{
height:200px;
}
.threed #card .front {
float: none;
position: absolute;
top: 0;
left: 0;
z-index: 900;
transform: rotateX(0deg) rotateY(0deg);
transform-style: preserve-3d;
backface-visibility: hidden;
}
.threed #card.flip .front {
z-index: 900;
border-color: #eee;
background: #333;
box-shadow: 0 15px 50px rgba(0,0,0,0.2);
transform: rotateY(180deg);
}
.threed #card .back {
float: none;
position: absolute;
top: 0;
left: 0;
z-index: 800;
border: 1px solid #ccc;
text-shadow: 1px 1px 1px rgba(0,0,0,0.6);
transform: rotateY(-180deg);
transform-style: preserve-3d;
backface-visibility: hidden;
}
.threed #card.flip .back {
z-index: 1000;
background-color:#ccc;
transform: rotateX(0deg) rotateY(0deg);
}
.threed #card .card-surface{
background-color:$base-white;
transition: all .8s ease-in-out;
width: 280px;
height: 180px;
padding:10px;
}
I have seen working examples like This one. Can anyone tell me what I am missing or is it not possible with this structure?
I have figured out the issue.
Here is a new version of the fiddle.
The problem was that I did not have the px after the perspective property. this was ignored by chrome but not firefox. I also applied The perspective to the wrong element in the demo so even though I had tried to ad the px before it didn't work.

How to overlay divs with pure css?

To create this effect:
It is possible or would I need to design it with software?
You could use gradient as background
div {
background: -moz-linear-gradient(-45deg, #1e5799 50%, #207cca 50%, #7db9e8 100%);
background: -webkit-gradient(linear, left top, right bottom, color-stop(50%,#1e5799), color-stop(50%,#207cca), color-stop(100%,#7db9e8));
...
}
An example : http://jsfiddle.net/w9fYj/
You can do it with triangles (which basically works on border adjustments) How do CSS triangles work?
And other shapes for more
Here is extensive example with transforms of many divisions which may interest you.
Demo
HTML
<div class="wrapper">
<div class="shape3">
<div class="shape3-content">Hi there!</div>
</div>
<div class="shape1">
<div class="shape1-content">Hi there!</div>
</div>
<div class="shape2">
<div class="shape2-content">Hi there!</div>
</div>
</div>
css
.wrapper {
border: 1px solid #ff8888;
height: 480px;
left: 50%;
margin: -240px 0 0 -320px;
overflow: hidden;
position: absolute;
top: 50%;
width: 640px;
}
.shape1 {
-webkit-transform: rotate(15deg);
-moz-transform: rotate(15deg);
background-color: #fff;
border: 1px solid black;
height: 50%;
left: -25%;
position: absolute;
top: 70%;
width: 150%;
}
.shape1-content {
-webkit-transform: rotate(-15deg);
-moz-transform: rotate(-15deg);
padding-left: 230px;
}
.shape2 {
-webkit-transform: rotate(15deg);
-moz-transform: rotate(15deg);
background-color: #fff;
border: 1px solid #88ff88;
bottom: 244px;
height: 100%;
position: absolute;
right: 50%;
width: 100%;
}
.shape2-content {
-webkit-transform: rotate(-15deg);
-moz-transform: rotate(-15deg);
bottom: 10px;
position: absolute;
right: 10px;
}
.shape3 {
background:red;
-webkit-transform: rotate(30deg);
-moz-transform: rotate(30deg);
border: 1px solid #8888ff;
bottom: 40%;
height: 100%;
position: absolute;
right: 20%;
width: 100%;
}
.shape3-content {
-webkit-transform: rotate(-30deg);
-moz-transform: rotate(-30deg);
bottom: 50%;
position: absolute;
right: 10px;
}
Here it is using pure CSS:
HTML
<div id="test">
</div>
CSS
#test {
widh:300px;
height:150px;
background:#C3C3C3;
position:relative;
overflow:hidden;
}
#test:after {
content:'';
position:absolute;
right:-100px;
top:10px;
transform:rotate(-30deg);
-webkit-transform:rotate(-30deg);
-moz-transform:rotate(-30deg);
-o-transform:rotate(-30deg);
-ms-transform:rotate(-30deg);
width:500px;
height:250px;
background:#880015;
}
And here is a FIDDLE
If you consider to support old browsers without using CSS3 then:
HTML
<div class="wrapper">
<div class="left"></div>
<div class="middle"></div>
<div class="right"></div>
</div>
CSS
.wrapper {
width: 400px;
height: 100px;
}
.left {
display: inline;
float: left;
background-color: #ccc;
width: 100px;
height: 100px;
}
.right {
display: inline;
float: right;
background-color: #610A0A;
width: 200px;
height: 100px;
}
.middle {
float:left;
display: inline;
line-height: 0%;
width: 0px;
border-top: 100px solid #ccc;
border-right: 100px solid #610A0A;
}
Fiddle Demo

Newbie in Css. Can't get to duplicate a tutorial about CSS animation of a frog

This is kind of embarassing for me, but I have a final project for my Software engineering class, and I'd been searching for tutorials so I can see and learn about html css and javascript to implement it in my project. I never worked on those, so I found a cool tutorial about some animation that I wanted to implement in my project so I decided to give it a try, and I cant get the code to work.
Here's the tutorial link.
http://davidwalsh.name/logo-animation
Here's my code (http://jsfiddle.net/5x4wv/):
<!DOCTYPE html>
<html>
<head>
<body>
<div class="mike">
<div class="head">
<div class="eyes">
<div class="eye">
<div class="pupil"></div>
</div>
<div class="eye">
<div class="pupil"></div>
</div>
</div>
<div class="nose">
<div class="ball"></div>
<div class="ball"></div>
</div>
<div class="mouth"></div>
</div>
</div>
<style>
div {
border-radius: 50%;
box-sizing: border-box;
}
.mike {
width: 400px;
margin: 0 auto;
padding-top: 2%;
transition: all 1s;
}
.mike:hover {
transform: scale(1.5) rotate(360deg);
}
.head {
width: 195px;
height: 120px;
background: #92ae57;
position: relative;
z-index: 1;
margin-left: 103px;
}
.eyes {
width:200px;
position: absolute;
bottom: 45px;
}
.eye {
width: 95px;
height: 93px;
background-color: #ffe13b;
border: 10px solid #92ae57;
display: inline-block;
z-index: 2;
animation: eyes 5s infinite step-start 0s;
}
.eye:last-child {
float:right;
}
.pupil {
width: 1px;
height: 1px;
border: 10px solid #353535;
display: inline-block;
position: absolute;
top: 38px;
margin-left:27px;
z-index: 3;
animation: pupil 5s infinite step-start 0s;
}
.pupil:last-child{
float:right;
}
.ball {
width: 1px;
height: 1px;
border: 5px solid #6f8346;
position: absolute;
top: 70px;
left: 88px;
}
.ball:last-child {
float:left;
margin-left: 14px;
}
.mouth {
height: 100px;
width: 180px;
border-bottom: 4px solid #6f8346;
position: relative;
top: 8px;
left: 7px;
}
/* Animations */
#keyframes eyes {
0%, 100% {
background: #92ae57;
border-radius: 50%;
border: 10px solid #92ae57;
}
5%, 95% {
background:#ffe13b;
border-radius: 50%;
border: 10px solid #92ae57;
}
}
#keyframes pupil {
0%, 100% {
opacity: 0;
}
5%, 95% {
opacity: 1;
}
}
</style>
</body>
</html>
I'm using Sublimetext 2 and running in Chrome.
Prefix stuff...
Delay duration only delays animation at first start not at every iteration.
USE FLOATS BARELY...use relative position especially for this..
http://jsfiddle.net/T862G/ take a look it works
#-webkit-keyframes eyes {
10% {background-color:#92ae57;}
25% {background-color:#ffe13b;}
}
#-webkit-keyframes pupil {
10% {opacity: 0;}
25% {opacity: 1;}
}
.mike:hover {
-webkit-transform: rotate(360deg) scale(1.5);
}

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