Wordpress shortcode problems with css hover - css

I am trying to solve an issue with CSS on my shortcode.
You can see it here in action:
http://www.mariovital.com/jose-ollin/sample-page
and the shortcode code:
// Add Shortcode
function servicos_shortcode( $atts ) {
// Attributes
extract( shortcode_atts(
array(
'posicao' => '',
'icon' => 'default.png',
'titulo' => 'O Serviço',
'link' => '',
), $atts )
);
// Code
return '
<div class="span3 fp-'.$posicao.'">
<div class="widget-front">
<div class="thumb-wrapper tc-holder">
<a class="round-div" href="'.$link.'" title="'.$titulo.'"></a>
<img src="'.$icon.'" alt="'.$servico.'">
</div>
<!-- /.widget-front -->
<h4>'.$titulo.'</h4>
</div>
</div> ';
}
add_shortcode( 'servicos', 'servicos_shortcode' );
The problem is with the hover selector you can see on my test page. I really don't know what is wrong with the CSS code.

I assume that you want the hover effect should happen to a particular div when it hovers by users. And it should not happen to all of those divs at once. So here goes the solution -
On your CSS, you have setup hover effect for both <article> and <div class="widget-font">
.widget-front.hover .round-div,
article.hover .round-div {
-webkit-transform: scale(1.4);
-moz-transform: scale(1.4);
-ms-transform: scale(1.4);
-o-transform: scale(1.4);
transform: scale(1.4);
}
But if you don't want the hover effect should affect all the divs inside the article. So, just remove the article.hover .round-div from CSS and your final snippet should looks like this -
.widget-front.hover .round-div {
-webkit-transform: scale(1.4);
-moz-transform: scale(1.4);
-ms-transform: scale(1.4);
-o-transform: scale(1.4);
transform: scale(1.4);
}
EDIT :
I just have a look at your code. You still have article.hover .round-div on your CSS code. If the CSS is generating externally and you are not able to change that, you can add this following code at the end -
article.hover .round-div {
-webkit-transform: none;
-moz-transform: none;
-ms-transform: none;
-o-transform: none;
transform: none;
}

Related

Animating div (enter and exit) in React

I want to build a simple "carousel" in React. I have a list of questions that I want the user to answer. When you click on next, it shows the next question. I want to also add a previous button in the future. Currently the animation for the item being revealed works.
However on mobile the screen jumps up when its animating from one div to another (with a slight delay)
The height of the parent div is always the same, so why would it jump?
JSX
{ this.state.activeIndex === 0 &&
<div className="surveyContainer--surveyList__animate">
<div>
<SelectField labels={data.meat.labels} value={this.props.survey.meat}/>
</div>
<div>
<Button handleClick={() => this.handleActiveIndex(2)} label="Next"/>
</div>
</div>
}
{this.state.activeIndex === 1 &&
<div className="surveyContainer--surveyList__animate">
<div>
<SelectField labels={data.energy.labels} value={this.props.survey.energy}/>
</div>
<div>
<Button handleClick={() => this.handleActiveIndex(2)} label="Next"/>
</div>
</div>
}
<SelectField/> and Button are both custom components.
CSS
.surveyContainer--surveyList__animate {
animation: slide-in 0.4s ease;
}
#keyframes slide-in {
0% {
opacity: 0;
transform: translateX(200px);
}
100% {
opacity: 1;
transform: translateX(0);
}
}
How do I fix the jumping? Also what might be a better approach to do this entire thing? If I want to add a previous button, then switching the animation will be a painstaking feature.
Edit:
For the jumping issue, try setting the parent's position to relative, then, for the child container:
.child {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
I recommend ReactTransitionGroup:
https://reactcommunity.org/react-transition-group/css-transition
Your code would look something like this:
import { CSSTranstion } from 'react-transition-group'
<CSSTranstion in={this.state.activeIndex === 0} timeout={200} classNames="survey-list" unmountOnExit>
<div className="survey-list">
<div>
<SelectField labels={data.meat.labels} value={this.props.survey.meat}/>
</div>
<div>
<Button handleClick={() => this.handleActiveIndex(2)} label="Next"/>
</div>
</div>
</CSSTransition>
<CSSTranstion in={this.state.activeIndex === 1} timeout={200} classNames="survey-list" unmountOnExit>
<div className="survey-list">
<div>
<SelectField labels={data.energy.labels} value={this.props.survey.energy}/>
</div>
<div>
<Button handleClick={() => this.handleActiveIndex(2)} label="Next"/>
</div>
</div>
</CSSTransition>
Then your CSS:
.survey-list {
opacity: 1;
transform: translateX(0);
}
.survey-list.survey-list-enter {
opacity: 0;
transform: translateX(200px);
}
.survey-list.survey-list-enter-active {
opacity: 1;
transform: translateX(0);
transition: opacity 200ms;
}
.survey-list.survey-list-exit {
opacity: 1;
}
.survey-list.survey-list-exit-active {
opacity: 0;
transform: translateX(-200px);
transition: opacity 200ms;
}
And I'm not sure entirely the breadth of your intention, but you may also want to look into TransitionGroup, since it will automate adding classes to an array of children as they're toggled in and out:
https://reactcommunity.org/react-transition-group/transition-group
As a sidenote, if you're using BEM for your CSS, you shouldn't (i.e. surveyContainer--survey-list) be using a modifier as a block. Just allow survey-list to be its own block if it has its own elements. It prevents long confusing classes.

Using spinner font with rotation

I'm using a spinner icon from a font set and rotating it. I must set the transform-origin to define the centre of rotation of the icon to avoid wobbling (as suggested here). However, if I change the font size, the wobbling effect comes again. The same happens if I change the browser resolution.
HTML:
<div>
<p>First icon</p>
<i id="first" class="fa fa-spinner rotation-animation"></i>
</div>
<div>
<p>Second icon</p>
<span id="second" class="fa fa-spinner rotation-animation"></span>
</div>
<div>
<p>Third icon</p>
<span id="third" class="fa fa-spinner rotation-animation"></span>
</div>
<div>
<p>Fourth icon</p>
<span id="fourth" class="fa fa-spinner rotation-animation"></span>
</div>
CSS:
.rotation-animation {
animation: div-rotate 0.7s infinite steps(8);
transform: translateZ(0);
-webkit-transform: translateZ(0);
transform-origin: 50% 51%;
-webkit-transform-origin: 50% 51%;
}
#keyframes div-rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#-webkit-keyframes div-rotate {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
#first {
font-size: 20px;
}
#second {
font-size: 30px;
}
#third {
font-size: 40px;
}
#fourth {
font-size: 50px;
}
https://jsfiddle.net/r944z1a6/
As you can see in the above link, the second icon is the only one which does not wobble. If you change the browser resolution, the second one will wobble too.
Why is it happening? The x and y percent offsets to the centre of rotation shouldn't change when changing the font size. Isn't it?
Is there any way to fix this and make the spinner not to wobble for any size/resolution?
Note: I've used font awesome for the example, but I'm actually using a custom font, which has the same effect.
EDIT:
Regardless of #vals answer, the only way that I've found which doesn't seem to wobble is using linear rotation:
animation: div-rotate 0.7s infinite linear;
It's not so cool, but works.
There is nothing wrong with the font-awesome icon, and spinning it.
Try setting it to 200px and you will see that it spins perfectly.
The wobbling that you see, and that you are trying to correct, arises from rounding px from the browser at small font sizes.
It's impossible to predict what will be the size rounding for any font size and browser zoom.
So, the only way to get a perfect solution is to make your effect at a larger scale, and then scale it
.rotation-animation {
animation: div-rotate 0.7s infinite steps(8);
transform: translateZ(0);
transform-origin: 50% 50%;
}
#keyframes div-rotate {
0% { transform: rotate( 0deg) scale(0.1);}
100% { transform: rotate(360deg) scale(0.1);}
}
#first {
font-size: 200px;
margin: -90px;
}
#second {
font-size: 300px;
margin: -140px;
}
#third {
font-size: 400px;
margin: -180px;
}
#fourth {
font-size: 500px;
margin: -230px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div>
<p>First icon</p>
<i id="first" class="fa fa-spinner rotation-animation"></i>
</div>
<div>
<p>Second icon</p>
<span id="second" class="fa fa-spinner rotation-animation"></span>
</div>
<div>
<p>Third icon</p>
<span id="third" class="fa fa-spinner rotation-animation"></span>
</div>
<div>
<p>Fourth icon</p>
<span id="fourth" class="fa fa-spinner rotation-animation"></span>
</div>

ng-show doesn't keep up with ng-animation for scaling down in a dropdown

I have a dropdown that I want a scaling down animation to show when the dropdown opens and closes. I have a CODEPEN here with the code for you to experiment in.
I slowed it down to a 10 sec animation (not the final speed obviously) just for you to see what I mean. The items are scaling down at the speed I instructed (10 sec) but the items below won't come down until the ng-animation is completed. This causes overlap.
This is what I have in my HTML
<div class="cnt">
<md-list ng-click="menuIsOpen = 1" layout="row" layout-padding="" class="layout-row" layout-align="start center" flex>
<span class="title flex" flex=""> Menu Item</span>
<i class="fa fa-chevron-down"></i>
</md-list>
<div class="sub-menu" ng-show="menuIsOpen===1" ng-animate="'animate'" >
<md-menu-item ng-repeat="item in data" >
<md-button>
<div layout="row" flex="">
<a ui-sref="{{item.link}}">
<p flex=""><i class="fa fa-{{item.icon}}"></i> {{item.title}}</p>
</a>
</div>
</md-button>
</md-menu-item>
</div>
<md-list ng-click="menuIsOpen = 2" layout="row" layout-padding="" class="layout-row" layout-align="start center" flex>
<span class="title flex" flex=""> Menu Item 2</span>
<i class="fa fa-chevron-down"></i>
</md-list>
<div class="sub-menu" ng-show="menuIsOpen===2" ng-animate="'animate'" >
<md-menu-item ng-repeat="item in data">
<md-button>
<div layout="row" flex="">
<a ui-sref="{{item.link}}">
<p flex=""><i class="fa fa-{{item.icon}}"></i> {{item.title}}</p>
</a>
</div>
</md-button>
</md-menu-item>
</div>
</div>
And the CSS
.ng-hide-remove {
-webkit-animation:2s scaleIn ease;
animation:2s scaleIn ease;
}
#-webkit-keyframes scaleIn {
From {
transform-origin: top;
-webkit-transform: scaleY(0);
-moz-transform: scaleY(0);
-ms-transform: scaleY(0);
-o-transform: scaleY(0);
transform: scaleY(0);
}
To {
transform-origin: top;
-webkit-transform: scaleY(1);
-moz-transform: scaleY(1);
-ms-transform: scaleY(1);
-o-transform: scaleY(1);
transform: scaleY(1);
}
}
#keyframes scaleIn {
From {
transform-origin: top;
-webkit-transform: scaleY(0);
-moz-transform: scaleY(0);
-ms-transform: scaleY(0);
-o-transform: scaleY(0);
transform: scaleY(0);
}
To {
transform-origin: top;
-webkit-transform: scaleY(1);
-moz-transform: scaleY(1);
-ms-transform: scaleY(1);
-o-transform: scaleY(1);
transform: scaleY(1);
}
}
I am essentially trying to reproduce the same animation as in the angular material website seen here
p.s. any different approach or idea that doesn't require too much change overall, I am open to it. I am hoping for a css modification, but I know that it may not be that easy after all. I am hopeful though :)
Thanks for the help.
UPDATE:
After a litte bit trial and error I think I found a SOLUTION.
If you animate not the div around (sub-menu) your md-menu-items but the item itself, it will work.
I just added ng-if="menuIsOpen===1" to your md-menu-item (deleted the ng-show="menuIsOpen===1 from the sub-menu) and changed the animation as follows:
md-menu-item.ng-enter{
-webkit-animation:3s move ease;
animation:3s move ease;
}
#-webkit-keyframes move {
From {
margin-bottom:-50px;
}
To {
margin-bottom:0px;
}
}
#keyframes move {
From {
margin-bottom:-50px;
}
To {
margin-bottom:0px;
}
}
Now the size of every item in the menu is animated.
I cheated a little bit with margin-bottom, but height was still not working.
I think you have two options. ( At least I can't think of anything more.)
Or maybe three, see above.
1.You can change the height and add transform-origin: top; like here:
#keyframes scaleIn {
From {
transform-origin: top;
-webkit-transform: scaleY(0);
-moz-transform: scaleY(0);
-ms-transform: scaleY(0);
-o-transform: scaleY(0);
transform: scaleY(0);
height: 0px;
}
To {
transform-origin: top;
-webkit-transform: scaleY(1);
-moz-transform: scaleY(1);
-ms-transform: scaleY(1);
-o-transform: scaleY(1);
transform: scaleY(1);
height: 190px;
}
}
With transform-origin it will scale from the top and not from the middle.
BUT then you have to adjust the height every time you change the number of menu items.
You write it new (is probably nothig for you because you wont change much). I think there are definitely easier solutions like your posted example. e.g. see HERE
Only the styles are missing and everything works.
I tried to change the height to % too, but that just never worked.
Even add some divs and change some positions nothing happens.
So maybe someone else has a better solution.
Hopefully I wasn't to slow only just got time to look at this properly.
Edited Codepen
Now to start your main problem was using CSS animations rather then transitions. With transitions being better for this as you are transitioning from one state(open) to another(closed). Rather then a complex animation with no defined start or end state.
So what I've done is change your classes:
.sub-menu{
background: #333;
max-height: 500px;
position: relative;
display: block;
overflow:hidden;
}
.sub-menu.ng-hide{
max-height: 0;
}
.sub-menu.ng-hide-remove {
transition: max-height 700ms cubic-bezier(0.35, 0, 0.25, 1);
}
.sub-menu.ng-hide-add {
transition: max-height 600ms cubic-bezier(0.35, 0, 0.25, 1);
}
They now use transisiton. As well as max-height rather than height so that no specific height value needs to be given to the submenu to fully show it. Also using cubic-bezier for smoother transitioning.
Also I removed the ng-animate="'animate'" directives on elements as it isn't needed, it is the old way of adding animations. All classes are now managed by the ng-show directive and there is no ng-animate directive. The current ngAnimate docs can give more info about the classes.
The only other change made was to move the ng-show to the div with the submenu class, which was just so an extra class didn't need to be created for the <ul>.

How would i make an element inside of a div rotate repeatedly?

I have a div and can neither use ID nor class.
I can only use names like so:
<div name="picture">
<img src="http://i.imgur.com/p0Fu5UZ.jpg" />
</div>
<div name="info">
<p>- Insert information here</p>
</div>
CSS:
div{
-webkit-animation: name 4s infinite linear
}
#-webkit-keyframes name {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
What's the appropriate way to select any particular div, because [name=picture] doesn't work with the crammed code nor the non-crammed code. What can i do to fix this?
It should work for you:
CSS:
div[name="picture"] {
-webkit-animation: name 4s infinite linear
}
#-webkit-keyframes name {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
HTML:
<div name="picture">
<img src="http://i.imgur.com/p0Fu5UZ.jpg" />
</div>
<div name="info">
<p>- Insert information here</p>
</div>
Demo: http://jsfiddle.net/srnug/121/
If you need the elements inside the div to rotate, then you can modify the selector as div[name="picture"] img or div[name="picture"] p

Showing only a specific section of a rotating image

I have an image that I've gotten to rotate in an endless circle.
However, I'd like to know if it is possible to show only a section of the image. For example:
Below is the code I have to make the image rotate.
.vinyl {
height:2072px;
width:2072px;
display:block;
position:absolute;
top: -1150px;
left: -200px;
background:url('http://level42.ca/mike-vinyl/img/Record.png') right no-repeat;
-webkit-animation: spin 2s infinite linear;
-moz-animation: spin 2s infinite linear;
-o-animation: spin 2s infinite linear;
-ms-animation: spin 2s infinite linear;
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
#-moz-keyframes spin {
0% {
-moz-transform: rotate(0deg);
}
100% {
-moz-transform: rotate(360deg);
}
}
#-o-keyframes spin {
0% {
-o-transform: rotate(0deg);
}
100% {
-o-transform: rotate(360deg);
}
}
#-ms-keyframes spin {
0% {
-ms-transform: rotate(0deg);
}
100% {
-ms-transform: rotate(360deg);
}
}
This is going on a wordpress theme and is ideally going to fill the header background. (Approx 1500x300 px)
I've got the image in the header, but it is on top of all other objects, and covers have the webpage.
Hope this makes sense.
*Note, this is just a prototype/idea that I have, not sure if it will be practical or completely implemented at all.
[Edit 1]
Following the suggestion below, I was able to achieve exactly what I was looking for, however. The site-sponsorship class that I have is stuck in the background. How can I force it on top?
<header id="masthead" class="site-header" role="banner">
<div class="vinyl-wrapper">
<div class="vinyl-background">
</div>
<h2 class="site-sponsorship">
<div>
<span style="">Presented by: </span>
<img src="http://level42.ca/mike-vinyl/img/sunriselogo3.png" style="width:200px;height:62px;vertical-align:bottom">
</div>
</h2>
</a>
<div id="navbar" class="navbar">
<nav id="site-navigation" class="navigation main-navigation" role="navigation">
<h3 class="menu-toggle"><?php _e( 'Menu', 'twentythirteen' ); ?></h3>
<a class="screen-reader-text skip-link" href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentythirteen' ); ?>"><?php _e( 'Skip to content', 'twentythirteen' ); ?></a>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
<?php get_search_form(); ?>
</nav><!-- #site-navigation -->
</div><!-- #navbar -->
</header><!-- #masthead -->
Certainly possible, you could wrap the rotating image inside of a container element with relative positioning and hidden overflow. For example, with a container .header:
.header{
width:100%;
height:200px;
/* These are the important styles */
position:relative;
overflow:hidden;
}
Here's a JSFiddle demonstrating the implemented code, using the same CSS that you provide. Hope this helps! Let me know if you have any questions.
EDIT: In your addition to your question, it doesn't look like you close .vinyl-wrapper. If this was intentional, then you could use z-index to get .site-sponsorship to appear on top:
.site-sponsorship {
position:relative;
z-index:1;
}
Otherwise (if .site-sponsorship is actually outside .vinyl-wrapper), the fix will need to be a bit different, and you could also absolutely position .site-sponsorship (still using z-index):
.site-sponsorship {
position:absolute;
z-index:1;
top:0;
}
Here's a JSFiddle showing the second fix.

Resources