Position absolute breaks my layout - css

I'm trying to use ngAnimate to create transitions for my views, however i found that it needs the views to have the position property set to absolute to be able to overlap, my problem is that when I apply the position absolute, the layout loses the width and the height.
Here's how It looks like with It's default position (yes, they're on Spanish, sorry about that):
And here's how It looks like with position absolute:
and the code goes like this:
index
<div class="col-md-6 col-md-offset-1 col-sm-8 col-sm-offset-2 col-xs-12">
<div class="slideLeft" ng-view></div>
</div>
the view
<div class="panel panel-primary">
<div class="panel-heading">
<label class="fixcolor"><strong>Agregar nuevo registro</strong></label>
</div>
<div class="panel-body">
<!-- it loses the layout here when loading with ng-include -->
<div ng-switch="currentStep">
<div ng-switch-when="1">
<div class="slideLeft" ng-include="'ViewsAngular/NuevoProducto/paso1.html'">
</div>
</div>
<div ng-switch-when="2">
<div class="slideLeft" ng-include="'ViewsAngular/NuevoProducto/paso2.html'">
</div>
</div>
<div ng-switch-when="3">
<div class="slideLeft" ng-include="'ViewsAngular/NuevoProducto/paso3.html'">
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
the css
.slideLeft{
position:absolute;
}
.slideLeft.ng-leave {
-webkit-animation:slideLeftLeave 1s ease-in;
-moz-animation:slideLeftLeave 1s ease-in;
animation:slideLeftLeave 1s ease-in;
}
.slideLeft.ng-enter {
-webkit-animation:slideLeftEnter 1s ease-in;
-moz-animation:slideLeftEnter 1s ease-in;
animation:slideLeftEnter 1s ease-in;
}
#-webkit-keyframes slideLeftLeave {
from { left: 0 }
to { left: -100% }
}
#-moz-keyframes slideLeftLeave {
from { left: 0 }
to { left: -100% }
}
#keyframes slideLeftLeave {
from { left: 0 }
to { left: -100% }
}
#-webkit-keyframes slideLeftEnter {
from { left: -100% }
to { left: 0 }
}
#-moz-keyframes slideLeftEnter {
from { left: -100% }
to { left: 0 }
}
#keyframes slideLeftEnter {
from { left: -100% }
to { left: 0 }
}
I think this has something to do with the divs not expanding with dynamic content when using position absolute, but how can I do this overlapping behaviour without using absolute position?

Related

How to avoid parent element's height jumping when displaying a child div with v-if

I have a parent div and a child div. Child div is displayed via v-if. I can add a transition to the child element but once the transition is over the parent's height changes abruptly and it doesn't look nice.
I'd like something like the jQuery's slideToggle() function.
Here's my html where I'm using fade effect by transitioning the opacity:
<div class="my-div">
<p>some content</p>
<transition name="fade" mode="out-in">
<p key=1 v-if="show">hello</p>
</transition>
</div>
and here's the transition css:
.fade-enter-active,
.fade-leave-active {
transition: opacity .5s
}
.fade-enter,
.fade-leave-to {
opacity: 0
}
.my-div {
background: lightgreen;
}
Here is the fiddle with my code:
https://jsfiddle.net/x15Lw6a3/
I don't know how to make the height transition. I've tried switching from opacity to height and to max-height as per some other questions but it just snaps up and down.
Any idea or a link to tutorial is appreciated. Thanks!
Try using max-height property by adding max-height: 100px; to fade-enter-active,
.fade-leave-active rule and in .fade-enter,
.fade-leave-to rule set it 0 as follows:
Vue.config.devtools = false;
Vue.config.productionTip = false;
new Vue({
el: '#demo',
data: {
show: true
}
})
.fade-enter-active,
.fade-leave-active {
transition: all 0.5s ease;
max-height: 100px;
opacity: 1;
}
.fade-enter,
.fade-leave-to {
opacity: 0;
max-height: 0px;
}
.my-div {
background: lightgreen;
}
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<div id="demo">
<button v-on:click="show = !show">
Toggle
</button>
<div class="my-div">
<p>some content</p>
<transition name="fade" mode="out-in">
<p key=1 v-if="show" >hello</p>
</transition>
</div>
</div>
Note:
You could see that the animation is not perfectly smooth
Tried a number of approaches myself, ended up going for a component, and VueSlideToggle does the job perfectly for me. It makes use of CSS transition targeting the height property.
new Vue({
el: '#demo',
data() {
return {
show: true
}
}
});
.my-div {
background: lightgreen;
}
<div id="demo">
<button v-on:click="show = !show">Toggle</button>
<div class="my-div">
<p>some content</p>
<vue-slide-toggle :open="show" tag="div" :duration="500">
<p v-if="show">hello</p>
</vue-slide-toggle>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://unpkg.com/vue-slide-toggle"></script>

css transform origin gets overwritten with rotate

I'm looking into CSS transforms and I cant get this one part to work.
#photo-container img {
transition: transform 2s, transform-origin 2s;
}
#container-1 img:hover {
transform: rotate(45deg);
transform-origin: 0 0;
}
#container-2 img:hover {
transform: rotate(1.5turn);
transform-origin: 50%, 50%;
}
#container-3 img:hover {
transform: scale(1.5);
transform-origin: 0 0;
}
<div class="photo-container" id="container-1">
<div class="photo">
<img src="http://placehold.it/100x100" alt="">
<div class="grey"></div>
epicface
</div>
</div>
The three classes HTML elements are the same as the one posted below.
My question is that say I change the transform origin to 0 0, and it has a transform set to rotate, when the rotate occurs and finishes, instead of returning to its original position the same way it did to get there, it recenters itself, then goes to that point that was specified in the rotate function and does it from there.
Is there something I missed here or is this the normal functionality?
Edit. i stuffed something up. sorry to bother
Try to add transform-origin to images without hover. And change #photo-container to .photo-container I can't see another problem with it.
.photo-container {
display: inline-block;
}
.photo-container img {
transition: transform 2s, transform-origin 2s;
transform-origin: 0 0;
}
#container-1 img:hover {
transform: rotate(45deg);
}
#container-2 img:hover {
transform: rotate(1.5turn);
}
#container-3 img:hover {
transform: scale(1.5);
}
<div class="photo-container" id="container-1">
<div class="photo">
<img src="http://via.placeholder.com/100x100" alt="">
<div class="grey"></div>
epicface
</div>
</div>
<div class="photo-container" id="container-2">
<div class="photo">
<img src="http://via.placeholder.com/100x100" alt="">
<div class="grey"></div>
epicface
</div>
</div>
<div class="photo-container" id="container-3">
<div class="photo">
<img src="http://via.placeholder.com/100x100" alt="">
<div class="grey"></div>
epicface
</div>
</div>

collapse / expand animation in Angular

I have some code like this
<div ng-click="showMore = true">show more</div>
<div class="show-more' ng-show="showMore">
<div class="cell">
//some span
</div>
<div class="cell">
//some div
</div>
<div ng-click="showMore = false">show less</div>
</div>
and when user clicks 'show more', I want to show the rest in animation
in my css
.cell {
padding-top: 20px;
padding-bottom: 15px;
height: 110px;
}
I have to get rid of ng-show or ng-hide, because display:block or display:none would not make transition: height 0.5s linear; work. So I tried to set the height of .cell to be 0 when it is collapsed, and set it as 110px when it is expanded, but cell height is not really 0 when it is collapsed, because it contains <span> or <div> which have height and padding
how to animate the expand/collapse process in my case? thanks in advance
var app = angular.module("myApp", []);
// Create a Controller named "myCtrl"
app.controller("myCtrl", function($scope) {
showMore = false;
});
.show-more {
-webkit-transition: max-height 1s;
-moz-transition: max-height 1s;
-ms-transition: max-height 1s;
-o-transition: max-height 1s;
transition: max-height 1s;
background: #e5feff;
overflow: hidden;
max-height: 0;
}
.show-more.show {
max-height: 300px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<div class="show-more" ng-class="{'show': showMore}">
<div class="cell">
//some span
</div>
<div class="cell">
//some div
</div>
</div>
<button type="button" ng-click="showMore = !showMore">
Show {{ showMore ? 'Less' : 'More' }} ...
</button>
</div>
Why you trying this in scripting way? Why don't you use Bootstrap Collapse class, Its all going to come with inbuilt Animations

CSS transition -webkit-transform jumping position

I have the following CSS:
.element{
position:relative;
transition:all 1s;
-webkit-transform: rotateX(1deg) rotateZ(1deg) rotateY(0deg);
-webkit-transform-style: preserve-3d;
}
.spun{
.element{
top:260px;
-webkit-transform: rotateX(45deg) rotateZ(45deg) rotateY(0deg);
}
}
and HTML
<div class="element" id="element-1">
<div class="graphic-wrap">
Text 1
</div>
</div>
<div class="element" id="element-2">
<div class="graphic-wrap">
Text 2
</div>
</div>
<div class="element" id="element-3">
<div class="graphic-wrap">
Text 3
</div>
</div>
When I add a class of spun to the body, everything jumps before moving into position. You can see it actually goes off the screen, even though if you compare the position of where it starts, and where it ends, they are really similar:
Demo: http://codepen.io/EightArmsHQ/pen/dadff4f8e9f63e9f825693865d1c9354
If, however I don't add the spun class, and instead gradually increment the values in developer tools, it gradually moves how I want it to.
How can I prevent everything from jumping?
This is because the .element doest have an initial top position so there is no state for it to transform from.
Simply give the .element a starting position. Eg:
$('body').click(function(){
$(this).toggleClass('spun');
})
.element {
top: 0px;
position: relative;
transition: all 1s;
transform: rotateX(1deg) rotateZ(1deg) rotateY(0deg);
transform-style: preserve-3d;
transform-origin: 50% 50%;
}
.spun .element {
top: 260px;
transform: rotateX(45deg) rotateZ(45deg) rotateY(0deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="element" id="element-1">
<div class="graphic-wrap">
Text 1
</div>
</div>
<div class="element" id="element-2">
<div class="graphic-wrap">
Text 2
</div>
</div>
<div class="element" id="element-3">
<div class="graphic-wrap">
Text 3
</div>
</div>

Darken image in div on hover, but not another child image

On hover, I'm trying to change the opacity of the main parent to darken the main image, but I want to show another image over it in full opacity. Here's what I tried, but it's not working.
<div class="masonry-item">
<div class="masonry-item1">
<a href="#" class="image">
<div class="caption">
<h3><img src="blah" /></h3> <!-- DARKEN THIS -->
</div>
<img src="blah" /> <!-- KEEP FULL OPACITY -->
</a>
</div>
</div>
my css:
.masonry-container .masonry-item .image:hover .caption {
opacity: 1;
}
.masonry-container .masonry-item a.image:hover img {
opacity: .2; /* this seems to darken everything, but when removed darkening doesn't work */
}
.masonry-container .masonry-item1:hover {
background-color: rgba(222,222,222,.5);
z-index:98;
}
Here's an example of what I'm trying to do:
http://screencast.com/t/7qDUmCJMNd
Are you looking for something like this?:
See JSFiddle
HTML:
<div class="masonry-item">
<div class="masonry-item1">
<div class="caption">
<h3><img id="image1" src="http://images.visitcanberra.com.au/images/canberra_hero_image.jpg" /></h3> <!-- DARKEN THIS -->
</div>
<img id="image2" src="http://laurafranksblog.files.wordpress.com/2013/04/storymaker-best-hubble-space-telescope-images-20092-514x268.jpg" /> <!-- KEEP FULL OPACITY -->
</div>
</div>
CSS:
.masonry-item1 {
background-color: #000;
position: relative;
height: 500px;
}
.masonry-item1:hover #image1 {
opacity: .2;
transition: all 1s;
}
/* This is just to get the images to overlap, you don't need this if you're doing it another way */
#image1, #image2 {
position: absolute;
}
Here is my solution. Although there is no darken, I believe you could make it as #mikelt21's answer.
<div class="masonry-item">
<img id="i1" src="https://cdn0.iconfinder.com/data/icons/business-and-finance-9/250/vector_265_07-01-128.png" />
<img id="i2" src="https://cdn0.iconfinder.com/data/icons/business-and-finance-9/250/vector_265_20-01-128.png" />
</div>
<style>
img{
position: absolute;
top:0;
left:0;
transition: all 1s;
}
div:hover #i1{
opacity:1;
}
div:hover #i2{
opacity:0;
}
#i1{
opacity:0;
}
#i1:hover{
opacity:1;
}
</style>
Here is the example in action

Resources