How can ı resolve my nested div hover problem in css - html

#main_div {
background-color: #333;
margin-top: 5%;
border-radius: 10px;
box-shadow: 12px 12px 18px #000;
-moz-box-shadow: 12px 12px 18px #000;
-webkit-box-shadow: 12px 12px 18px #000;
border-left: 5px solid orange;
border-top: 5px solid orange;
height: 800px;
}
a {
background-color: orange !important;
}
a:hover {
border-left: 5px solid darkorange !important;
border-top: 5px solid darkorange !important;
transition: 0.4s;
-webkit-transform: scale(1.1);
-ms-transform: scale(1.1);
transform: scale(1.1);
}
<div id="main_div">
<a href"#">
<div><span>Hello World!</span></div>
</a>
</div>
I am trying to hover div. "a" is growing in hover position. But I have a problem As a grows, main_div grows with it. How do I prevent main_div from growing.

As commented above, try giving the border already some width and simply change its color on hover.
#main_div {
background: black;
padding: 1rem;
text-align: center;
}
a {
display: inline-block;
color: #fff;
border-top: 5px solid transparent;
border-left: 5px solid transparent;
padding: 1rem;
transition: all .3s ease;
}
a:hover {
transform: scale(1.1);
border-color: orange;
}
<div id="main_div">
<a href"#">
<div><span>Hello World!</span></div>
</a>
</div>

Related

Weird quick switching between normal and hover state CSS

I just created a custom styled button with an effect when hovering. However if you are unlucky and find a specific spot while hovering on the button it quickly switches between the normal and hover state.
My code:
button {
height: 34px;
padding: 0 16px;
border-radius: 4px;
margin: 8px;
border: none;
background: red;
color: #fff;
transition: background .2s, transform .2s;
outline: none;
cursor: pointer;
}
button:hover {
box-shadow: 4px 4px 0 0 blue;
transform: translate(-1px, -1px);
}
button:active {
background: green;
box-shadow: 2px 2px 0 0 blue;
}
<button>I am a button</button>
Code
Is there a trick to solve this issue?
The cause is the transform on hover. As soon as you stop hovering, the button goes back to place. If you've only moved one pixel away, you are now hovering the button again, which moves 1px away, and now is not hovered, and so on.
The best solution would be to remove the transform effect.
If you can't, a simple solution would be to add a transparent border around the button when it's hovered. You'll have to go another pixel to stop hovering the button, and when the hover stops you'll be outside of the new button position.
button {
height: 34px;
padding: 0 16px;
border-radius: 4px;
margin: 8px;
border: none;
background: red;
color: #fff;
transition: background .2s, transform .2s;
outline: none;
cursor: pointer;
}
button:hover {
box-shadow: 4px 4px 0 0 blue;
transform: translate(-1px, -1px);
border: 1px solid transparent;
}
button:active {
background: green;
box-shadow: 2px 2px 0 0 blue;
}
<button>I am a button</button>
A solution could be to add a container with a small padding, and check the hover on it instead of the button. Since it doesn't move, you shouldn't have the problem.
#buttonContainer {
display: inline-block;
padding: 2px;
}
button {
height: 34px;
padding: 0 16px;
border-radius: 4px;
margin: 8px;
border: none;
background: red;
color: #fff;
transition: background .2s, transform .2s;
outline: none;
cursor: pointer;
}
#buttonContainer:hover button{
box-shadow: 4px 4px 0 0 blue;
transform: translate(-1px, -1px);
}
button:active {
background: green;
box-shadow: 2px 2px 0 0 blue;
}
<div id="buttonContainer">
<button>I am a button</button>
</div>

Make custom tooltips compatible with changing widths

I have a custom tooltip code for my forum but due to its nature, I can't seem to make it compatible with different [tip] ranges.
See below for what I mean:
span.tooltip {
border-bottom: 1px dashed black;
}
span.tooltip span {
display: inline;
z-index: 10;
opacity: 0;
position: absolute;
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
margin-left: -100px;
margin-top: 27px;
-webkit-box-shadow: 1px 1px 7px transparent;
-moz-box-shadow: 1px 1px 7px transparent;
box-shadow: 1px 1px 7px transparent;
border: 1px solid #444;
}
span.tooltip:hover span {
display: inline;
opacity: 1;
position: absolute;
background: #f4f4f4;
}
span.tooltip>span:hover {
display: inline;
position: absolute;
border: 1px solid #444;
background: #f4f4f4;
}
span.tooltip>span {
max-width: 200px;
padding: 10px 12px;
opacity: 0;
visibility: hidden;
z-index: 10;
position: absolute;
font-size: 12px;
font-style: normal;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
-o-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: 1px 1px 7px #6B151F;
-moz-box-shadow: 1px 1px 7px #6B151F;
box-shadow: 1px 1px 7px #6B151F;
}
span.tooltip:hover>span {
opacity: 1;
text-decoration: none;
visibility: visible;
overflow: visible;
display: inline;
}
span.tooltip span>b:first-child {
width: 15px;
height: 15px;
margin-left: 20px;
margin-top: -19px;
display: block;
position: absolute;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-box-shadow: inset -1px 1px 0 #fff;
-moz-box-shadow: inset 0 1px 0 #fff;
-o-box-shadow: inset 0 1px 0 #fff;
box-shadow: inset 0 1px 0 #fff;
display: none0/;
*display: none;
background: #f4f4f4;
border-top: 1px solid #333;
border-right: 1px solid #333;
}
<span class="tooltip">works fine with long tips<span><b></b>parameter</span></span>
<br /><br />
<span class="tooltip">not<span><b></b>parameter</span></span> so much with shorter ones
<br /><br />
not even when it's <span class="tooltip">indented<span><b></b>parameter</span></span> into the paragraph
So uh... Yeah. I'm not sure how to make it compatible with smaller tips. Percent widths and using left do not work. I have already tried. Please don't suggest I use that unless you found a way how to make it work.
If it's not possible to make it work then that's all right, just lemme know.
There are a few problems with the tooltip you are using. First of all tooltips must be fluid and flexible, meaning they need to position themselves according to the element they are tipping. Also it's width should be decided by the ammount of text inside it. I have created a Tooltip javascript file that can help you accomplish that. But if you prefer fixing your current one you can do the following:
Add padding to your tooltip
span.tooltip span {/* all your previous code */
padding: 6px 10px; }
add a minimum width to your tooltip
min-width: 20px;
if you do decide to implement my tooltip library send me a message or comment on my post.

Center the button vertically and horizontally

I need to make sure that the 'Next' button below the video is centered vertically and horizontally within the block with the yellow background.
In addition, the 'click' effect on the button does not seem to work as intended. There is something causing a conflict here and I cannot figure out what.
When I only run the "next-video-button" and "next-video-button:active" CSS rules, everything works perfectly.
You may find my CSS and HTML below.
.course-video {
background: #f9c70f;
border: none;
margin: 0;
box-shadow: 0px 2px 4px rgba(0,0,0,0.3) inset;
-moz-box-shadow: 0px 2px 4px rgba(0,0,0,0.3) inset;
border-radius: 0;
-moz-border-radius: 0;
}
.next-video-button {
transition: all 0.1s;
-webkit-transition: all 0.1s;
padding: 7px 200px;
border-radius: 10px;
font-family: 'Montserrat';
font-size: 1em;
color: #ffffff;
text-decoration: none;
background-color: #888888;
border-bottom: 5px solid #5a5a5a;
text-shadow: 1px -2px #888888;
text-align: center;
}
.next-video-button:active {
transform: translate(0px,5px);
-webkit-transform: translate(0px,5px);
border-bottom: 1px solid;
}
.video-title {
font-family: montserrat;
font-size: 1.5em;
color: #000000;
padding: 0.5em;
box-sizing: border-box;
width: 854px;
text-shadow: 0px 2px 4px rgba(0,0,0,0.3);
}
.video-descr {
width: 854px;
box-sizing: border-box;
height: 50px;
margin-top: -5px;
}
<div class="course-video video-title">Hello</div>
<iframe src="https://player.vimeo.com/video/154094373" width="854" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<div class="course-video video-descr">NEXT</div>
To center the button give it a width and add margin: 0 auto and display: block; to .next-video-button.
The button won't work though because of a href="#". Replace the # with the video URL.

'Click' animation effect on button with CSS

I am not able to achieve the click-effect in my Next button (see snippet 1).
In the first snippet it is achievend with the float: left; value, but when I insert it into my code, it breaks the position of the button. My 'Next' button is supposed to be the way it is the second snippet, i.e. vertically and horizontally centered.
Any ideas how to find a workaround here?
Snippet 1
.next-button {
transition: all 0.1s;
-webkit-transition: all 0.1s;
position: relative;
padding: 10px 40px;
margin: 0px 10px 10px 0px;
float: left;
border-radius: 10px;
font-family: 'Montserrat';
font-size: 25px;
color: #ffffff;
text-decoration: none;
background-color: #f9c60f;
border-bottom: 5px solid #888888;
text-shadow: 1px -2px #888888;
}
.next-button:active {
transform: translate(0px,5px);
-webkit-transform: translate(0px,5px);
border-bottom: 1px solid;
}
<html lang="en">
<head>
<body>
NEXT
</body>
</html>
Snippet 2 (My code)
.next-button {
transition: all 0.1s;
-webkit-transition: all 0.1s;
position: relative;
padding: 10px 40px;
margin: 0px 10px 10px 0px;
float: left;
border-radius: 10px;
font-family: 'Montserrat';
font-size: 25px;
color: #ffffff;
text-decoration: none;
background-color: #f9c60f;
border-bottom: 5px solid #888888;
text-shadow: 1px -2px #888888;
}.course-video {
background: #f9c70f;
border: none;
margin: 0;
box-shadow: 0px 2px 4px rgba(0,0,0,0.3) inset;
-moz-box-shadow: 0px 2px 4px rgba(0,0,0,0.3) inset;
border-radius: 0;
-moz-border-radius: 0;
}
.next-video-button {
transition: all 0.1s;
-webkit-transition: all 0.1s;
padding:7px 200px;
border-radius: 10px;
font-family: 'Montserrat';
font-size: 1em;
color: #ffffff;
text-decoration: none;
background-color: #888888;
border-bottom: 5px solid #5a5a5a;
text-shadow: 1px -2px #888888;
text-align: center;
line-height:49px;
}
.next-video-button:active {
transform: translate(0px,5px);
-webkit-transform: translate(0px,5px);
border-bottom: 1px solid;
}
.video-title {
font-family: montserrat;
font-size: 1.5em;
color: #000000;
padding: 0.5em;
box-sizing: border-box;
width: 854px;
text-shadow: 0px 2px 4px rgba(0,0,0,0.3);
}
.video-descr {
width: 854px;
box-sizing: border-box;
height: 50px;
margin-top: -5px;
text-align:center;
}
.next-button:active {
transform: translate(0px,5px);
-webkit-transform: translate(0px,5px);
border-bottom: 1px solid;
}
<div class="course-video video-title">Hello</div>
<iframe src="https://player.vimeo.com/video/154094373" width="854" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<div class="course-video video-descr">NEXT</div>
Try using
.next-video-button {
display:inline-block;
...
}
instead of
float:left
Using inline-block makes the element act like it was text so your text-aligns will work on these as well

how does float left affect transform translate

If I remove the float:left attribute from .action-button the transform animation doesn't work. Can you explain what is happening here?
Markup:
Are
Styles:
.action-button
{
position: relative;
padding: 10px 40px;
margin: 0px 10px 10px 0px;
float: left;
border-radius: 8px;
font-family: 'Pacifico', cursive;
font-size: 25px;
color: #FFF;
text-decoration: none;
}
.green
{
background-color: #82BF56;
border-bottom: 5px solid #669644;
text-shadow: 0px -2px #669644;
}
.action-button:active
{
transform: translate(0px,5px);
-webkit-transform: translate(0px,5px);
border-bottom: 1px solid;
}
Codepen line 17: http://codepen.io/koriolis/pen/euAEg
This is because a elements are inline elements, in that they align the the parent element and do not clear either side.
When you add float: left, It changes the elements from being inline to block but also removes the clear: both and allows for elements to be aligned next to each other.
You can achieve the same effect as a float by using inline-block if you don't want the tags to float on the page.
.action-button {
position: relative;
padding: 10px 40px;
margin: 0px 10px 10px 0px;
display: inline-block;
border-radius: 8px;
font-family: 'Pacifico', cursive;
font-size: 25px;
color: #FFF;
text-decoration: none;
}
CodePen Example
tag a - default display: inline
float: left - display property is set to block
when you remove float: left - a again display: inline
use display: inline-block instead float: left
body {
padding: 50px;
}
.animate {
transition: all 0.1s;
-webkit-transition: all 0.1s;
}
.action-button {
position: relative;
padding: 10px 40px;
margin: 0px 10px 10px 0px;
display: inline-block;
border-radius: 8px;
font-family:'Pacifico', cursive;
font-size: 25px;
color: #FFF;
text-decoration: none;
}
.blue {
background-color: #3498DB;
border-bottom: 5px solid #2980B9;
text-shadow: 0px -2px #2980B9;
}
.red {
background-color: #E74C3C;
border-bottom: 5px solid #BD3E31;
text-shadow: 0px -2px #BD3E31;
}
.green {
background-color: #82BF56;
border-bottom: 5px solid #669644;
text-shadow: 0px -2px #669644;
}
.yellow {
background-color: #F2CF66;
border-bottom: 5px solid #D1B358;
text-shadow: 0px -2px #D1B358;
}
.action-button:active {
transform: translate(0px, 5px);
-webkit-transform: translate(0px, 5px);
border-bottom: 1px solid;
}
Hello
How
Are
You?
fiddle