Little CSS animation on hover - html

Trying to create something like this.
I can't use letter-spacing. I created this code, but it doesn't work well.
http://jsfiddle.net/pyqq8wfe/
.refreshed_logo {
font-family: ProximaNovaBold;
font-size: 50px;
text-decoration: none;
color: #000000;
}
.logo_wrapper {
color: inherit;
text-decoration: none;
width: 250px;
position: absolute;
}
.refreshed_logo:after {
content: 'digital';
width: 20px;
height: 20px;
text-align: center;
position: absolute;
font-size: 20px;
background-color: red;
border-radius: 18px;
color: white;
margin-left: 4px;
margin-top: 3px;
text-indent: 8px;
font-weight: normal;
line-height: 1;
transition-property: width, height;
transition-duration: 0.2s, 0.2s;
transition-delay: 0s, 0.2s;
-o-transition-property: width, height;
-o-transition-duration: 0.2s, 0.2s;
-o-transition-delay: 0s, 0.2s;
-moz-transition-property: width, height;
-moz-transition-duration: 0.2s, 0.2s;
-moz-transition-delay: 0s, 0.2s;
-webkit-transition-property: width, height;
-webkit-transition-duration: 0.2s, 0.2s;
-webkit-transition-delay: 0s, 0.2s;
}
.refreshed_logo:hover:after {
width: 71px;
-webkit-transition: width 0.5s;
transition: width 0.5s;
text-indent: 2px;
}
.logo_wrapper:hover {
text-decoration: none;
}
<a href="/" class="logo_wrapper">
<span class="refreshed_logo">
Granat
</span>
</a>
Any thoughts?

Since you cannot use letter-spacing or split the words, below is an approach using border-right which along with overflow: hidden setting hides all characters after 'd'. On hover they are revealed and thus produce the effect.
.refreshed_logo {
font-family: ProximaNovaBold;
font-size: 50px;
text-decoration: none;
color: #000000;
}
.logo_wrapper {
color: inherit;
text-decoration: none;
width: 250px;
position: absolute;
}
.refreshed_logo:after {
content: 'digital';
width: 20px;
height: 20px;
/*text-align: center; not required */
position: absolute;
font-size: 20px;
background-color: red;
border-radius: 18px;
color: white;
/* following properties were added */
padding-left: 5px;
box-sizing: border-box;
border-right: 5px solid red;
overflow: hidden;
/* end of addition */
font-weight: normal;
line-height: 1;
transition-property: width, height;
transition-duration: 0.2s, 0.2s;
transition-delay: 0s, 0.2s;
}
.refreshed_logo:hover:after {
width: 65px;
transition: width 0.5s;
}
.logo_wrapper:hover {
text-decoration: none;
}
<a href="/" class="logo_wrapper">
<span class="refreshed_logo">
Granat
</span>
</a>

I've try to have the same result there's maybe better :
Last edit : for hide the others letter i've use the same color of the background, and only change the first letter color.
CSS :
.titre{
font-size:20pt;
}
.sstitre{
font-size:10pt;
font-weight:bold;
color:red;
background-color:red;
border-radius:10px;
padding-left:4px;
padding-right:2px;
width:10px;
position: absolute;
overflow:hidden;
transition:width 0.5s;
}
.sstitre::first-letter{
color:white;
}
.titre:hover .sstitre{
width:40px;
color:white;
}
HTML
<span class="titre">Granat<span class="sstitre">digital</span></span>
JSFidle

Related

Set own styles to content in before element

I've just created a button. I've found a problem where my content doesn't fit on it's place.
Here is my code:
.btn-red {
display: inline-block;
padding: 13px 20px;
color: #fff;
text-decoration: none;
position: relative;
background: #f42f2c;
font: 10px "Oswald", sans-serif;
letter-spacing: 0.4em;
text-align: center;
text-indent: 2px;
text-transform: uppercase;
transition: color 0.1s linear 0.05s;
border-radius: 0;
border: 1px solid #f42f2c;
}
.btn-red:focus {
box-shadow:none !important;
}
.btn-red::before {
content: "READ MORE";
display: block;
position: absolute;
top: 50%;
left: 0;
width: 100%;
height: 1px;
background: #f9f9ff;
color:#f42f2c !important;
z-index: 1;
opacity: 0;
transition: height 0.2s ease, top 0.2s ease, opacity 0s linear 0.2s;
}
.btn-red::after {
transition: border 0.1s linear 0.05s;
}
.btn-red .btn-red-inner {
position: relative;
z-index: 2;
}
.btn-red:hover {
transition: color 0.1s linear 0s;
text-decoration: none;
color: #f42f2c !important;
}
.btn-red:hover::before {
top: 0;
height: 100%;
opacity: 1;
transition: height 0.2s ease, top 0.2s ease, opacity 0s linear 0s;
}
.btn-red:hover::after {
transition: border 0.1s linear 0s;
}
<a href="o-nas.php" class="btn-red">
<span class="btn-inner">READ MORE</span>
</a>
I tried to add padding: 13px 20px to .btn-red::before, but it has some bugs and I don't know how to solve this.
I think I achieve the same thing that you wanted without using :before to control the button text. Look below:
.btn-red {
position: relative;
display: inline-flex;
box-sizing: border-box;
padding: 13px 20px;
text-decoration: none;
background-color: #f42f2c;
border: 1px solid #f42f2c;
}
.btn-red:before {
position: absolute;
top: 50%;
left: 0;
width: 100%;
height: 0;
content: "";
background-color: #fff;
transform: translateY(-50%);
transition: height 0.2s ease-in-out;
}
.btn-red .btn-inner {
font: 10px "Oswald", sans-serif;
color: #fff;
line-height: 1em;
letter-spacing: 0.4em;
text-transform: uppercase;
z-index: 1;
transition: color 0.2s ease-in-out;
}
.btn-red:hover:before {
height: 100%;
}
.btn-red:hover .btn-inner {
color: #f42f2c;
}
<a class="btn-red" href="#" title="Read More">
<span class="btn-inner">Read more</span>
</a>
Hope this can help you anyway. If you have any doubt about the code, please, just let me know :)
Cheers!

Hide text on hover and show an image

I made a button with some text in it and I want the text to disappear on hover and an image to appear in its place. Here is the HTML code:
#facebook {
width: 200px;
height: 50px;
border-style: solid;
border-color: white;
border-width: 1px;
border-radius: 7px;
line-height: 50px;
display: table-cell;
transition-timing-function: ease-in-out;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
-ms-transition: all 0.5s;
transition: all 0.5s;
}
#facebook:hover {
width: 200px;
height: 50px;
border-style: solid;
border-color: white;
line-height: 50px;
background: rgba(59, 89, 152, .6);
}
<a href="https://www.facebook.com">
<div id="facebook"><span id="text">Facebook</span>
</div>
</a>
So basically I want a Facebook logo to appear instead of text. I tried to do it alone, but I failed. Does anyone know how this can be done?
Something like that?
https://jsfiddle.net/d04pLr6q/
#facebook {
width: 200px;
height: 50px;
border-style: solid;
border-color: white;
border-width: 1px;
border-radius: 7px;
line-height: 50px;
display: table-cell;
transition-timing-function: ease-in-out;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
-ms-transition: all 0.5s;
transition: all 0.5s;
background-color: rgba(59, 89, 152, 1);
overflow:hidden;
text-align: center;
color:white;
}
a{
text-decoration:none;
}
#facebook:hover{
width: 200px;
height: 50px;
border-style: solid;
border-color: white;
line-height: 50px;
background-image: url(http://www.underconsideration.com/brandnew/archives/facebook_2015_logo_detail.png);
background-size: 100%;
background-position: center;
color: transparent;
}
You can replace this facebook img with any logo. Its not perfect but pure CSS :)
i suggest you don't use a div inside an a . it could cause errors. so i changed a bit your html structure ( the solution works the same with your html structure ) .
so i set the id #facebook directly on the a and if you want it to behave like a div just add display:block to a#facebook
second, i've hidden the text when hover with visibility:hidden, you can also use opacity:0 . in this case it won't matter.
keep in mind that you can use transition with opacity but not with visibility
then on :hover added a background-image to the #facebook element ( you can add whatever url you like )
let me know if it helps ;)
#facebook {
width: 200px;
height: 50px;
border-style: solid;
border-color: white;
border-width: 1px;
border-radius: 7px;
line-height: 50px;
display: table-cell;
transition-timing-function: ease-in-out;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
-ms-transition: all 0.5s;
transition: all 0.5s;
background-position:center center;
}
#facebook:hover{
width: 200px;
height: 50px;
border-style: solid;
border-color: white;
line-height: 50px;
background-color: rgba(59, 89, 152, .6);
background-image:url("http://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico");
background-repeat:no-repeat;
}
#facebook:hover #text {
visibility:hidden;
}
<span id="text">Facebook</span>
You need 2 blocks of hover CSS. See example below and adjust as needed.
#facebook {
width: 200px!important;
height: 50px!important;
border-style: solid;
border-color: white;
border-width: 1px;
border-radius: 7px;
line-height: 50px;
display: table-cell;
transition-timing-function: ease-in-out;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
-ms-transition: all 0.5s;
transition: all 0.5s;
position: relative;
display: inline-block;
}
img {
width: auto;
height: 50px;
display: none;
}
#facebook:hover img {
display: block;
height: 50px;
width: auto;
}
#facebook:hover #text {
display: none;
}
#facebook img {
width: 100%;
height: auto;
}
<a href="https://www.facebook.com">
<div id="facebook">
<span id="text">Facebook</span>
<img src ="http://i65.tinypic.com/2evxmqs.jpg" width="150px" height="45px" />
</div></a>
#facebook {
width: 200px;
height: 50px;
border-style: solid;
border-color: white;
border-width: 1px;
border-radius: 7px;
line-height: 50px;
display: table-cell;
transition-timing-function: ease-in-out;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
-ms-transition: all 0.5s;
transition: all 0.5s;
}
#facebook:hover {
width: 200px;
height: 50px;
border-style: solid;
border-color: white;
line-height: 50px;
background: rgba(59, 89, 152, .6);
}
#facebook span {
transition-timing-function: ease-in-out;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-o-transition: all 0.5s;
-ms-transition: all 0.5s;
transition: all 0.5s;
}
#facebook:hover span {
color: transparent;
}
<a href="https://www.facebook.com">
<div id="facebook"><span id="text">Facebook</span>
</div>
</a>
you can use JavaScript for that.
document.getElementById('facebook').onmouseover = function(){
document.getElementById('facebook').innerHTML = '';
document.getElementById('facebook').style.backgroundImage = 'url(pic.jpg)';
document.getElementById('facebook').style.backgroundSize = 'cover';
};
document.getElementById('facebook').onmouseout = function(){
document.getElementById('facebook').innerHTML = 'Facebook';
document.getElementById('facebook').style.backgroundImage = 'none';
};

Bad position of Proto.io's toggle button

I want to use toggle button from Proto.io:
https://proto.io/freebies/onoff.
It works but when I place the button after an image, the switch is not round anymore. Have a look how it is on JSFiddle: https://jsfiddle.net/rvmcn7ju.
Pro forma, here's the CSS:
.onoffswitch {
position: relative; width: 90px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
-moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "UP";
padding-left: 10px;
background-color: #009900; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "DOWN";
padding-right: 10px;
background-color: #000099; color: #FFFFFF;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 18px; margin: 6px;
background: #FFFFFF;
border: 2px solid #999999; border-radius: 20px;
position: absolute; top: 0; bottom: 0; right: 56px;
-moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
It works when I change top attribute to 292px in .onoffswitch-switch (with this particular image). I probably have to change the position to relative and do sth else. Any help appreciated.
Updated your fiddle you need position relative to contain the switch.
.onoffswitch-label {
position: relative;
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
https://jsfiddle.net/rvmcn7ju/1/
Updated again because the switch looked ovaly
.onoffswitch-switch {
...
margin: 4px; // changed margin
height: 18px; // added height
...
}
https://jsfiddle.net/rvmcn7ju/3/

Amending Font Size Without Affecting Other Classes

Please see my code below:
HTML =>
<header>
<div class="menuWrap">
Home
About
AM
Work
Contact
</div>
</header>
CSS =>
header {
width: 100%;
height: 80px;
background-color: #F5F5F5;
border-bottom: 1px solid #E6E6E6;
}
.menuWrap {
margin: 0 auto;
width: 80%;
height: 100%;
text-align: center;
}
.menuItem {
line-height: 80px;
display: inline-block;
width: 20%;
color: #1DC0CE;
text-decoration: none;
font-family: 'Lobster', cursive;
font-size: 25px;
-o-transition: .2s;
-ms-transition: .2s;
-moz-transition: .2s;
-webkit-transition: .2s;
transition: .2s;
}
.logoItem {
line-height: 80px;
display: inline-block;
width: 15%;
background-color: #1DC0CE;
color: #FFFFFF;
text-decoration: none;
font-family: 'Lobster', cursive;
font-size: 25px;
border-bottom: 1px solid #1DC0CE;
-o-transition: .2s;
-ms-transition: .2s;
-moz-transition: .2s;
-webkit-transition: .2s;
transition: .2s;
}
When I am increasing the font-size for 'logoItem' the 'menuItem' elements position is moving (the text is moving down the page)
Any tips on how to stop this!?
Give them a uniform height and ensure it's large enough to work for both sizes:
#menuWrap a {
display:inline-block;
height:30px;
}
You should probably get rid of the line-height declaration as well.

CSS 3 checkbox value is null when set to "off"

I have the following checkbox:
<div class="onoffswitch">
<input type="checkbox" name="showOnNavigation" class="onoffswitch-checkbox" id="showOnNavigation" checked>
<label class="onoffswitch-label" for="showOnNavigation">
<div class="onoffswitch-inner"></div>
<div class="onoffswitch-switch"></div>
</label>
</div>
The CSS for it:
.onoffswitch {
position: relative; width: 90px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
width: 200%; margin-left: -100%;
-moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ON";
padding-left: 10px;
background-color: #A3D900; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #CCCCCC; color: #333333;
text-align: right;
}
.onoffswitch-switch {
width: 25px; margin: 2.5px;
background: #000000;
border: 2px solid #999999; border-radius: 20px;
position: absolute; top: 0; bottom: 0; right: 56px;
-moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
When I'm submitting a form and checkbox is on the ON position, the checkbox value is ON. When it is on OFF position, the value is not set to OFF, so my script will issue an error that the index is not set. It used to work before, but for some reason it doesn't work anymore. Really frustrating, kindly HELP!! A CSS only approach would be most preffered, otherwsie I could easily do this with JavaScript.
I got the code generated from http://proto.io/freebies/onoff/
Put a hidden field with the same name before your checkbox with a value of "OFF"