CSS Border Transition - Weird effect - css

When I hover over the corner of the element I am getting a weird constant hover and hover out effect, how can I fix this?
HTML
<h2>
HELLO
</h2>
CSS
h2 {
position: absolute;
background: rgba(2,35,64,0.58);
width: calc(100% - 97px);
height: calc(100% - 88px);
line-height: calc(100% + 70px);
top: 0;
left: 0;
display: block;
font-size: 18px;
text-transform: uppercase;
text-align: center;
color: #FFF;
border: solid 20px rgba(2,35,64,0);
padding: 20px;
margin: 0px;
-webkit-transition: all 0.3s linear;
-moz-transition: all 0.3s linear;
-o-transition: all 0.3s linear;
transition: all 0.3s linear;
cursor: pointer;
}
h2:hover {
border: solid 5px #FFF;
padding: 10px;
margin: 25px;
background: transparent;
}
h2.woocommerce-loop-category__title:hover {
border: solid 5px #FFF;
padding: 10px;
margin: 25px;
background: transparent;
}
http://jsfiddle.net/xc7vjstn/1/

change the background from transparent to what ever color you want and you will see the content plus if you want to keep it online like small box then margin and padding is what you need to play with.
h2:hover {
border: solid 5px #FFF;
padding: 10px;
margin: 25px;
background: blue;
}

The margin in h2:hover is causing the behavior removing the margin fixed the problem
h2:hover {
border: solid 5px #FFF;
padding: 10px;
/*margin: 25px; */
background: transparent;
}

Here is my solution, please check the live example below:
h2 {
position: absolute;
background: rgba(2, 35, 64, 0.58);
width: calc(100% - 97px);
height: calc(100% - 88px);
line-height: calc(100% + 70px);
top: 0;
left: 0;
font-size: 18px;
text-transform: uppercase;
text-align: center;
color: #FFF;
border: solid 20px rgba(2, 35, 64, 0);
padding: 20px;
margin: 0 auto;
-webkit-transition: all 0.3s linear;
-moz-transition: all 0.3s linear;
-o-transition: all 0.3s linear;
transition: all 0.3s linear;
cursor: pointer;
}
h2:hover {
background: transparent;
-ms-transform: scale(0.9);
-webkit-transform: scale(0.9);
transform: scale(0.9);
}
<h2>
HELLO
</h2>

Related

How to get absolute element appearing outside of container with overflow set?

I have a very small container which has a custom dropdown element inside of it.
#main {
height: 90px;
width: 400px;
overflow-y: auto;
}
.wrapper-dropdown {
text-transform: uppercase;
letter-spacing: .08em;
font-size: 12px;
position: relative;
width: 200px;
padding: 12px 15px;
background: #fff;
border-radius: 6px;
border: 1px solid #d9e2f6;
cursor: pointer;
outline: none;
-webkit-transition: all .3s ease-out;
-moz-transition: all .3s ease-out;
-o-transition: all .3s ease-out;
transition: all .3s ease-out;
}
.wrapper-dropdown .dropdown {
position: absolute;
top: 100%;
left: -1px;
right: -1px;
background: #fff;
border-radius: 0 0 5px 5px;
border: 1px solid #d9e2f6;
border-top: none;
border-bottom: none;
list-style: none;
padding: 0 5px;
-webkit-transition: all .3s ease-out;
-moz-transition: all .3s ease-out;
-o-transition: all .3s ease-out;
transition: all .3s ease-out;
max-height: 0;
overflow: hidden;
margin: 0;
z-index: 5;
}
.wrapper-dropdown .dropdown li {
padding: 0 10px;
width: 100%;
}
.wrapper-dropdown .dropdown li a {
display: block;
text-decoration: none;
color: #6a759e;
padding: 15px 0;
transition: all .3s ease-out;
border-bottom: 1px solid #d9e2f6;
margin-right: 20px;
}
.wrapper-dropdown.active .dropdown {
-webkit-box-shadow: 0 10px 20px 0 rgba(217, 226, 246, .8);
-moz-box-shadow: 0 10px 20px 0 rgba(217, 226, 246, .8);
box-shadow: 0 10px 20px 0 rgba(217, 226, 246, .8);
max-height: 400px;
}
<div id="main">
CLICK OPTION 1 TO SHOW LIST
<div class="wrapper-dropdown">
<span class="selectedtext">Option1</span>
<ul class="dropdown">
<li>Option1</li>
<li>Option2</li>
<li>Option3</li>
</ul>
</div>
</div>
I'm trying to get the absolute positioned element (which is the list of options) to appear outside of the bounds of the main container which has overflow-y set.
I understand why this happening this due to this answer.
But am simply asking if anyone has any insights/tips/suggestions on a way to get around this or if it's generally not possible without moving the dropdown items outside of the container with the overflow set.
My example is here

How to create button with rounded sides?

I need to create button like this
You can see a rounded borders on center of sides. I'm tried to do it with after and before classes, but it was tricky. Which solution is the cleanest? Also I'm done on dev resizeble button and it'll be better if this can be done as one figure, without absolute positioning or smth like that
body {
background-color: #000;
display: flex;
justify-content: center;
align-items: center;
}
button {
text-transform: uppercase;
background-color: #F9EFCA;
border: none;
padding: 20px 100px;
cursor: pointer;
letter-spacing: 1px;
border-bottom: 10px solid #ae9e5c !important;
box-shadow: inset 0 -1px 1px 0 rgba(0, 0, 0, .12), 0 10px 20px -5px rgba(0, 0, 0, .25);
font-size: 50px;
transition: .2s all;
position: relative;
border-radius: 10px;
}
button:hover,
button:active {
transition: .2s all;
border-bottom: none !important;
}
button:before,
button:after {
content: '';
position: absolute;
top: 9%;
bottom: 0;
height: 91%;
background: #F9EFCA;
width: 10px;
border-radius: 100%;
}
button:before {
left: -4px;
}
button:after {
right: -4px;
}
button:active:before,
button:active:after,
button:hover:before,
button:hover:after {
top: 9%;
bottom: 0;
height: 82%;
}
<button>Call me</button>
Codepen example
create a new button class and try this in your CSS:
.button_costum
{
margin: 10px auto;
font-size: 2.0rem;
padding: 1.25rem 2.5rem;
display: block;
background-color: // choose what you want
border: 1px solid transparent;
color: // choose what you want
font-weight: 300;
-webkit-border-radius: 3px;
border-radius: 20px; // in your case it shout be 25 or 30
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
try using the property on button
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
This would help you target the button corners without distorting the shape of the button itself.

Toggle Switch lable

Im used Toggle Switch i need to put switch open and close label behind the switch , look image 01 and image 02 you can understand my issue,
this is a two type Open and closed Switch Open after displayed open Switch Closed after displayed Closed, please look the working snippet
how can i fix it,
please help me to fix this
Thanks
Image 01- current view
Image 02 - i need like this
.onoffswitch1 {
position: relative; width: 90px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch1-checkbox {
display: none;
}
.onoffswitch1-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 30px;
}
.onoffswitch1-inner {
display: block; width: 200%; margin-left: -100%;
-moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
-o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}
.onoffswitch1-inner:before, .onoffswitch1-inner:after {
display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
border-radius: 30px;
box-shadow: 0px 15px 0px rgba(0,0,0,0.08) inset;
}
.onoffswitch1-inner:before {
content: "YES";
padding-left: 10px;
background-color: #2FCCFF; color: #FFFFFF;
border-radius: 30px 0 0 30px;
}
.onoffswitch1-inner:after {
content: "NO";
padding-right: 10px;
background-color: #EEEEEE; color: #999999;
text-align: right;
border-radius: 0 30px 30px 0;
}
.onoffswitch1-switch {
display: block; width: 30px; margin: 0px;
background: #FFFFFF;
border: 2px solid #999999; border-radius: 30px;
position: absolute; top: 0; bottom: 0; right: 56px;
-moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
background-image: -moz-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
background-image: -webkit-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
background-image: -o-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
background-image: linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
box-shadow: 0 1px 1px white inset;
}
.onoffswitch1-checkbox:checked + .onoffswitch1-label .onoffswitch1-inner {
margin-left: 0;
}
.onoffswitch1-checkbox:checked + .onoffswitch1-label .onoffswitch1-switch {
right: 0px;
}
<div class="onoffswitch1">
<input type="checkbox" name="onoffswitch1" class="onoffswitch1-checkbox" id="myonoffswitch1" checked>
<label class="onoffswitch1-label" for="myonoffswitch1">
<span class="onoffswitch1-inner"></span>
<span class="onoffswitch1-switch"></span>
</label>
</div>
Please check if this is what you need. You may have to tweak the colors and the position of the text.
.onoffswitch1 {
width: 90px;
}
.onoffswitch1-checkbox {
display: none;
}
.onoffswitch1-label {
display: inline-block;
cursor: pointer;
border: 2px solid #999999;
border-radius: 30px;
width: 90px;
height: 2em;
background: darkgray;
position: relative;
margin-top: 2em;
}
.onoffswitch1-checkbox:checked + .onoffswitch1-label {
background: lightblue;
}
.onoffswitch1-checkbox:checked+.onoffswitch1-label:before {
content: "OPEN";
position: absolute;
top: -1.5em;
left: 0;
}
.onoffswitch1-checkbox+.onoffswitch1-label:before {
content: "CLOSED";
position: absolute;
top: -1.5em;
left: 0;
}
.onoffswitch1-switch {
display: block;
width: 30px;
margin: 0px;
background: #FFFFFF;
border: 2px solid #999999;
border-radius: 30px;
position: absolute;
top: 0;
bottom: 0;
right: 56px;
-moz-transition: all 0.3s ease-in 0s;
-webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s;
transition: all 0.3s ease-in 0s;
background-image: -moz-linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 80%);
background-image: -webkit-linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 80%);
background-image: -o-linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 80%);
background-image: linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 80%);
box-shadow: 0 1px 1px white inset;
}
.onoffswitch1-checkbox:checked+.onoffswitch1-label .onoffswitch1-inner {
margin-left: 0;
}
.onoffswitch1-checkbox:checked+.onoffswitch1-label .onoffswitch1-switch {
right: 0px;
}
<div class="onoffswitch1">
<input type="checkbox" name="onoffswitch1" class="onoffswitch1-checkbox" id="myonoffswitch1" checked>
<label class="onoffswitch1-label" for="myonoffswitch1">
<span class="onoffswitch1-inner"></span>
<span class="onoffswitch1-switch"></span>
</label>
</div>
Try this.
<div class="switchcontainer">
<label class="switch"><input type="checkbox" id="togBtn"><div class="slider round"><span class="on">ON</span><span class="off">OFF</span></div></label>
</div>
.switchcontainer{
margin-top:25px;
}
.switchcontainer .on{
margin-top:-25px;
color:green;
}
.switchcontainer .off{
margin-top:-25px;
color:red;
}
.switch {
position: relative;
display: inline-block;
width: 90px;
height: 34px;
border: 2px solid #999999;
border-radius: 30px;
}
.switch input {display:none;}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #EEEEEE;
-webkit-transition: .4s;
transition: .4s;
box-shadow: 0px 15px 0px rgba(0,0,0,0.08) inset;
}
.slider:before {
content: "";
height: 30px;
width: 26px;
left: 0px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
display: block;
width: 30px;
margin: 0px;
background: #FFFFFF;
border: 2px solid #999999;
border-radius: 30px;
position: absolute;
top: 0;
bottom: 0;
right: 56px;
-moz-transition: all 0.3s ease-in 0s;
-webkit-transition: all 0.3s ease-in 0s;
-o-transition: all 0.3s ease-in 0s;
transition: all 0.3s ease-in 0s;
background-image: -moz-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
background-image: -webkit-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
background-image: -o-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
background-image: linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 80%);
box-shadow: 0 1px 1px white inset;
}
input:checked + .slider {
background-color: #2FCCFF;
box-shadow: 0px 15px 0px rgba(0,0,0,0.08) inset;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(55px);
-ms-transform: translateX(55px);
transform: translateX(55px);
}
/*------ ADDED CSS ---------*/
.on
{
display: none;
}
.on, .off
{
color: white;
position: absolute;
transform: translate(-50%,-50%);
top: 50%;
left: 50%;
font-size: 10px;
font-family: Verdana, sans-serif;
}
input:checked+ .slider .on
{display: block;}
input:checked + .slider .off
{display: none;}
/*--------- END --------*/
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
https://jsfiddle.net/gnanavelr/8LqLczyh/1/
I create a switch button for you check this out
this is the html
<div class="switch">
<input class="toggle" id="toggle-1" type="checkbox" >
<label class="c-label-switch" for="toggle-1"></label>
<label class="c-label" for="toggle-1">Remember password </label>
</div>
and this is the css
.switch {
display: block;
}
.switch span {
display: inline-block;
color: #141414;
margin-top: 0px;
font-size: 14px;
font-weight: bold;
}
.switch .c-label {
padding: 0px;
vertical-align: middle;
}
.toggle {
position: absolute;
margin-left: -9999px;
visibility: hidden;
}
.toggle + label {
display: inline-block;
position: relative;
cursor: pointer;
border-radius: 15px;
width: 70px;
height: 30px;
overflow: hidden;
line-height: 4px;
margin-bottom: 0px;
vertical-align: middle;
margin-right: 10px;
}
.c-label-switch {
border: 1px solid #d1d1d1;
}
.toggle + label:before, .toggle + label:after {
display: block;
border-radius: 20px;
position: absolute;
top: 0px;
left: 0px;
bottom: 0px;
padding: 12px 12px 12px 9px;
color: #FFF;
font-family: 'Source Sans Pro';
}
.toggle + label:before {
content: "No";
right: 0px;
background-color: #ddd;
text-indent: -93px;
margin-left: 0px;
line-height: 5px;
font-size: 10px;
}
.toggle + label:after {
content: "Yes";
text-indent: 35px;
width: 6px;
background-color: #fff;
margin: 1px;
text-shadow: 0 1px 0 #fff;
margin-left: 1px;
font-size: 10px;
color: #141414;
}
.toggle:checked + label:before {
background-color: #0065b3;
text-indent: 0;
}
.toggle:checked + label:after {
margin-left: 41px;
box-shadow: none;
}
.toggle + label:before, .toggle + label:after {
transition: All 0.5s ease;
-webkit-transition: All 0.5s ease;
-moz-transition: All 0.5s ease;
-o-transition: All 0.5s ease;
}

Fill element with slanted background on hover

I'm trying to create an CSS button hover effect. But I didn't manage to fill the element with a slanted shape.
How the hover effect was planned:
Screenshot 1: How it looks actually.
Screenshot 2: How I want the hover effect to look like with slanted side.
.button_sliding_bg {
color: #31302B;
background: #FFF;
padding: 12px 17px;
margin: 25px;
font-family: 'OpenSansBold', sans-serif;
border: 3px solid #31302B;
font-size: 14px;
font-weight: bold;
letter-spacing: 1px;
text-transform: uppercase;
border-radius: 2px;
display: inline-block;
text-align: center;
cursor: pointer;
box-shadow: inset 0 0 0 0 #31302B;
-webkit-transition: all ease 0.8s;
-moz-transition: all ease 0.8s;
transition: all ease 0.8s;
}
.button_sliding_bg:hover {
box-shadow: inset 200px 0 0 0 #31302B;
color: #FFF;
}
<button class="button_sliding_bg">Buttontext</button>
You can use the technique described in this answer : Fill element from center on hover and skew the pseudo element so it fills the button with a slant :
div {
position: relative;
display: inline-block;
padding: 15px 70px;
border: 5px solid #B17461;
color: #B17461;
font-size: 30px;
font-family: arial;
transition: color .5s;
overflow:hidden;
}
div:before {
content: '';
position: absolute;
top: 0; left: 0;
width: 130%; height: 100%;
background: #B17461;
z-index: -1;
transform-origin:0 0 ;
transform:translateX(-100%) skewX(-45deg);
transition: transform .5s;
}
div:hover {
color: #fff;
}
div:hover:before {
transform: translateX(0) skewX(-45deg);
}
<div>BUTTON</div>
Don't forget to add vendor prefixes for browser support (see canIuse for more info).
I believe that you are actually looking for the end state to fill the entire element with background color and not leave the gap. You could also do it with linear-gradient background images and transition their background-size and background-position like in the below snippet.
One disadvantage of using linear-gradient over pseudo-elements or transforms is that the browser support is lower but it doesn't need extra pseudo-elements and so can leave them spare for other use.
.button_sliding_bg {
color: #31302B;
background: #FFF;
padding: 12px 17px;
margin: 25px;
font-family: 'OpenSansBold', sans-serif;
border: 3px solid #31302B;
font-size: 14px;
font-weight: bold;
letter-spacing: 1px;
text-transform: uppercase;
border-radius: 2px;
display: inline-block;
text-align: center;
cursor: pointer;
background-image: linear-gradient(135deg, #31302B 50%, transparent 51%);
background-size: 100px 100px; /* some initial size to get the slanted appearance */
background-position: -50px -50px; /* negative positioning to hide it initially */
background-repeat: no-repeat;
transition: all ease 0.8s;
}
.button_sliding_bg:hover {
background-size: 200% 200%; /* 200% because gradient is colored only for 50% */
background-position: 0px 0px; /* bring it fully into view */
color: #FFF;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<button class="button_sliding_bg">Buttontext</button>
<button class="button_sliding_bg">Button text lengthy</button>
<button class="button_sliding_bg">Button text <br> with line break</button>
<button class="button_sliding_bg">Button text <br> with <br> multiple <br> line <br>breaks</button>
You can use css :after.
Jsfiddle
.button_sliding_bg {
color: #31302B;
background: #FFF;
padding: 12px 17px;
margin: 25px;
font-family:'OpenSansBold', sans-serif;
border: 3px solid #31302B;
font-size: 14px;
font-weight: bold;
letter-spacing: 1px;
text-transform: uppercase;
border-radius: 2px;
display: inline-block;
text-align: center;
cursor: pointer;
box-shadow: inset 0 0 0 0 #31302B;
-webkit-transition: all ease 0.8s;
-moz-transition: all ease 0.8s;
transition: all ease 0.8s;
position: relative;
}
.button_sliding_bg:hover {
box-shadow: inset 200px 0 0 0 #31302B;
color: #FFF;
}
.button_sliding_bg:after {
content:'';
display: block;
position: absolute;
right: 0;
bottom: 0;
width: 0;
height: 0;
border-width: 0 0 0 0;
border-color: transparent transparent #fff transparent;
border-style: solid;
border-width: 0 0 32px 30px;
-webkit-transition: all ease 0.8s;
-moz-transition: all ease 0.8s;
transition: all ease 0.8s;
}
<button class="button_sliding_bg">Buttontext</button>

CSS on window resize, list items getting out of menu

(source: gyazo.com)
;
This is what happens if I will resize my screen or go on a little computer screen.
And this is how it should be (100% size on my Desktop screen):
(source: gyazo.com)
;
Why is it happening? Probably needs auto checking for width and using percent instead?
I am not sure..
This is my code though.
HTML:
<div id="menu">
<ul id="menuitems">
<li id="menu-active"><a href="#" >HOMEPAGE</a></li></a>
<li>PLAY NOW</li>
<li>COMMUNITY</li>
<li>HUNGER WIKI</li>
<li>HIGHSCORES</li>
<li>HELP</li>
<li><div id="login"></div></li>
</ul>
</div>
CSS:
body {
background-color: #1e1e1e;
/*background-image: url("../img/background.png");*/
background-repeat: no-repeat;
background-position: center top;
color: #fff;
font-size: 14px;
}
#logo {
background-image: url("../img/logo.png");
background-repeat: no-repeat;
width: 465px;
height: 126px;
margin-left: 24%;
margin-top: 3%;
}
#menu {
background-image: url("../img/gradient-header.png");
background-repeat: repeat;
width: 100%;
height: 56px;
border: solid 1px #000;
font-weight: bold;
}
#menuitems {
padding: 0;
margin: 0;
float: left;
}
#menuitems li {
background-image: url("../img/gradient-header.png");
background-repeat: repeat;
display: inline-block;
width: 140px;
height: 56px;
background-color: white;
float: left;
border-right: solid 1px #44acbf;
border-left: solid 1px #114a56;
line-height: 56px;
text-align: center;
-webkit-transition: all 200ms ease-in-out;
-moz-transition: all 200ms ease-in-out;
-ms-transition: all 200ms ease-in-out;
-o-transition: all 200ms ease-in-out;
transition: all 200ms ease-in-out;
}
#menuitems li:hover {
background-image: url("../img/gradient-1.png");
background-repeat: repeat;
border-right: solid 1px #2b6e81;
cursor: pointer;
-webkit-transition: all 200ms ease-in-out;
-moz-transition: all 200ms ease-in-out;
-ms-transition: all 200ms ease-in-out;
-o-transition: all 200ms ease-in-out;
transition: all 200ms ease-in-out;
}
#menuitems li:active {
background-image: url("../img/gradient-onClick-menu.png");
background-repeat: repeat;
}
#menuitems li:last-child {
width: 88px;
border-right: solid 0px transparent;
}
#menu-active {
background-image: url("../img/gradient-1.png") !important;
background-repeat: repeat !important;
border-right: solid 1px #2b6e81 !important;
}
#menuitems li:first-child {
border-left: solid 0px transparent;
}
#login {
background-image: url("../img/icon.png");
background-repeat: no-repeat;
margin-left: 32%;
margin-top: 20%;
width: 25px;
height: 21px;
}
#menuitems a {
width: 140px;
height: 56px;
color: #fff;
}
I am using .container by bootstrap framework as a container.
You have a fixed width on your menu items. That means they always stay the same size, if there isn't enough room for them on one line they will split into the next line

Resources