Hover-State at bottom of element - html

I am currently developing a styleguide and the hover-state of my navigation is giving me some headache, but I am pretty sure, that it could be solved very easily, so I just want to ask, if someone has an idea.
My html looks like this:
<nav class='components__navigation'>
<a href='../index.html'><img class='styleguide__logo' src='../imgs/Logo.png' alt='Logo'></a>
<ul class='components__navListTop'>
<li class='components__navItem'><a href='#'>Design</a></li>
<li class='components__navItem' id='active'><a href='components.html'>Components</a></li>
<li class='components__navItem'><a href='#'>Motionguide</a></li>
</ul>
</nav>
and my css looks like this:
.components__navigation {
display: flex;
height: 75px;
align-items: center;
padding-left: 50px;
border-bottom: 4px solid #f5f5f5;
}
.components__navigation img {
width: 250px;
height: 40px;
margin-right: 100px;
}
.components__navListTop {
font-size: 14px;
display: flex;
list-style: none;
padding: 0;
}
.components__navListTop a {
color: #333;
text-decoration: none;
margin-right: 50px;
}
.components__navItem a {
text-decoration: none;
background-image: linear-gradient(#ffda00,#ffda00),linear-gradient(#fff,#fff);
background-size: 0 3px,auto;
background-repeat: no-repeat;
background-position: bottom;
transition: background .2s linear;
}
.components__navItem a:hover {
background-size: 100% 3px,auto;
}
#active a {
background-image: linear-gradient(#ffda00,#ffda00),linear-gradient(#fff,#fff);
background-size: 100% 3px,auto;
background-repeat: no-repeat;
background-position: bottom;
}
Here is a pen to make it more visual:
https://codepen.io/dbljn/pen/abbMdVE
The current hover-state is right under the font of the tabs, but I want the hover-state to be where the gray border is. Like so:
Do you have an idea? And thanks a lot!!

It is always a good practice to write similar styling rules when the elements are overlapping on each other.
for example, we could use the same background-image property with nav html element instead of border property
.components__navigation {
display: flex;
align-items: center;
padding-left: 50px;
background-image: linear-gradient(transparent 90%, #f5f5f5 0);
}
remove the margin from ul element and background-image from below selectors so that the nav element will spread on li element and will be dynamic
.components__navListTop {
font-size: 14px;
display: flex;
list-style: none;
padding: 0;
margin: 0;
}
.components__navListTop a {
color: #333;
text-decoration: none;
}
finally give the li element its background-image and other CSS rules,
.components__navItem {
padding: 20px 0;
margin-right: 50px;
background-image: linear-gradient(transparent 90%,#ffda00 0);
background-size: 0;
background-repeat: no-repeat;
background-position: bottom;
transition: background .2s linear;
}
Since you want the animation while hovering on li element, the :hover pseudo attribute should be present on this li element, also it's good to use classes instead of id
.components__navItem:hover, .active {
background-size: 100%;
}
Finally putting it all together,
body, html {
margin: 0;
}
.components__navigation {
display: flex;
align-items: center;
padding-left: 50px;
background-image: linear-gradient(transparent 90%, #f5f5f5 0);
}
.components__navigation img {
width: 250px;
height: 40px;
margin-right: 100px;
}
.components__navListTop {
font-size: 14px;
display: flex;
list-style: none;
padding: 0;
margin: 0;
}
.components__navListTop a {
color: #333;
text-decoration: none;
}
.components__navItem {
padding: 20px 0;
margin-right: 50px;
background-image: linear-gradient(transparent 90%,#ffda00 0);
background-size: 0;
background-repeat: no-repeat;
background-position: bottom;
transition: background .2s linear;
}
.components__navItem:hover, .active {
background-size: 100%;
}
<nav class='components__navigation'>
<a href='../index.html'><img class='styleguide__logo' src='../imgs/Logo.png' alt='Logo'></a>
<ul class='components__navListTop'>
<li class='components__navItem active'><a href='#'>Design</a></li>
<li class='components__navItem'><a href='components.html'>Components</a></li>
<li class='components__navItem'><a href='#'>Motionguide</a></li>
</ul>
</nav>

Try replacing .components__navItem a with:
.components__navItem a {
text-decoration: none;
background-image: linear-gradient(#ffda00,#ffda00);
background-size: 0 3px,auto;
background-repeat: no-repeat;
background-position: bottom;
transition: background .2s linear;
padding-bottom: 33px;
}
This is assuming a fixed font size though.

Related

Strange border on background-position animation

i trying to make background-position animation like this:
<div id="topAreaContainer">
<a href="http://www.google.co.il">
גכעגכע גע גכעגכע
</a>
</div>
body {
background: #000000;
direction: rtl;
}
#topAreaContainer {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 70px;
color: #ffffff;
width: 50%;
justify-content: center;
text-align: center;
}
#topAreaContainer a {
color: #ffffff;
text-decoration: none;
font-size: 1.5em;
background: transparent;
background: linear-gradient(to right, transparent 50%, #ffffff 50%);
background-size: 200% 100%;
background-position: left bottom;
transition: background-position 0.4s ease;
border: 3px solid #ffffff;
padding: 7px 25px;
margin: 0;
}
#topAreaContainer a:hover {
background-position: right bottom;
color: #78899c;
}
https://jsfiddle.net/Layfv2sj/
i tried to change the percent but nothing helped.
with english text its working fine.
what can i do?

How to eliminate animation flicker on button using css?

I created buttons that have a hover effect. The button fills from bottom to top with a background color white, and the text changes color. However, there is this weird line that appears at the bottom when the animation takes place. Any help would be greatly appreciated.
.project-button div {
position: relative;
display: inline-block;
padding: 1rem;
margin: 0 1rem 1rem 1rem;
font-size: 1rem;
font-weight: 700;
border: 1px solid white;
border-radius: 15px;
background-repeat: no-repeat;
transition: background-size .5s, color .5s;
}
.to-top {
background-position: 50% 100%;
background-size: 100% 0%;
}
.project-button a {
color: white;
}
.project-button div:hover {
background-size: 100% 100%;
background-image: linear-gradient(white, white);
}
.color-blue:hover {
color: #51d0de;
}
/* Misc */
html {
background: black;
margin: 1em;
}
<div class="project-button">
<div class="to-top color-blue">Visit Site</div>
</div>
Try the following:
I think the problem has to do with how Chrome computes the animation. At times (depending on the frame) the white background is just a bit too small to fill the button revealing the black background (hence the flicker).
.project-button div {
position: relative;
display: inline-block;
padding: 1rem;
margin: 0 1rem 1rem 1rem;
font-size: 1rem;
font-weight: 700;
border: 1px solid white;
border-radius: 15px;
background-image: linear-gradient(white, white);
background-repeat: no-repeat;
background-position: 0 -100%;
background-size: 100% 200%;
transition: background-position .5s, color .5s;
}
.project-button a {
color: white;
}
.project-button div:hover {
background-position: 0% 0%;
}
.color-blue:hover {
color: #51d0de;
}
/* Misc */
html {
background: black;
margin: 1em;
}
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<div class="project-button">
<div class="color-blue">Visit Site</div>
</div>
</body>
</html>
Inspired by Transition background-color via slide up animation

Link within content, background fill left to right, and then right to left so it looks like the box is sliding right through

I am trying to carry out an animation on links, the background should fill from left to right, and then the background should reverse and go from right to left. I have created a Pen for the first part:
p {
color: #000;
}
a {
background: linear-gradient(to right, #903e77 50%, transparent 50%);
background-size: 200% 100%;
background-position: right bottom;
color: #000;
text-decoration: none;
}
a:hover {
background-position: left bottom;
transition: background 250ms ease-in-out;
}
<p>This is a sentence with a link in the middle.</p>
I am thinking this needs a span element or something inside to act as another background block.
The effect would be similar to links here:
https://ueno.co/contact
In the footer is most noticeable.
You can adjust it like this:
p {
color: #000;
font-size: 40px;
}
a {
background: linear-gradient(#903e77, #903e77);
background-size: 200% 100%;
background-position: 200% 0;
background-repeat: no-repeat;
color: #000;
text-decoration: none;
}
a:hover {
background-position: -100% 0;
transition: background 0.5s ease-in-out;
}
<p>This is a sentence with a link in the middle.</p>
Or like this:
p {
color: #000;
font-size: 40px;
}
a {
background: linear-gradient(#903e77, #903e77);
background-size: 0 100%;
background-position: left;
background-repeat: no-repeat;
color: #000;
text-decoration: none;
transition: background-size 0.5s,background-position 0s 0.5s;
}
a:hover {
background-size:100% 100%;
background-position:right;
}
<p>This is a sentence with a link in the middle.</p>
Also like this:
p {
color: #000;
font-size: 40px;
}
a {
background: linear-gradient(#903e77, #903e77);
background-size: 200% 100%;
background-position: 200% 0;
background-repeat: no-repeat;
color: #000;
text-decoration: none;
transition:background-position 0.5s;
}
a:hover {
background-position: -100% 0;
}
<p>This is a sentence with a link in the middle.</p>
You could use a positioned pseudo-element on the link and manipulate the position of that with a transform
p {
color: #000;
font-size: 2em;
}
a {
display: inline-block;
overflow: hidden;
position: relative;
vertical-align: bottom;
}
a:before {
content: "";
width: 100%;
position: absolute;
left: 0;
height: 100%;
background: pink;
z-index: -1;
transform: translateX(-100%);
transition: transform 1s;
}
a:hover:before {
transform: translateX(100%);
}
<p>This is a sentence with a link in the middle.</p>

My ID is not being applied

I am working on a project and I basically copied and pasted some code I had made before that I know worked. The only difference is that now, the index.html and index.css is in a different folder. The CSS is being applied but the ID's at the bottom are not for some reason. Still, if you preview it on this website, it is completely fine.
/*
font-family: 'Dosis', sans-serif;
font-family: 'Chewy', cursive;
HEX: #fff2df
HEX: #d9ad7c
HEX: #a2836e
HEX: #674d3c
*/
body {
font-family: 'Dosis', sans-serif;
background: #fff2df;
}
/* Matan's Website */
h1 {
font-family: 'Chewy', cursive;
font-size: 65px;
text-align: center;
}
/* Line */
hr {
width: 600px;
border-style: solid;
margin-top: -15px;
}
/* All Boxes */
ul {
overflow: hidden;
text-align: center;
}
li {
float: center;
text-align: center;
display: inline-block;
}
a {
background-color: #000;
border-radius: 20px;
z-index: 100;
}
.buttons {
list-style-type: none;
margin: 0;
padding: 0;
text-align: center;
width: 100%;
}
.links {
font-size: 37.5px;
text-decoration: none;
display: inline-block;
text-align: center;
}
/* Individual Boxes */
#word {
background-image: url('Pictures/word.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
padding: 162.75px 119.25px;
margin: 65px 75px 0px 0px;
color: #fff;
transition: all 0.5s ease-out;
}
#word:hover {
padding: 189.875px 139.125px;
transition: all 0.5s ease-out;
opacity: 0.8;
margin-right: 63.4px;
margin-left: -28.125px;
margin-top: 37.875px;
}
#pwpoint {
background-image: url('Pictures/powerpoint.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
padding: 162.75px 69.75px;
margin: 65px 75px 0px 0px;
color: #fff;
transition: all 0.5s ease-out;
}
#pwpoint:hover {
padding: 189.875px 81.375px;
transition: all 0.5s ease-out;
opacity: 0.8;
margin-right: 63.275px;
margin-left: -11.5px;
margin-top: 37.875px;
}
#ptshop {
background-image: url('../Pictures/photoshop.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
padding: 162.75px 99px;
margin: 65px 0px 0px 0px;
color: #fff;
transition: all 0.5s ease-out;
}
#ptshop:hover {
padding: 189.875px 115.5px;
transition: all 0.5s ease-out;
opacity: 0.8;
margin-right: -28.125px;
margin-left: -4.9px;
margin-top: 37.875px;
}
<!DOCTYPE html>
<html>
<head>
<title>Portfolio</title>
<link rel="stylesheet" type="text/css" href="../index.css">
<link href="https://fonts.googleapis.com/css?family=Chewy|Dosis" rel="stylesheet">
</head>
<body>
<h1>My Portfolio</h1>
<hr>
<div class="allbuttons">
<ul class="buttons">
<li><a class="links" id="word" href="Word/index.html">Word</a></li>
<li><a class="links" id="pwpoint" href="Powerpoint/index.html">Powerpoint</a></li>
<li><a class="links" id="ptshop" href="Photoshop/index.html">Photoshop</a></li>
<li><a class="links" id="other" href="Other/index.html">Other</a></li>
</ul>
</div>
</body>
</html>
None of the IDs work, but the CSS file is linked correctly and displayed correctly. Any ideas why this might be?
"Eliminate all other factors, and the one which remains must be the truth."
As Sherlock Holmes frequently pointed out, when searching for the truth (in this case, a solution) we must first eliminate the clutter.
Relative vs. Absolute URLs are convenient when accurate, but prone to error for a variety of reasons.
A tidy workspace is invaluable; when coding any project, create and maintain a controlled and suitable space to help with avoiding and diagnosing problems that might crop up.
...
Other mildly patronising platitudes are available on request ;-)

How to hide text in menu on hover and put image with underline instead?

I want to make menu on top, and on hover mouse to hide text and display icon. And to add underline under icon.In my code i successfully change text to image but how to add underline under image and make underline 3px wight and 60px length?
There is my code- HTML:
<div class="menu topMenu">
<ul class="topMenuOptions">
<li><span>111</span></li>
<li><span>222</span></li>
<li><span>333</span></li>
</ul>
CSS:
.topMenu {
text-transform: uppercase;
background-image: url('images/1.png');
position: absolute;
height: 88px;
width: 400px;
background: lightcoral;
margin-left: 332px;
padding-top: 30px;
}
.topMenuOptions {
padding: 0;
margin: 0;
margin-left: 155px;
list-style-type: none;
}
.topMenuOptions li {
cursor: pointer;
padding: 10px;
color: white;
font-size: 14px;
display: inline;
}
.topMenuOptions li:hover:nth-child(1) {
background: url('images/2.png') center center no-repeat;
background-position: 20px 0;
background-size: contain;
color:transparent;
}
.topMenuOptions li:hover:nth-child(2) {
background: url('images/3.png') center center no-repeat;
background-size: contain;
background-position: 20px 0;
color: transparent;
}
.topMenuOptions li:hover:nth-child(3) {
background: url('images/4.png') center center no-repeat;
background-size: contain;
background-position: 20px 0;
color: transparent;
}
Use border-bottom: 3px solid white;, for example:
.topMenuOptions li:hover:nth-child(1) {
background: url('images/2.png') center center no-repeat;
background-position: 20px 0;
background-size: contain;
color:transparent;
border-bottom: 3px solid #fff;
}
As per your requirement, I made a fiddle which you can check.
for the underline, you can keep border-bottom of 3px with border-color initially as transparent. this transparent color is required by default to avoid the jerking of the text when a border is added on hover.
I have modified your code a bit just for your understanding.
.topMenu {
text-transform: uppercase;
background-image: url('images/1.png');
position: absolute;
height: 88px;
width: 400px;
background: lightcoral;
/* margin-left: 332px; */
padding-top: 30px;
}
.topMenuOptions {
padding: 0;
margin: 0;
margin-left: 155px;
list-style-type: none;
}
.topMenuOptions li {
cursor: pointer;
padding: 10px;
color: white;
font-size: 14px;
display: inline;
border-bottom: 3px solid transparent;
}
.topMenuOptions li:hover:nth-child(1) {
background: url('http://php.quicoto.com/wp-content/uploads/2013/06/css3.jpg') center center no-repeat;
background-position: 0px 0;
background-size: contain;
color: transparent;
border-bottom: 3px solid #fff;
}
.topMenuOptions li:hover:nth-child(2) {
background: url('http://php.quicoto.com/wp-content/uploads/2013/06/css3.jpg') center center no-repeat;
background-size: contain;
background-position: 0px 0;
color: transparent;
border-bottom: 3px solid #fff;
}
.topMenuOptions li:hover:nth-child(3) {
background: url('http://php.quicoto.com/wp-content/uploads/2013/06/css3.jpg') center center no-repeat;
background-size: contain;
background-position: 0px 0;
color: transparent;
border-bottom: 3px solid #fff;
}
<div class="menu topMenu">
<ul class="topMenuOptions">
<li><span>111</span></li>
<li><span>222</span></li>
<li><span>333</span></li>
</ul>
JSFIDDLE
`<ul>
<li class="option">
<span id="text">111</span>
<span id="image" class="hide">IMAGE</span>
</li>
<li class="option">
<span id="text">222</span>
<span id="image" class="hide">IMAGE</span>
</li>
</ul>`
.option:hover .option > #image
{
display:block;
border-bottom:1px solid black;
}
.option:hover: .option > #text
{
display:none;
}
.hide
{
display:none;
}
you can do something like this, which is more efficient,
inside the image span you can add a image tag, which will also do the job.