Is something like this even possible in CSS? [closed] - css

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Is it possible to make 2 picture overlap this way ?
Imagine you have 2 images both like 60% of the resulting image. They should overlap, but by a diagonally cutout.

Either you use CSS Masking or you play around with CSS3 transform rotate:
-ms-transform: rotate(45deg); /* IE 9 */
-webkit-transform: rotate(45deg); /* Chrome, Safari, Opera */
transform: rotate(45deg);
You would rotate one inner container by say 45 degrees and the image inside that container by -45 degrees to make it straight again. The result is a diagonal border. Add z-index and absolute positioning and you got your result.
Here's a demo.
.container {
width: 500px;
height: 200px;
margin: 50px;
overflow:hidden;
position: relative;
border: 2px solid #666;
}
.img1 {
border-right: 2px solid #666;
position: absolute;
width: 300px;
height: 600px;
overflow: hidden;
left: -75px;
top: -230px;
z-index: 2;
-ms-transform: rotate(45deg); /* IE 9 */
-webkit-transform: rotate(45deg); /* Chrome, Safari, Opera */
transform: rotate(45deg);
}
.img1 img {
-ms-transform: rotate(-45deg); /* IE 9 */
-webkit-transform: rotate(-45deg); /* Chrome, Safari, Opera */
transform: rotate(-45deg);
}
.img2 {
position: absolute;
width: 350px;
overflow: hidden;
left: 150px;
z-index: 1;
}
<div class="container">
<div class="img1"><img src="http://lorempixel.com/output/city-q-c-600-300-7.jpg" /></div>
<div class="img2"><img src="http://lorempixel.com/output/city-q-c-600-300-10.jpg" /></div>
</div>

Related

Space while rotation Div In css

I want one div in my page whose position will be fixed rotation is 30 degree but when I am doing this its shows like this
I Don't want that empty space in the top while rotation. I want Top same as bottom currently in top its showing some space when i rotate my div.
CSS is
#beta{
position:fixed;
bottom:0;
padding:-30px;
z-index: 1;
width: 15em;
height:3em;
background: #65a9d7;
-ms-transform: rotate(30deg); /* IE 9 */
-webkit-transform: rotate(30deg); /* Chrome, Safari, Opera */
transform: rotate(30deg);
}
You can add transform-orign, which will act as rotating axis.
And if you want this to be at top then add top and remove bottom value and while rotating, the blocks shifts so give left value to the half of its height of appropriate value.
#beta{
position:fixed;
top:0;
z-index: 1;
width: 15em;
height:3em;
left: 1.5em;
background: #65a9d7;
-ms-transform: rotate(30deg); /* IE 9 */
-webkit-transform: rotate(30deg); /* Chrome, Safari, Opera */
transform: rotate(30deg);
transform-origin: left top;
}
And one more thing, padding doesn't work with negative value. :)
Have a nice code day.
Take a look at the transform-origin CSS property if you want to set the point at which the object rotates around. In your specific example, the reason there is so much space above is because you've set bottom: 0, which will force a fixed element to snap to the bottom of its parent.
I'm not sure the exact layout you're looking for, but here is something with less white space at the top:
#beta {
position: fixed;
z-index: 1;
width: 15em;
height: 3em;
background: #65a9d7;
-ms-transform: rotate(30deg);
/* IE 9 */
-webkit-transform: rotate(30deg);
/* Chrome, Safari, Opera */
transform: rotate(30deg);
margin-top: 4em;
}
<div id="beta">
Beta Version
</div>
Edit: The following snippet is a follow-up to a comment from the original poster.
.container {
border: 5px solid #000;
height: 5em;
overflow: hidden;
position: relative;
width: 15em;
}
.beta {
background: #65a9d7;
height: 3em;
line-height: 3em;
margin-top: -1.5em;
position: absolute;
text-align: center;
top: 50%;
width: 15em;
-ms-transform: rotate(30deg);
/* IE 9 */
-webkit-transform: rotate(30deg);
/* Chrome, Safari, Opera */
transform: rotate(30deg);
}
<div class="container">
<div class="beta">
Beta Version
</div>
</div>

prevent scrolling from left to right when slanting div

I've searched on here and could not find an answer so I apologise if this has been asked before.
Anyway, im creating a website, and one of the effects im using is a slanting div effect.
But when i create it using the transform, rotate and skew for some reason it makes the website scroll from left to right.
Ive tried putting the overflow to hidden on the parent div but it then hides the slanting effect.
Here is my code...
Html:
<div class="container">
<div class="slant"></div>
<!-- rest of the code goes here -->
</div>
Css:
.container{width:100%;position:relative;}
.slant{
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
top: -45px;
position: absolute;
width: 100%;
background-color: inherit;
left: 0;
height: 120px;
overflow: hidden;
z-index: 200;
-webkit-transform: rotate(-2deg) skew(-2deg) scale(1.1,1);
-mox-transform: rotate(-2deg) skew(-2deg) scale(1.1,1);
-ms-transform: rotate(-2deg) skew(-2deg) scale(1.1,1);
-o-transform: rotate(-2deg) skew(-2deg) scale(1.1,1);
transform: rotate(-2deg) skew(-2deg) scale(1.1,1);
}
Ive heard you can do this with ::before pseudo-elements but to be honest I dont know how and cant seem to find a tutorial to show me.
Any help is welcome and will be appreciated
Thanks
Do you use scale(1.1,1) for some strong reason?
You can remove it, and also remove default margin and padding from body, so that container shrinks to the width of the browser. Then everything works (tested in Chrome, FF, IE11).
Your css will look like this:
body {margin:0px;padding:0px;}
.container{width:100%;position:relative;}
.slant{
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
top: -45px;
position: absolute;
width: 100%;
background-color: inherit;
left: 0;
height: 120px;
overflow: hidden;
z-index: 200;
width:100%;
-webkit-transform: rotate(-2deg) skew(-2deg) ;
-mox-transform: rotate(-2deg) skew(-2deg) ;
-ms-transform: rotate(-2deg) skew(-2deg);
-o-transform: rotate(-2deg) skew(-2deg) ;
transform: rotate(-2deg) skew(-2deg);
background-color: red;
}

CSS 3 hover issue [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a div in the sidebar. The whole div is a link which takes you to another part of the website.
Now, there is this small flower like image in the left side of the div, background image. When you hover the div the flower should
rotate
fade in and out.
If I apply the animation on the entire div, the div will rotate, not the background image. So I solved it like this: the flower is in an absolutely positioned div and rotates and fades in and out continuously (if I apply the animation to the :hover then it rotates only when I hover directly on the image.)
Is this what you want?
http://jsfiddle.net/kgFdJ/2/
#foo {
width: 300px;
height: 500px;
background-color: #eee;
position: relative;
}
#foo:after {
content: "";
width: 20px;
height: 20px;
background-color: #f00;
position: absolute;
top: 10px;
left: 10px;
-moz-transition: all 1s;
-o-transition: all 1s;
-webkit-transition: all 1s;
transition: all 1s
}
#foo:hover:after {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
opacity: 0;
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg)
}
But be aware that using a pseudo selector to another pseudo selector could get a little buggy in some browsers, so instead you can do something like this:
HTML
<div id="foo">
<div class="flower"></div>
</div>
CSS
#foo:hover > div.flower ...

Higher level CSS animation library?

I looked around but can't find any good resources for doing higher level animations (like card flip, cubes, etc). Like a ???:CSS :: jQuery:JS.
I know of transit but I'm looking for something that has more functionality and animations built in.
Have you thought about using Animate.css? Seems pretty good. Another good one seems like CSS3 Animations and for stuff like card-flipping, CSS3 Playground.
An edited version of this one: http://css3.bradshawenterprises.com/flip/:
JSfiddle: http://jsfiddle.net/PnUHr/1/
CSS
#f1_container {
position: relative;
margin: 10px auto;
width: 450px;
height: 281px;
z-index: 1;
}
#f1_container {
-webkit-perspective: 1000;
perspective: 1000;
}
#f1_card {
width: 100%;
height: 100%;
-webkit-transform-style: preserve-3d;
-webkit-transition: all 1.0s linear;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
#f1_container:hover #f1_card {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
box-shadow: -5px 5px 5px #aaa;
}
.face {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
.face.back {
display: block;
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
box-sizing: border-box;
color: white;
text-align: center;
background-color: #aaa;
}
HTML
<div id="f1_container">
<div id="f1_card" class="shadow">
<div class="front face">
<img src="Cirques.jpg"/>
</div>
<div class="back face center">
<img src="Cirques.jpg" style="transform:scaleX(-1), transform:scaleY(-1)"/>
</div>
</div>
</div>
All credits go to the original created (see link). I've just removed the padding that was on the back-facing <div> and added a mirrored background of the front-facing image.
For Mozilla/Gecko browsers you need to add the -moz-* prefixes too. Same for Opera (-o-*) and Internet Explorer (-ms-*`).
Direct image link: http://css3.bradshawenterprises.com/images/Cirques.jpg
Effeckt.css is STILL work in progress but look very promising– a pattern libary of multiple sources.

Prevent children from inheriting rotate transformation in CSS

I am performing a CSS transform: rotate on a parent, yet would like to be able to negate this effect on some of the children - is it possible without using the reverse rotation?
Reverse rotation does work, but it affects the position of the element, and it may have a negative performance impact (?). In any case, it doesn't look like a clean solution.
I tried the "transform: none" suggestion from this question prevent children from inheriting transformation css3, yet it simply doesn't work - please see the fiddle here: http://jsfiddle.net/NPC42/XSHmJ/
May be you have to write like this:
.child {
position: absolute;
top: 30px;
left: 50px;
background-color: green;
width: 70px;
height: 50px;
-webkit-transform: rotate(-30deg);
-moz-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
-ms-transform: rotate(-30deg);
transform: rotate(-30deg);
}
Check this for more http://jsfiddle.net/XSHmJ/1/
Updated:
You can use:after & :before psuedo class for this.
check this http://jsfiddle.net/XSHmJ/4/
I believe that you are going to need to fake it using a second child, the specification does not seem to allow for the behavior you would like, and I can understand why the position of a child element has to be affected by a transform to its parent.
This isn't the most elegant of solutions, but I think you're trying to do something that the specification is never going to allow. Take a look at the following fiddle for my solution:
.parent {
position: relative;
width: 200px;
height: 150px;
margin: 70px;
}
.child1 {
background-color: yellow;
width: 200px;
height: 150px;
-webkit-transform: rotate(30deg);
-moz-transform: rotate(30deg);
-o-transform: rotate(30deg);
-ms-transform: rotate(30deg);
transform: rotate(30deg);
}
.child2 {
position: absolute;
top: 30px;
left: 50px;
background-color: green;
width: 70px;
height: 50px;
}
<div class="parent">
<div class="child1"></div>
<div class="child2"></div>
</div>
If you want to apply transforming effects on a parent without affecting its children, you can simply animate a parent's pseudo-element like this:
.parent {
display: inline-block;
position: relative;
}
.parent::before {
content: "";
background: #fab;
/* positioning / sizing */
position: absolute;
left: 0;
top: 0;
/*
be aware that the parent class have to be "position: relative"
in order to get the width/height's 100% working for the parent's width/height.
*/
width: 100%;
height: 100%;
/* z-index is important to get the pseudo element to the background (behind the content of parent)! */
z-index: -1;
transition: 0.5s ease;
/* transform before hovering */
transform: rotate(30deg) scale(1.5);
}
.parent:hover::before {
/* transform after hovering */
transform: rotate(90deg) scale(1);
}
This actually worked for me. JSFiddle

Resources