I'll get straight to the point. What I want to do is to create simple text, such as: © 2017, that will change (on hover) to developed by Jonathan Doe. I want activation field to be smaller than the deactivation field but the problem is that hitbox for the © 2017 is the size of hidden element.
I was looking for the solution on the internet for quite some time but everything that I found, was button with not flexible width. Maybe I need to use some sort of tooltip, that will cover passive state? I am not sure.
I want this element to float in the bottom left cornet of the site, that's why I set position to fixed.
The other problem is that when text developed by Jonathan Doe is active, deactivation field is bigger on top than it should be. It looks like elements with 0 opacity are messing up my hitboxes. I was trying to play with display: none;, but then animation is not playing.
I started to code literally yesterday, so please forgive me for all the noob mistakes. I am trying to understand the logic behind all of this.
I've added the piece of code, I hope I did it right.
.con {
position: fixed;
font-weight: normal;
color: #000000;
font-family: 'Roboto', sans-serif;
z-index: 99;
}
/* © 2017 */
.con.copyright:before {
position: fixed;
padding: 9px 16px 7px 16px;
bottom: 16px;
left: 16px;
font-size: 14px;
line-height: 26px;
text-align: left;
content: '© 2017';
opacity: 1;
transition: all 0.3s cubic-bezier(.64, 0, .36, 1);
}
.con.copyright:hover:before {
opacity: 0;
bottom: 32px;
}
.con.copyright:after {
position: fixed;
padding: 9px 16px 7px 16px;
bottom: 0px;
left: 16px;
font-size: 14px;
line-height: 26px;
text-align: left;
content: 'developed by Jonathan Doe';
opacity: 0;
transition: all 0.3s cubic-bezier(.64, 0, .36, 1);
}
.con.copyright:hover:after {
opacity: 1;
bottom: 16px;
}
<div class="con copyright"></div>
I do not like how you can keep developed by Jonathan Doe text active by quickly moving your mouse over it.
It took me few additional days but I think I've finally did this. Hitboxes are perfect. The only one problem now is that for some unknown reason, text is not antialiased. I was playing with some values but nothing helped.
EDIT: I've came out with better version. Less messy and with working antyaliasing.
Here is the new version - maybe some beginner like myself will find this useful. I will update it if I discover anything new:
EDIT: I've: • added transition-delay and reversed it so that effect is properly played on "mouseout"
EDIT: I've: • replaced visibility: hidden; with pointer-events: none; because with greater transform: translateY values "mouseout" was glitchy • split transition: all to transition: transform, opacity and removed transition-delay to get better control over delays
EDIT: Minor adjustments for better UX
* {
box-sizing: border-box;
}
/* copyright */
.copyright {
position: fixed;
color: #000000;
font-family: 'Roboto', sans-serif;
font-size: 14px;
left: 16px;
top: 16px;
text-align: left;
width: 78px;
height: 42px;
z-index: 10;
}
.copyright:before {
pointer-events: none;
position: absolute;
display: block;
top: 13px;
left: 16px;
opacity: 1;
content: '© 2017';
transform: translateY(0px);
transition: transform .24s 0s ease, opacity .16s .08s ease;
}
.copyright:hover:before {
transform: translateY(-24px);
transition: transform .24s 0s ease, opacity .16s 0s ease;
opacity: 0;
}
.copyright_ch {
position: absolute;
opacity: 0;
padding: 13px 0px 0px 16px;
top: 0px;
left: 0px;
pointer-events: none;
width: 205px;
transition: transform .24s 0s ease, opacity .16s 0s ease;
height: 100%;
transform: translateY(24px);
}
.copyright:hover .copyright_ch {
opacity: 1;
pointer-events: auto;
transform: translateY(0px);
transition: transform .24s 0s ease, opacity .16s .08s ease
}
<div class="copyright"><div class="copyright_ch">developed by Jonathan Doe</div></div>
note: This is not really a flexible solution. If you would like to change inscriptions, font size, hitboxes etc., you will have to change and adjust values manually. To get a good look at current hitboxes add background-color: #cccccc; to .copyright and .copyright_ch classes. You might also want to play with opacity: 0/1 so that you can see what you are working with.
Related
On my site (antetech.org) I use bttn.css for the nav buttons. On the buttons the letter-spacing is doubled on hover. When the right buttons are hovered, all the ones to the left shift over. How can I keep the letter-spacing effect without having the other buttons move? Here is the bttn.css code
.bttn-default {
color: #fff;
}
.bttn-primary, .bttn, .bttn-md {
color: #fff;
}
.bttn, .bttn-md {
margin: 0;
padding: 0;
border-width: 0;
border-color: transparent;
background: transparent;
font-weight: 400;
cursor: pointer;
position: relative;
}
.bttn-md {
font-size: 6px;
font-family: inherit;
padding: 1% 2%;
}
.bttn-stretch {
margin: 0;
padding: 0;
border-width: 0;
border-color: transparent;
background: transparent;
font-weight: 400;
cursor: pointer;
position: relative;
font-family: inherit;
padding: 1px 2px;
overflow: hidden;
border-width: 0;
border-radius: 0;
background: transparent;
color: #fff;
letter-spacing: 0;
-webkit-transition: all 0.2s cubic-bezier(0.02, 0.01, 0.47, 1);
transition: all 0.2s cubic-bezier(0.02, 0.01, 0.47, 1);
}
.bttn-stretch:after, .bttn-stretch:before {
position: absolute;
left: 0;
width: 100%;
height: 1px;
background: currentColor;
content: '';
opacity: 0.65;
-webkit-transition: all 0.2s cubic-bezier(0.02, 0.01, 0.47, 1);
transition: all 0.2s cubic-bezier(0.02, 0.01, 0.47, 1);
-webkit-transform: scaleX(0);
transform: scaleX(0);
}
.bttn-stretch:after {
top: 0;
}
.bttn-stretch:before {
bottom: 0;
}
.bttn-stretch:hover, .bttn-stretch:focus {
letter-spacing: 2px;
opacity: 0.9;
-webkit-transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
}
.bttn-stretch:hover:after, .bttn-stretch:focus:after {
opacity: 1;
-webkit-transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
.bttn-stretch:hover:before, .bttn-stretch:focus:before {
opacity: 1;
-webkit-transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
.bttn-stretch.bttn-md {
font-size: 120%;
font-family: inherit;
padding: 1px 2px;
}
.bttn-stretch.bttn-default {
color: #fff;
}
.bttn-stretch.bttn-primary {
color: #FFF;
}
Hopefully what I'm trying to do is possible, I'm not sure if it is. Thanks for the help <3
You can add a min-width to the buttons so that they're already big enough to display the text with the expanded letter spacing:
.bttn-stretch { min-width: 5.25em; }
Using em units helps ensure this will still work regardless of the font-size. I'd recommend specifying your letter-spacing in fractional ems as well.
I would also scope the hover effect to non-touch devices. Something like:
#media only screen and (min-width: 420px) { /* this media query targets screens at least 420px wide. The intent here is to only apply the :hover styles on devices with a mouse. Admittedly, 420 pixels is a bit of an arbitrary value here, you might find a better way to target the right devices for your use case. */
.bttn-stretch { min-width: 5.25em; } /* this sets a minimum value for the width of the buttons so that they're already big enough to accommodate the letter-spaced text before the :hover styles are applied */
.bttn-stretch:hover, .bttn-stretch:focus {
letter-spacing: 0.104em; /* Currently you've got this set to 2px. I prefer to use em units because it keeps the spacing proportional to the size of your font. Because your font size is set at 19.2px, a value of 0.104em gets you very close to your current letter-spacing of 2px. You could just use 0.1em if you're not bothered by the 0.004em difference */
/* the following lines were in your existing style sheet, I've just copied them over */
opacity: 0.9;
-webkit-transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
}
}
Setting the width of the parent div of your buttons and also giving your buttons a set width should give you the functionality that you want, just be mindful that you will have to adjust the values as the value i used was just to test, also make sure it carries over when the screen is reduced to mobile size you may need to edit some css in that case also
#second-nav{
list-style: none;
float: right;
margin-top: 60px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
margin-top: 0;
margin-bottom: 0;
padding-top: 15px;
padding-bottom: 15px;
display: block;
width: 480px;
}
#second-nav li{
position: relative;
display: inline-table;
padding: 5px 20px;
width: 70px;
}
I'm using a CSS transition on my hyperlink elements to make their interaction appear smoother. But I also want immediate feedback when the user is waiting for it. Hence I want the new state to appear immediately, but let it fade out when the user moves away.
Here's some CSS that I'm currently using:
a
{
display: inline-block;
padding: 20px;
background: #eeeeee;
color: black;
text-decoration: none;
transition: background 1s;
}
a:hover
{
background: #bbbbbb;
transition: background 0s;
}
a:active
{
background: #888888;
transition: background 0s;
}
Test link
As you can see the colour fade is in effect when leaving the element with the mouse cursor, but not when entering it.
When pressing a mouse button on the hovered link, the colour again changes immediately.
Now comes the interesting part: When the mouse button is released, I'd like the colour to fade back to the hover state. But I can't manage to do so because the :hover state doesn't know from which state direction it's coming and always disables the transition.
Whatever is changed, there must be no transition when first hovering the link.
Again in a simple state diagram:
State: normal <----------> hover <----------> active
Transition: yes no yes? no
(currently no)
Is this possible with CSS? I know I could add custom JavaScript but that would need to go to a great number of elements.
An idea is tu use pseudo-element to create your backgrounds and you can easily create the effect you want. The drawbacks is that you will have more CSS and you have to add your content inside a span in order to correctly set z-index values.
Using 2 pseudo-elements:
a {
display: inline-block;
padding: 20px;
background: #eeeeee;
color: black;
text-decoration: none;
transition: background 1s;
position: relative;
}
a span {
position: relative;
z-index: 3;
}
a:before,
a:after {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: transparent;
z-index: 1;
transition: background 1s;
}
a:after {
z-index: 2;
}
a:hover::before {
background: red;
transition: background 0s;
}
a:active::after {
background: blue;
transition: background 0s;
}
<span>Test link</span>
Using only one pseudo element:
a {
display: inline-block;
padding: 20px;
background: #eeeeee;
color: black;
text-decoration: none;
transition: background 1s;
position: relative;
}
a span {
position: relative;
z-index: 1;
}
a:before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: transparent;
z-index: 0;
transition: background 1s;
}
a:hover {
background: red;
transition: background 0s;
}
a:active::before {
background: blue;
transition: background 0s;
}
<span>Test link</span>
Here's what I did based on Temani Afif's answer. It doesn't need the additional <span> inside the link but instead an additional data-text attribute on it, and it only works for plain text content (no images etc.).
The example has two test links, one with and one without the attribute, to show the fallback behaviour that's basically what I have in the question.
Not sure which is "better". It probably depends on the circumstances. I just wanted to add this solution as well.
a
{
display: inline-block;
padding: 20px;
background: #eeeeee;
color: black;
text-decoration: none;
transition: background 1s;
position: relative;
}
a:hover
{
background: red;
transition: background 0s;
}
a[data-text]::before
{
content: attr(data-text);
color: transparent;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: 20px;
background: transparent;
transition: background 1s, color 1s;
}
a[data-text]:active::before,
a:not([data-text]):active
{
color: white;
background: blue;
transition: background 0s;
}
Test link
Test link
I have a simple overlay of text over an image, darkening the background in the process. I used transition with ease-in-out, but it doesn't seem to ease out properly.
I know that the ease-in-out should be applied to the thing itself, and not its pseudo of :hover, but it doesn't seem to want to work. I have tried many ways, moving it around, deleting stuff, adding stuff, but nothing seems to make sense.
I notice the text do ease out fine, but the background with rgba opacity doesn't co-operate. It just snaps back :(
Do refer to a live version at http://g4stly.com/staff.html to know what I'm talking about, specifically.
Thanks in advance!
My code is as follows:
#g4stly
{
background-image: url('http://g4stly.com/images/users/g4stly.jpg');
}
.textFrame
{
text-align: center;
font-size: 20px;
color: #DDAA49;
text-decoration: none;
background-repeat: no-repeat;
background-size: cover;
border-radius: 30%;
width: 250px;
height: 250px;
}
.textFrame p
{
opacity: 0;
height: 75%;
margin: 0;
border-radius: 30%;
transition: opacity 300ms ease-in-out;
}
.textFrame p a
{
text-decoration: none;
color: #976649;
font-size: 25px;
}
.textFrame:hover p
{
opacity: 1;
background: rgba(0,0,0,0.8);
}
.textFrame p:first-child
{
padding: 25% 0 0 0;
}
<div id="g4stly" class="textFrame textFrameLeft">
<p>g4stly<br><br>
Owner of everything g4stly related<br>
Basically, the boss.</p>
</div>
I noticed you updated the code. Looks like your issue has already been solved.
The .textFrame p was only applying transition for opacity, so you couldn't see the background transition. I seed you added background .... to the transition, you could also do:
transition: all 1000ms ease-in-out;
Another option would be to move the rgba background to inside the .textFrame p, so the background wouldn't suddenly disappear, fading out along with the rest of the element.
Hopefully this helps you understand the cause :)
You had a comma where there should have been a semicolon.
transition: background 1000ms ease-in-out;
#g4stly {
background-image: url('http://g4stly.com/images/users/g4stly.jpg');
}
.textFrame {
text-align: center;
font-size: 20px;
color: #DDAA49;
text-decoration: none;
background-repeat: no-repeat;
background-size: cover;
border-radius: 30%;
width: 250px;
height: 250px;
}
.textFrame p {
opacity: 0;
height: 75%;
margin: 0;
border-radius: 30%;
transition: background 1000ms ease-in-out;
transition: opacity 1000ms ease-in-out;
}
.textFrame p a {
text-decoration: none;
color: #976649;
font-size: 25px;
}
.textFrame:hover p {
opacity: 1;
background: rgba(0, 0, 0, 0.8);
}
.textFrame p:first-child {
padding: 25% 0 0 0;
}
<div id="g4stly" class="textFrame textFrameLeft">
<p>g4stly<br><br> Owner of everything g4stly related<br> Basically, the boss.</p>
</div>
I am trying to recreate an effect I saw on "TheButton" subreddit. You can see that next to most usernames there is a colored dot that when hovered over expands and reveals some underlying text.
Using their CSS as a starting point, I can recreate this effect but my issue is that the underlying text I have does not collapse, so I never achieve a "dot" shape while the user is not hovering.
Here's my CSS:
* {
font: normal x-small verdana,arial,helvetica,sans-serif;
}
.flair {
min-width: 12px;
max-width: 12px;
height: 12px;
line-height: 12px;
border-radius: 12px;
border: none;
overflow: hidden;
padding: 0;
vertical-align: middle;
font-size: 10px !important;
-webkit-transition:all 0.3s;
transition: all 0.3s;
-webkit-transition-delay: 1s;
transition-delay: 1s;
position: relative;
}
.flair:hover {
max-width: 500px;
padding: 0 5px;
color: #fff;
-webkit-transition-delay: 0s;
transition-delay: 0s;
}
.flair-no-press {
background:#888;
color:#888;
}
And here's my HTML:
<span class="flair flair-no-press" title="non presser">non presser</span>
Here's a jsfiddle showing what this looks like. Once again my intended effect is simply making the dot collapse entirely when not being hovered over like they have.
What am I missing here?
Is it possible to choose a different timing/speed for transition in css so when mouse hover over a div it expands with different speed than the speed it retracts back to its original width not hover state.
I have tried declaring different transition speeds in :hoer and normal state styling, however, only normal state style seems to apply.
http://jsfiddle.net/tpf8mv51/3/
Problems:
1st) it goes with same speed it expanded with.
2nd) zindex takes effect after animation is completed for reasons i don't gte.
3rd) other images get affected even though they shouldn't, by affected i mean they 99% of time disappear till animation is done.
* {
margin: 0;
padding: 0;
}
body {
overflow: hidden;
}
.main {
font-size: 0;
height: 100%;
width: 100%;
display: none;
z-index: -1;
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}
.main img {
-webkit-user-select: none;
width: 25%;
-webkit-transition: transform .5s;
transform-origin: left;
z-index: 0;
vertical-align: top;
}
.main img:hover {
transform: scale(1.3, 1);
z-index: 1;
}
Don't fret. try this (quick IN, slow OUT):
.main img {
width: 25%;
height: 100%;
transition: width 2s ease;
}
.main img:hover {
width: 50%;
transition: width .5s ease;
}
Your Fiddle as I can see it only has one transition. If you're only changing the width, tell it to change the width, which has full browser support, rather than calling transform with all the attendant prefixes.
CSS doesn't distinguish between mouseover and mouseout, but this thread seems like it may have the answer to your question:
MouseOver and MouseOut In CSS
Edit: I just realized you said you have tried this. Javascript may be your only option.
Update your css with the below (add transition)
.main img {
-webkit-user-select: none;
width: 25%;
-webkit-transition: transform .5s;
transform-origin: left;
z-index: 0;
vertical-align: top;
transition:all 1s;
}
.main img:hover {
transform: scale(1.3, 1);
z-index: 1;
transition:all 1s;
}