Animating background colour without using image – how to animate exit - css-animations

I wanted a hover effect where the background of a link would be filled on hover and emptied on exit.
The solution I've come up with so far is using keyframes to fill the element by adding linear gradients stop motion style.
HTML
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. </p>
SCSS
$hovercolor:goldenrod;
a {
text-decoration: none;
color: black;
border-bottom: 3px solid $hovercolor;
background: white;
&:hover {
animation-name: hoveranimate;
animation-duration: .1s;
animation-fill-mode: forwards;
}
}
#keyframes hoveranimate {
0% {
background: linear-gradient(white, white 100%, $hovercolor 80%, $hovercolor);
}
10% {
background: linear-gradient(white, white 90%, $hovercolor 70%, $hovercolor);
}
20% {
background: linear-gradient(white, white 80%, $hovercolor 60%, $hovercolor);
}
30% {
background: linear-gradient(white, white 70%, $hovercolor 50%, $hovercolor);
}
40% {
background: linear-gradient(white, white 60%, $hovercolor 40%, $hovercolor);
}
50% {
background: linear-gradient(white, white 50%, $hovercolor 30%, $hovercolor);
}
60% {
background: linear-gradient(white, white 40%, $hovercolor 20%, $hovercolor);
}
70% {
background: linear-gradient(white, white 30%, $hovercolor 20%, $hovercolor);
}
80% {
background: linear-gradient(white, white 20%, $hovercolor 10%, $hovercolor);
}
90% {
background: linear-gradient(white, white 10%, $hovercolor 0%, $hovercolor);
}
100% {
background: linear-gradient(white, white 0%, $hovercolor 0%, $hovercolor);
}
}
http://codepen.io/snuts/pen/NdrrXN
So I'm halfway there, the animation works on hover, but I've not worked out a way to reverse the animation on exit.
Anyone know a way to achieve this? And also, if there is a simpler way to achieve the first step I'd be happy to learn it.
Thanks.

I tried to write some new code on your solution but was too bad to manage it so i leave that to somebody else.. But i did manage to solve the animation back with the way your code worked...
So what i did was to just create another keyframe when not hovering.. (on the a tag) with the same animation attributes you used ...
a{
animation-name:hoverout;
animation-duration: .1s;
animation-fill-mode: forwards;
}
and then i made a new keyframe exactly like yours but backwards...
#keyframes hoverout {
100% {
background: linear-gradient(white, white 100%, $hovercolor 80%, $hovercolor);}
90% {
background: linear-gradient(white, white 90%, $hovercolor 70%, $hovercolor);}
80% {
background: linear-gradient(white, white 80%, $hovercolor 60%, $hovercolor);}
70% {
background: linear-gradient(white, white 70%, $hovercolor 50%, $hovercolor);}
60% {
background: linear-gradient(white, white 60%, $hovercolor 40%, $hovercolor);}
50% {
background: linear-gradient(white, white 50%, $hovercolor 30%, $hovercolor);}
40% {
background: linear-gradient(white, white 40%, $hovercolor 20%, $hovercolor);}
30% {
background: linear-gradient(white, white 30%, $hovercolor 20%, $hovercolor);}
20% {
background: linear-gradient(white, white 20%, $hovercolor 10%, $hovercolor);}
10% {
background: linear-gradient(white, white 10%, $hovercolor 0%, $hovercolor);}
0% {
background: linear-gradient(white, white 0%, $hovercolor 0%, $hovercolor);}
}
Hope this helped! here is a working fiddle too: http://codepen.io/anon/pen/pREadY

Related

how to make a full width slider without loosing quality?

i am trying to create a full width slider for only images with text. My slider is full width but needs a specific height (example 400px)because it is going to be displayed as the banner of my website.
The problem is that the images look blurry and i dont know the proper size or perhaps the code to prevent this.
This is what i have so far as for my html and the images's size
<div class="wrapper">
<div class="full-width">
<div class="inner">
<div class="slide">
<div>Lorem ipsum dolor sit amet, consectetur. <br>Curabitur molestie elit et ultricies vehicula.</div>
<img src="http://lorempixel.com/1020/400/sports" width="1020" height="400">
</div>
<div class="slide">
<div>Nullam dictum magna sapien, sed adipiscing nibh. <br>Curabitur molestie elit et ultricies vehicula.</div>
<img src="http://lorempixel.com/1020/400/city" width="1020" height="400">
</div>
<div class="slide">
<div>Donec malesuada hendrerit velit, sed consequat. <br>Curabitur molestie elit et ultricies vehicula.</div>
<img src="http://lorempixel.com/1020/400/cats" width="1020" height="400">
</div>
<div class="slide">
<div>Maecenas augue dui, rhoncus a blandit non. <br>Curabitur molestie elit et ultricies vehicula.</div>
<img src="http://lorempixel.com/1020/400/business" width="1020" height="400">
</div>
</div>
<div class="controls">
<
>
</div>
<div class="slide-nav"></div>
</div>
</div>
as for my css:
.full-width {
overflow: hidden;
position: relative;
background: #fff;
}
.full-width,
.full-width .slide img {
width: 100%;
}
.full-width:hover {
background: transparent;
}
.full-width .inner {
overflow-y: hidden;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=00)";
filter: alpha(opacity=00);
-moz-opacity: 0;
opacity: 0;
}
.full-width .slide {
float: left;
overflow-x: hidden;
position: relative;
}
.full-width .slide img {
height: auto;
}
.full-width .slide div {
color: #fff;
position: absolute;
padding: 0 5%;
left: 0;
width: 90%;
text-align: right;
font-size: 32px;
}
.full-width .slide div p {
float: right;
text-align: left;
padding: 10px;
margin: 0;
background: rgba(0, 0, 0, 0.8);
}
.full-width .controls a {
position: absolute;
top: 50%;
margin-top: -46px;
display: block;
background: rgba(0, 0, 0, 0.5);
text-decoration: none;
color: #fff;
font-size: 40px;
padding: 0 10px 2px 7px;
line-height: 40px;
*display: none;
}
.full-width .controls a.left {
left: 0px;
}
.full-width .controls a.right {
right: 0px;
}
.full-width .slide-nav {
*display: none;
font-size: 75px;
margin: 0 auto;
line-height: 50px;
font-family: 'Helvetica', Arial, sans-serif;
}
.full-width .slide-nav span {
cursor: pointer;
color: #ccc;
}
.full-width .slide-nav span.current {
color: #333;
}
.lt-ie9 .full-width p,
.lt-ie9 .full-width .controls a {
background: url('bg-trans.png') repeat;
_background: #333;
}
what i need to know if it is a matter of adjusting only the image size although i tried that already and didnt worked or if it remains in the code.
thanks in advance for any help!
If the images are getting blurry at larger sizes, you will need to produce an image with the dimensions of the maximum area you want it to cover. This way when it is at full size the quality will be clear.
When you decrease the screen size, the image size will likely be decreasing too. In my experience it is better to start large and scale to a smaller size to preserve the clarity of the image, so you should approach it that way.
If the problem is that it is not scaling correctly because the proportions are off because of the fixed height, then you will need to produce images with the correct proportions to support the size you need. This is most easily done with image editing software like Photoshop rather than making adjustments in HTML.

Full width input buttons on same line

I'm trying to make two input buttons (yes/no) display on the same line with maximum width for both. I want the width of the buttons to scale down in size as the browser window size decreases.
http://jsfiddle.net/jasonniebauer/grQGP/1/
<div id="merchant_radio6">
<p>
Ever accepted credit cards before?
</p>
<div>
<input type="radio" id="yes" name="accept_cc"/>
<label for="yes">
Yes
</label>
<input type="radio" id="no" name="accept_cc"/>
<label for="no">
No
</label>
</div>
</div>
#merchant_radio6 input[type="radio"],
#merchant_radio7 input[type="radio"] {
display: none;
}
#merchant_radio6 input[type="radio"] + label,
#merchant_radio7 input[type="radio"] + label {
box-sizing:border-box;
padding: 1rem 3rem 1rem 3rem;
width: 100%;
display: inline-block;
color: #BDC3C7;
background-color: #F2F2F2;
text-align: center;
vertical-align: middle;
cursor: pointer;
border-radius: 3px;
-webkit-transition: border .25s linear, color .25s linear, background-color .25s linear;
-webkit-transition-property: border, color, background-color;
-webkit-transition-duration: 0.25s, 0.25s, 0.25s;
-webkit-transition-timing-function: linear, linear, linear;
-webkit-transition-delay: initial, initial, initial;
transition: border .25s linear, color .25s linear, background-color .25s linear;
transition-property: border, color, background-color;
transition-duration: 0.25s, 0.25s, 0.25s;
transition-timing-function: linear, linear, linear;
transition-delay: initial, initial, initial;
}
#merchant_radio6 input[type="radio"] + label:nth-of-type(2),
#merchant_radio7 input[type="radio"] + label:nth-of-type(2) {
margin-left: 1rem;
}
#merchant_radio6 input[type="radio"]:checked + label,
#merchant_radio7 input[type="radio"]:checked + label {
background-color: #3498DB;
color: #FFFFFF;
outline: 0;
}
Set each button width to 50% and set them to float: left. If you want space between your buttons, you'll need to do something like width: 49%; margin-left: 1%;
Each button needs to be set to 50% width or less for them to appear on the same line. When width is set as a percentile, it uses the parent's width to calculate its own width - it makes no adjustments based on sibling elements' widths.
Edit: because you have margins set, these will need to be at <50% width. For most (all?) browsers, margins are calculated separately from width when considering display. E.g. an element that's 50% width and has a 10px margin on each side will take up more than 50% of its parent container's width. Note that some browsers might also treat borders this way.

create a border-radius for div

I've created a div, where in I've to write css for creating border-radius to that div. So I wanted the border-radius should be like the following image.
The CSS code what I've written is as follows.
{
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
border-top-right-radius: 6% 60%;
border-bottom-right-radius: 6% 60%;
margin: 10px 0;
color: #FFFFFF;
background: -moz-linear-gradient(top, #2ea2f5 0%, #2ea2f5 50%, #0089f3 50%, #0089f3 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#2ea2f5), color-stop(50%,#2ea2f5), color-stop(50%,#0089f3), color-stop(100%,#0089f3));
background: -webkit-linear-gradient(top, #2ea2f5 0%,#2ea2f5 50%,#0089f3 50%,#0089f3 100%);
background: -o-linear-gradient(top, #2ea2f5 0%,#2ea2f5 50%,#0089f3 50%,#0089f3 100%);
background: -ms-linear-gradient(top, #2ea2f5 0%,#2ea2f5 50%,#0089f3 50%,#0089f3 100%);
background: linear-gradient(to bottom, #2ea2f5 0%,#2ea2f5 50%,#0089f3 50%,#0089f3 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#2ea2f5', endColorstr='#0089f3',GradientType=0 );
}
And even you can go through it jsfiddle.net
So please help me I've stuck with this from 2 days.
Well, I managed to do something similar, and it should be cross-browser supported ( after small edits ) :
http://jsbin.com/elubek/1/edit
CSS:
div.wrapper {
position: relative;
width: 450px;
}
div.tag {
width: 400px;
padding: 3px 10px;
height: 74px;
background: -webkit-linear-gradient(top, #2ea2f5 0%,#2ea2f5 50%,#0089f3 50%,#0089f3 100%);
border-radius: 5px;
position: absolute;
top: 0;
z-index: 120;
}
div.box1 {
height: 62px;
width: 62px;
right: 0px;
top: 9px;
border-radius: 10px;
z-index: -1;
position: absolute;
-webkit-transform: rotate(-45deg);
background: -webkit-linear-gradient(top right, #2ea2f5 0%,#2ea2f5 50%,#0089f3 50%,#0089f3 100%);
float: right;
}
div.circle {
width: 10px;
height: 10px;
position: absolute;
z-index: 5;
border-radius: 100px;
background: white;
right: 10;
top: 35px;
}
p {
font-family: 'Verdana';
color: white;
margin: 0;
}
p.prgress-info {
font-size: 25px;
letter-spacing: -1px;
padding-top: 10px;
}
p.deadline {
padding-bottom: 19px;
font-size: 12px;
font-weight: normal;
}
p.deadline span { font-size: 14px; }
HTML:
<div class='wrapper'>
<div class='tag'>
<p class="prgress-info">003. In progress</p>
<p class="deadline"><span>7</span>/ Deadline: 30 July 2013</p>
</div>
<div class='box1'></div>
<div class='circle'></div>
</div>
You can play with the height/width of div.box1, to achieve the radius you want ;)
border-radius does allow some complex shapes, using it's extended syntax. For example:
border-radius:15px 25px 25px 15px / 15px 45px 45px 15px;
See http://jsfiddle.net/tDCaA/1/ for this in action. It's heading in the direction you're looking for, but doesn't quite achieve it.
The trouble is that further tweaking doesn't get much closer -- with the straight lines you've got on the sample image, you're really not looking at a border-radius effect at all; it's a more complex shape than border-radius is designed to do. So my advice would be to stop focusing on border-radius as the answer here, and look for alternatives.
So what alternatives are there? Here are a few you could try:
An SVG image. This example is a good case for an SVG image, as you've got a few little design elements in there like the white hole at the end of the tag which aren't easy to achieve in CSS.
A CSS triangle. Draw the end part of the tag using the old triangle hack with a CSS border. You may have trouble getting the corners rounded on this though.
Rotation. Create a second element (possibly using the CSS :after selector), that will act as the end piece of the tag. Then use CSS to rotate it 45 degrees to give it the required shape. To be honest though, I would consider using rotation for this to be overkill, and not great for browser performance. It should work though. And since we're already rotation, you could also use other transform effects to tweak it to the desired shape.
CSS border-image. CSS also has a border-image property that can be used to do complex borders. Combined with SVG, this can be very powerful and can give you all the variable shaped borders you want. Most modern browsers support it now (http://caniuse.com/#search=border-image).
An old-school background image. Don't be afraid of just using a plain png background image for this kind of thing. All the techniques above have their place, but background images work well and have compatibility with old browser versions. There's nothing wrong with using them for this kind of thing if the other solutions don't work for you.

Text isn't wrapping inside absolute positioned container

I've created tooltips that are absolutely positioned and have divs inside of them that have max-width: 200px;. The text within the divs are not wrapping to the next line, however. They're going outside of the container even though there are spaces in the text, so it's not a word-break issue. See image below:
Edit: The tooltips are pulling in the text from their trigger element's title attribute and that seems to be the problem. If the content is hard-coded, the text wraps just fine.
Here's the HTML:
<div class="tooltip">
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis malesuada, lectus eget gravida eleifend, odio libero hendrerit elit.</div>
</div>
And the CSS:
.tooltip{
padding: 10px;
position: absolute;
background: #303030;
font-size: .9em;
color: #ccc;
-moz-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: 0 5px 10px rgba(0,0,0,.4);
-moz-box-shadow: 0 5px 10px rgba(0,0,0,.4);
box-shadow: 0 5px 10px rgba(0,0,0,.4);
}
.tooltip div{
max-width: 200px;
border: 1px solid red; /* See where element is */
}
This seems so obvious, but I cannot think of what the issue is. Any help would be appreciated.
Thanks
It probably has something to do with the way you're injecting the text into the .tooltip element. Try something like this (using jQuery):
$('.trigger').on('click', function() {
$('.tooltip div').html($('.trigger').attr('title'));
});
http://jsfiddle.net/DyxkA/

Kwicks slider images with text

Hello (I am not a programmer so bear with me)
I am using drupal 7. My boss loves the KWICKS slider. I have gotten this to work but only with images using views-kwicks module.
I would like to be able to have text(teaser) placed over the images in the slider with a link to the corresponding page when clicked, like http://demo.themesmania.com/creative/kwicks-slider
How should I go about doing this? Thank you!!
the markup used in that link is:
put this inside your <li></li> of kwicks:
<div class="slide-description">
<h4>At vero eos et accusamus et</h4>
<p>At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti</p>
</div>
then use this css:
.slide-description { background-color:#000;
bottom: 0;
cursor: pointer;
display: block;
font-weight: normal;
left: 0;
line-height: normal;
padding: 16px 20px;
position: absolute;
width: 760px;z-index: 2;}