div Hover Issue when reaches border - html

I want hover effect on div, I have applied bottom style when hover on div and everything is working but when hover border/edge of the div means the div jerking/jumping continuously.
my code :
.traning-box {
background: #fff;
padding-top: 70px;
padding-bottom: 30px;
box-shadow: 0 0 35px 5px rgba(0, 0, 0, .07);
border-radius: 5px;
width: 120px;
text-align: center;
}
.traning-box:hover {
bottom: 15px;
position: relative;
}
<div class="traning-box">
<p> Test box</p>
</div>

Try to use :after pseudo-element. When the .traning-box goes up, the :after goes down, so the cursor will still over the .traning-box (because it is a parent block for the :after).
.traning-box {
background: #fff;
border-radius: 5px;
box-shadow: 0 0 35px 5px rgba(0, 0, 0, .07);
padding-top: 70px;
padding-bottom: 30px;
position: relative;
text-align: center;
width: 120px;
}
.traning-box:after {
bottom: 0;
display: block;
content: '';
height: 15px;
left: 0;
position: absolute;
width: 100%;
}
.traning-box:hover {
margin-top: -15px;
}
.traning-box:hover:after {
bottom: -15px;
}
<div class="traning-box">
<p>Test box</p>
</div>

You could use animation to achieve it.
.traning-box {
background: #fff;
padding-top: 70px;
padding-bottom: 30px;
box-shadow: 0 0 35px 5px rgba(0, 0, 0, .07);
border-radius: 5px;
width: 120px;
text-align: center;
margin:20px;
position:relative;
}
.traning-box:hover {
animation-name:move;
animation-duration:1s;
animation-iteration-count:1;
animation-timing-function: ease;
position: relative;
border:1px solid red;
}
#keyframes move{
50%{
transform:translateY(-15px);
}
}
<div class="traning-box">
<p> Test box</p>
</div>

You need to use transition and translate together to achieve smooth hover effect.
.traning-box {
background: #fff;
padding-top: 70px;
padding-bottom: 30px;
box-shadow: 0 0 35px 5px rgba(0, 0, 0, .07);
border-radius: 5px;
width: 120px;
text-align: center;
transition: all 0.5s linear;
}
.traning-box:hover {
transform: translateY(-15px);
position: relative;
}
<div class="traning-box">
<p> Test box</p>
</div>

Try below. You have to use inner div to write a hover effect.
.traning-box{
background: #fff;
padding-top: 70px;
padding-bottom: 30px;
box-shadow: 0 0 35px 5px rgba(0, 0, 0, .07);
border-radius: 5px;
width: 120px;
text-align: center;
}
.traning-box1 {width:120px;}
.traning-box1:hover .traning-box{
bottom: 15px;
position: relative;
}
<br/>
<br/>
<div class="traning-box1">
<div class="traning-box">
<p> Test box</p>
</div>
</div>

Related

Element opacity stuck because of psuedoelement

I'm trying to build a "block" on a website that contains a background image with lowered opacity, some text with regular opacity and a button with regular opacity
Currently, I'm getting the background image and text to work, but the button is stuck on the image's opacity (blends in with the background).
Here is the html:
h1,p {
text-align: center;
position:relative;
top:-70px;
position: relative;
color: navy;
}
.box1 {
width: 97.5%;
background-color: white;
position: relative;
padding-top: 200px;
padding-bottom: 200px;
padding-left: 30px;
padding-right: 30px;
margin-top: 20px;
margin-bottom: 10px;
margin-right: 1.25%;
margin-left: 1.25%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.box1::before {
content: "";
background-image: url(/static/background.jpeg);
background-size: contain;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
position: absolute;
opacity: 0.5;
}
.click {
color:rgba(0, 0, 0, 0.19)
}
<div class="box1">
<h1>Our Mission</h1>
<p>THe organization plans to complete tasks x, y, z</p>
<button class="click">Learn More</button>
</div>
Add position: relative to your .click class.
Side note: You have a duplicate position: relative in your h1, p selector.

CSS Position 2 buttons inline-block in center of screen, while keeping hover behavior [duplicate]

This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
How can I vertically center a div element for all browsers using CSS?
(48 answers)
How can I vertically align elements in a div?
(28 answers)
Closed 2 years ago.
I have been playing around with css for a bit trying many different methods with no success. I came really close with the code below, except the hover doesn't work anymore. Guessing it has overlapping elements? So, I would like 2 buttons next to each other but also center of screen regardless of screen size - and they also need to be hoverable. Here is the closest I could get...
.standardButton{
font-family: "Roboto", sans-serif;
text-transform: uppercase;
outline: 0;
border-radius: 5px;
background: #4CAF50;
margin-top: -5px;
width: 90%;
height: 50px;
border: 0;
color: #FFFFFF;
font-size: 14px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;
}
.standardButton:hover,.standardButton:active,.standardButton:focus {
background: #43A047;
}
.buttonBackground2{
height: 15px;
width: 110px;
border-radius: 5px;
background: #FFFFFF;
max-width: 360px;
margin: 0 auto 100px;
padding-bottom: 35px;
padding-left: 0px;
padding-right: 0px;
padding-top: 10px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.positionLogoutButton{
display: inline-block;
margin: 10px;
}
.positionAddDeviceButton{
display: inline-block;
margin: 10px;
}
.centerEverything{
display: flex;
justify-content: center;
}
<div class="centerEverything">
<div class="positionLogoutButton">
<div class="buttonBackground2">
<button class="standardButton" onClick={handleLogout}>Logout</button>
</div>
</div>
<div class="positionAddDeviceButton">
<div class="buttonBackground2">
<button class="standardButton" onClick={handleAddDevice}>Add Device</button>
</div>
</div>
</div>
Using flexbox basic properties on container element this is achieved easily: (Have removed un-necessary CSS like margin: 0 auto 100px; This is not needed )
.standardButton{
font-family: "Roboto", sans-serif;
text-transform: uppercase;
outline: 0;
border-radius: 5px;
background: #4CAF50;
margin-top: -5px;
width: 90%;
height: 50px;
border: 0;
color: #FFFFFF;
font-size: 14px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;
}
.standardButton:hover,.standardButton:active,.standardButton:focus {
background: #43A047;
}
.buttonBackground2{
height: 15px;
width: 110px;
border-radius: 5px;
background: #FFFFFF;
max-width: 360px;
/* margin: 0 auto 100px; This is not needed */
padding-bottom: 35px;
padding-left: 0px;
padding-right: 0px;
padding-top: 10px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.positionLogoutButton{
display: inline-block;
margin: 10px;
}
.positionAddDeviceButton{
display: inline-block;
margin: 10px;
}
.centerEverything{
display: flex;
justify-content: center;
height:100vh;
align-items:center;
}
<div class="centerEverything">
<div class="positionLogoutButton">
<div class="buttonBackground2">
<button class="standardButton" onClick={handleLogout}>Logout</button>
</div>
</div>
<div class="positionAddDeviceButton">
<div class="buttonBackground2">
<button class="standardButton" onClick={handleAddDevice}>Add Device</button>
</div>
</div>
</div>
You can position it vertically and horizontally using the the following code snippet on .centerEverything.
.centerEverything{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
I have added a parent container with a class .someContainer to show you an example with a black background.
Also I removed margin: 0 auto 100px; from the buttons as this is adding unnecessary height to the button.
.standardButton{
font-family: "Roboto", sans-serif;
text-transform: uppercase;
outline: 0;
border-radius: 5px;
background: #4CAF50;
margin-top: -5px;
width: 90%;
height: 50px;
border: 0;
color: #FFFFFF;
font-size: 14px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;
}
.standardButton:hover,.standardButton:active,.standardButton:focus {
background: #43A047;
}
.buttonBackground2{
height: 15px;
width: 110px;
border-radius: 5px;
background: #FFFFFF;
max-width: 360px;
padding-bottom: 35px;
padding-left: 0px;
padding-right: 0px;
padding-top: 10px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.positionLogoutButton{
display: inline-block;
margin: 10px;
}
.positionAddDeviceButton{
display: inline-block;
margin: 10px;
}
.centerEverything{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.someContainer {
position: relative;
background-color: black;
height: 300px;
}
<div class="someContainer">
<div class="centerEverything">
<div class="positionLogoutButton">
<div class="buttonBackground2">
<button class="standardButton" onClick={handleLogout}>Logout</button>
</div>
</div>
<div class="positionAddDeviceButton">
<div class="buttonBackground2">
<button class="standardButton" onClick={handleAddDevice}>Add Device</button>
</div>
</div>
</div>
</div>

Modal-Overlay issue

First of all excuse me for explanation if I am not up to the mark, as this is my first post in this platform, Well, I am working on overlay where it has to be shown in right side of the page with given width of say 416px and 100vh of height, but things are getting cut if I do decrease the browser window and as I am decreasing the size of the browser window the button at bottom start appearing on content of overlay which has to remain at bottom even the height is getting decreased, here is the my code as below:
.advanced-overlay {
width: 100%;
min-height: 100vh;
background-color: rgba(35, 0, 18, 0.5);
position: fixed;
z-index: 100002;
top: -41px;
left: 0;
bottom: 0;
.advance-overlay-footer {
display:flex;
justify-content: space-between;
align-items:center;
position: fixed;
right: 24px;
width:156px;
bottom: 24px;
height:6%;
}
.advanced-overlay-content {
position: relative;
// min-height: 83vh;
width: 416px;
margin-top: 108px;
margin-left: auto;
margin-right: 6px;
opacity: 1;
z-index: 100004;
border-radius: 16px 16px 16px 16px;
background-color: #f5f4f6;
box-shadow: 0 2px 30px 0 rgba(0, 0, 0, 0.07),
0 19px 18px 0 rgba(0, 0, 0, 0.05), 0 8px 12px 0 rgba(0, 0, 0, 0.05),
0 1px 5px 0 rgba(0, 0, 0, 0.04), 0 0 2px 0 rgba(0, 0, 0, 0.03);
.close-advance-overlay {
position: absolute;
background-color: #fff;
width: 110px;
height: 40px;
display: flex;
border-radius: 20px;
padding: 5px 22px;
top: -18px;
right: 155px;
opacity: 1;
cursor: pointer;
img {
height: 20px;
width: 20px;
align-self: center;
}
.button-text {
align-self: center;
margin-left: 5px;
font-weight: 600;
font-size: 16px;
color: #000000;
}
}
.advnaced-overlay-content-secion {
//min-height:89vh;
width: 100%;
bottom:10%;
// height:100vh;
.select-box {
margin-top: 40px;
margin-bottom: 40px;
}
.accordinan-filter {
margin-bottom: 24px;
}
.accordian-title {
font-weight: 900;
}
.accordian-content {
margin: 0;
font-size: 16px;
}
}
}
}
.is-maximum {
height: 73vh;
overflow-y: auto;
overflow-x: hidden;
&::-webkit-scrollbar {
width: 4px;
background-color: #fff;
}
&::-webkit-scrollbar-thumb {
border-radius: 3px;
background-color: #d3d3d3;
}
}
<div class="advanced-overlay" v-if="toggleFilter">
<div class="advanced-overlay-content">
<div class="close-advance-overlay" #click="toggleAdvanceFilterOverlay">
<img class src="../assets/icons/close.svg" />
<span class="button-text">Close</span>
</div>
<div class="advnaced-overlay-content-secion is-maximum">
<div class="select-box"></div>
<div class="accordinan-filter"></div>
</div>
<div class="advance-overlay-footer">...two buttons</div>
</div>
</div>
So, I what I would like to achieve eventually is that, I want respsonsive overlay at right side of the browser window, provided if I am decreasing height of the browser the buttons at bottom should stay there (fixed position) and content should be within limit of .advnaced-overlay-content-secion
for a responsive design I recommend you to read into the use of grid and espacially for mobile designs also the use of #media breakpoints.
for having some thing to stick at the bottom simply use:
position: fixed;
bottom: 0;

how can I vertically align a google icon within a button? (ie11)

I have trouble with vertical alignment of some google icons inside buttons. I tried to play with padding and margin but I could not fix the issue.
This is a screenshot of the problem: as you can see the icon are placed slightly higher:
This is part of the html, each button is more or less the same:
<div id="mainToolbar">
<button id="buttonPencil" data-tool="yes" data-type="draw" title="Use pencil" class="button" onclick="changeTool(0);">
<i class="material-icons">brush</i>
</button>
</div>
This is the css for the button:
.button {
margin: auto;
display: inline-block;
margin-top: 5px;
color: black;
border: 0px solid grey;
border-radius: 6px;
background-color: #EFEFEF;
text-align: center;
text-decoration: none;
cursor: pointer;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
z-index: 4;
vertical-align: middle;
}
.button {
width: 50px;
height: 40px;
}
.button:hover {
background-color: #aaaaaa !important;
color: white !important;
}
And finally the css for the div:
#mainToolbar {
position: absolute;
top: 0px;
left: 0px;
height: 520px;
width: 60px;
z-index: 10;
text-align: center;
}
How can I put the icon right in the middle of the button (both vertically and horizontally)? Thanks.
You can use absolute positioning along with translate to position the icon right in the middle. Be sure to add a position:relative on the button so that the icon is positioned w.r.t to the button.
.button {
margin: auto;
display: inline-block;
margin-top: 5px;
color: black;
border: 0px solid grey;
border-radius: 6px;
background-color: #EFEFEF;
text-align: center;
text-decoration: none;
cursor: pointer;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
z-index: 4;
vertical-align: middle;
}
.button {
width: 50px;
height: 40px;
position: relative;
}
.button:hover {
background-color: #aaaaaa !important;
color: white !important;
}
.button:active i{
/*for push effect on click*/
transform: translate(-45%, -45%);
}
.button i {
/*horizontal and vertical centering*/
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#mainToolbar {
position: absolute;
top: 0px;
left: 0px;
height: 520px;
width: 60px;
z-index: 10;
text-align: center;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">
<div id="mainToolbar">
<button id="buttonPencil" data-tool="yes" data-type="draw" title="Use pencil" class="button" onclick="changeTool(0);">
<i class="material-icons">brush</i>
</button>
</div>
To explain:
top:50% with a position: absolute will move the icon down 50% of the parent's height. A translateY with -50% will move the icon up by half its height so that its aligned right in the middle by its center. Similarly with horizontal centering.
Its Working Fine see snippet
.button {
margin: auto;
display: inline-block;
margin-top: 5px;
color: black;
border: 0px solid grey;
border-radius: 6px;
background-color: #EFEFEF;
text-align: center;
text-decoration: none;
cursor: pointer;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
z-index: 4;
vertical-align: middle;
}
.button {
width: 50px;
height: 40px;
}
.button:hover {
background-color: #aaaaaa !important;
color: white !important;
}
And finally the css for the div:
#mainToolbar {
position: absolute;
top: 0px;
left: 0px;
height: 520px;
width: 60px;
z-index: 10;
text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div id="mainToolbar">
<button id="buttonPencil" data-tool="yes" data-type="draw" title="Use pencil" class="button" onclick="changeTool(0);">
<i class="fa fa-leaf"></i>
</button>
</div>

Div hover function resize css

I've created a div that contains a box, within that box is text and a link. What I want is when a person hovers over this box with the link, a red line appears on the bottom of the box. At the moment I've managed this but I want the red line to be the width of the grey box and only 5 pixels in height.
#teamspeak_box {
width: 159px;
height: 43px;
background: #212121;
bottom: 82px;
right: 76px;
position: absolute;
border-radius: 0px 0px 5px 5px;
}
#teamspeak_box_2 {
width: 43px;
height: 43px;
background: #313131;
bottom: 82px;
right: 191px;
position: absolute;
border-radius: 0px 0px 0px 5px;
}
#teamspeak_text {
color: white;
bottom: 93px;
right: 66px;
position: absolute;
}
#teamspeak_image {
bottom: 80px;
right: 104px;
position: absolute;
}
#teamspeak_image a:hover {
background-color: #C62828;
transition: all 0.5s ease;
}
<div id="teamspeak_box"></div>
<div id="teamspeak_box_2">
</div>
<div id="teamspeak_text">
<p>TEAMSPEAK
<P/>
</div>
<div id="teamspeak_image">
<a href="ts3server://craft412.serveminecraft.net:9987">
<img src="images/CRAFT412 - Box - Teamspeak.png" alt="TEAMSPEAK">
</a>
</div>
I find your element positioning insane. Try this one
HTML
<a href="ts3server://craft412.serveminecraft.net:9987">
<div class="teamspeak-box">
<div class="teamspeak-icon">
<img src="http://filepic.ru/file/1436899103.png" alt="">
</div>
<p>TEAMSPEAK</p>
</div>
</a>
CSS
.teamspeak-box{
width: 159px;
height: 43px;
background: #212121;
border-radius: 0px 0px 5px 5px;
overflow: hidden;
color: white;
display: table;
}
.teamspeak-icon{
width: 43px;
height: 43px;
background: #313131;
display: table-cell;
transition: all 0.5s ease;
}
.teamspeak-icon img{
width: 100%;
}
.teamspeak-box p{
display: table-cell;
text-align: center;
vertical-align: middle;
}
.teamspeak-box:hover .teamspeak-icon{
-webkit-box-shadow: inset 0px -5px 0px 0px rgba(255,0,0,1);
-moz-box-shadow: inset 0px -5px 0px 0px rgba(255,0,0,1);
box-shadow: inset 0px -5px 0px 0px rgba(255,0,0,1);
}
Run this code on JSFiddle
Basically you want to change the styling on one element while hovering another. This can be done the following way:
#teamspeak_image a:hover ~ #teamspeak_box {
background-color: #C62828;
transition: all 0.5s ease;
}
See this answer for more info. And you might consider adding a border-bottom: 5px solid red; to the box instead of background-color.
In order for the red line to be the width of the grey box and 5px tall,
use the css property to set the display of the grey box to block. Thus, for the grey box use:
display:block;
height:5px;
After that you can set other css properties for the links inside the grey box.