Burger Toggle only One Bar Changes on Hover - html

I'm currently working on a navbar for what's going to be my website, but I'm having problems with the toggle burger icon.
I would like for to have all three bars of the toggle button to change at the same time while hovering over it, but only of them changes at a time when I hover over it.
Relevant Code
HTML
<div class='toggle-button' onClick={() => setOpen(!open)}>
<div class='bar' />
<div class='bar' />
<div class='bar' />
</div>
CSS
.toggle-button {
border: 1px solid grey;
border-radius: 5px;
cursor: pointer;
display: inline-block;
height: fit-content;
transition: all 0.5s ease;
}
.toggle-button:hover {
background-color: black;
}
.toggle-button .bar {
background-color: grey;
border-radius: 2.5px;
margin: 4px;
height: 4px;
width: 25px;
}
.toggle-button .bar:hover {
background-color: black;
}

That's because the selector you used is used for inheritance.
That, and your :hover should be on the .toggle-button class, otherwise the style will change when you hover on the bar and not the full div.
Original:
.toggle-button .bar:hover {
background-color: black;
}
What you need:
.toggle-button:hover > .bar {
background-color: gray;
}
Also, I changed the color to gray so the bars won't blend with the rest of the button.
If you need more information I'm happy to explain.

If I understand correctly what you are trying to accomplish is to change to color of the 3 lines .bar on hover.
You will need to do it as follows:
.toggle-button {
border: 1px solid grey;
border-radius: 5px;
cursor: pointer;
display: inline-block;
height: fit-content;
transition: all 0.5s ease;
}
.toggle-button .bar {
background-color: grey;
border-radius: 2.5px;
margin: 4px;
height: 4px;
width: 25px;
}
.toggle-button:hover .bar {
background-color: black;
}

Related

Button Hover and Active Click Not Working

I know this questions has been asked a dozen times, but I can't seem to get my button to have a hover and pressed effect. I am trying to have the color of my button change when I hover over it. I would also like the button to have an active pressed effect when clicked. I feel like it has something to do with my css linkage, but I have tried a bunch of different combinations and still can't get it to work.
HTML
<a href="#">
<button>Click for Plans</button>
</a>
css
button {
background-color: #3AF8AB;
border-style: none;
color: white;
position: absolute;
border-radius: 10px;
font-size: 3.5vmin;
margin-top: 0px;
font-weight: bold;
padding: 7px;
margin-left: 73%;
margin-right: 1%;
cursor: pointer;
}
.button:hover {
background-color: blue;
transition: 0.7s;
}
.button:active {
background-color: blue;
box-shadow: 0 5px #666;
transform: translatey(4px);
}
button:hover and button:active in css are class and you have element. You can add the class button to your button or change the style to button ( and not .button )
button {
background-color: #3AF8AB;
border-style: none;
color: white;
position: absolute;
border-radius: 10px;
font-size: 3.5vmin;
margin-top: 0px;
font-weight: bold;
padding: 7px;
margin-left: 73%;
margin-right: 1%;
cursor: pointer;
}
button:hover {
background-color: blue;
transition: 0.7s;
}
button:active {
background-color: blue;
box-shadow: 0 5px #666;
transform: translatey(4px);
}
<button>Click for Plans</button>

Why is the border funky when a radius is applied?

I was messing around in HTML when I saw this small bug
I made this button using SCSS and gave it a border radius of 5px. If you're able to notice, there's a small curve where the border raidus is supposed to be.
Close up:
Why is this happening?
Code
/* Button.scss file */
#import "../../util/variables";
button {
background-color: white;
color: black;
outline: none;
border: 1px currentColor solid;
padding: 0.3rem 0.85rem;
border-radius: $border-radius;
&:hover {
cursor: pointer;
}
&.primary {
background-color: $primary;
color: $primary-text;
}
&.secondary {
background-color: $secondary;
color: $secondary-text;
}
&.block {
display: block;
width: 100%;
margin-bottom: 0.5rem;
}
}
<!-- HTML -->
<button
class="button"
>
Login
</button>
EDIT:
$primary is #283593
I use firefox
button {
background-color: white;
color: black;
outline: none;
border: 1px currentColor solid;
padding: 0.3rem 0.85rem;
border-radius: 5px;
}
button:hover {
cursor: pointer;
}
button.primary {
background-color: #283593;
color: white;
}
button.block {
display: block;
width: 100%;
margin-bottom: 0.5rem;
}
<button class="button primary">Login</button>
This is an artifact caused by the imprecision of fractional numbers used in the rendering. You can expect it to vary depending on browser, and perhaps even GPU and rendering mode.
See also: Is floating point math broken?

How do I make a border for <div>'s and <img>'s? [duplicate]

This question already has answers here:
HTML Div border not showing
(3 answers)
Closed 2 years ago.
I want to add borders for images and my top-nav and here is my code I have tried
.navtop {
background: #b7f582;
width: 100%;
height: 100px;
overflow: hidden;
}
.navtop a {
width: auto;
min-width: 90px;
text-align: center;
text-decoration: none;
height: 100px;
-webkit-transition: 0.5s;
background: #82a8f5;
float: left;
}
.navtop a:hover {
transition: 0.5s;
transform: translateY(10px);
background: #d96cbc;
color: black;
}
.navtop img {
float: left;
width: 100px;
height: 100px;
border-color: black;
border-width: 5px;
}
<div class="navtop">
<img src="RingLogo.png">
Home
</div>
How can I add a border color to a <div> area and and image? See, I can add a border onto buttons but not anything else.
Use the border in one statement for simplicity because you are missing the border-style:
border: 5px solid black;
You can check for other border-styles and other options via this link.
You haven't specified the border-style, that's why it's not working. Either add border-style: solid or use the shorthand to define all 3 properties (border-width, border-style and border-color) in a single line: border: 5px solid black.
The reason why defining only border-width and border-color is working on <button>s is that browsers apply some default styles, so buttons already have a border-style defined, as shown below:
console.log(window.getComputedStyle(document.getElementById('defaultButton')).borderStyle);
.navtop {
background: #b7f582;
height: 100px;
overflow: hidden;
border: 5px solid green;
}
.navtop a {
width: auto;
min-width: 90px;
text-align: center;
text-decoration: none;
height: 100px;
-webkit-transition: 0.5s;
background: #82a8f5;
float: left;
}
.navtop a:hover {
transition: 0.5s;
transform: translateY(10px);
background: #d96cbc;
color: black;
}
.navtop img {
float: left;
width: 100px;
height: 100px;
border: 5px solid black;
box-sizing: border-box;
}
#styledButton {
border-color: red;
border-width: 5px;
}
<div class="navtop">
<img src="RingLogo.png">
Home
<button id="defaultButton">Foo</button>
<button id="styledButton">Bar</button>
</div>
you can do something like this also close the </div>, div is not self closing element.
.navtop {
background: #b7f582;
width: 100%;
height: 110px;
overflow: hidden;
border:5px solid red;
}
.navtop a {
width: auto;
min-width: 90px;
text-align: center;
text-decoration: none;
height: 100px;
-webkit-transition: 0.5s;
background: #82a8f5;
float: left;
}
.navtop a:hover {
transition: 0.5s;
transform: translateY(10px);
background: #d96cbc;
color: black;
}
.navtop img {
float: left;
width: 100px;
height: 100px;
border: 5px solid blue;
}
<style>
</style>
<div class="navtop">
<img src="http://placekitten.com/301/301">
Home
</div>

CSS: Why menu border doesn't appear when the scroll bar appears?

LIVE DEMO
Consider the following menu example: (note the red border)
<div class="menu-wrapper">
<div class="menu-item">Hello</div>
<div class="menu-item">Stack</div>
<div class="menu-item">Overflow</div>
</div>
.menu-wrapper {
display: flex;
flex-direction: column;
width: 200px;
background-color: #ccc;
border-left: 5px solid #bbb;
height: 300px;
}
.menu-item {
padding: 20px;
cursor: pointer;
}
.menu-item:hover {
margin-left: -5px;
background-color: #444;
color: #fff;
border-left: 5px solid red;
}
Now, imagine that the height of menu-wrapper is small, and we want the vertical scroll bar to appear. For example, we could replace:
height: 300px;
with:
height: 100px;
overflow-y: auto;
But, the red border disappears then:
Why is that? How would you fix that?
PLAYGROUND HERE
Since overflow hides what overflows, you may instead draw the border on the background or with an inset shadow , so it is drawn on the whole height of cntainer : DEMO
.menu-wrapper {
display: flex;
flex-direction: column;
width: 200px;
background-color: #ccc;
box-shadow: inset 5px 0 #bbb;/* here draws an inside left border via shadow */
height: 300px;
height: 100px;
overflow:auto;
}
.menu-item {
padding: 20px;
cursor: pointer;
}
.menu-item:hover {
background-color: #444;
color: #fff;
border-left: 5px solid red;
}
I think this works:
The problem is that the red border of menu-item is hiding behind the grey border of the menu-wrapper. So, I removed the border from the wrapper and put it in the item, like this:
.menu-wrapper {
...
/* border-left: 5px solid #bbb; No longer needed */
height: 100px;
overflow-y: auto;
}
.menu-item {
padding: 20px;
cursor: pointer;
border-left: 5px solid #bbb; /* Add border to menu-item rather than the wrapper */
}
.menu-item:hover {
/* margin-left: -5px; No longer needed*/
background-color: #444;
color: #fff;
border-left: 5px solid red;
}
Note: The grey border of the menu-wrapper doesn't take the full height anymore. You could use box-shadow on the wrapper (as answered by GCyrillus) to fix this.
You could integrate both the solutions, so the design won't look too bad in older browsers where box-shadow isn't supported.
.menu-wrapper {
...
box-shadow: inset 5px 0 #bbb;
}

CSS3: Change shape of button on hover

I created a button:
http://jsfiddle.net/fy2zG/#&togetherjs=xaJ1VA8PBN
My css so far is:
.button {
padding: 5px 20px;
background: orange;
position: relative;
float:left;
text-align: center;
border-radius: 10px;
text-decoration: none;
color: white;
}
My goal is to have (only) the right side of the button turning to an arrow peak on hover. The result should be something similar like this:
When hovering out, the button shall transit to its original shape.
Is this something that can be achieved with CSS or is jQuery needed?
Working example
jsfiddle
EDIT, now with transition
jsfiddle
EDIT, now with transition on mouseout
jsfiddle
HTML
login
CSS
.button {
padding: 5px 20px;
background: orange;
position: relative;
float:left;
text-align: center;
border-radius: 10px;
text-decoration: none;
color: white;
position:relative;
}
.button:after {
content: " ";
border: solid transparent;
border-width: 0;
border-left-color: orange;
position: absolute;
-webkit-transition: all 1s ease;
left: 100%;
top: 50%;
}
.button:hover:after {
content: " ";
display:block;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(0, 0, 0, 0);
border-left-color: orange;
border-width: 25px;
margin-top: -25px;
margin-left: -10px;
}
Can't make that with css or jQuery (unless i don't know some plugin).
Basically you must have two images. One for normal button, one for arrow shaped button. And onNover just change background image using background transition. But i think it will look ugly.