How to not have buttons shift css - html

On my site (antetech.org) I use bttn.css for the nav buttons. On the buttons the letter-spacing is doubled on hover. When the right buttons are hovered, all the ones to the left shift over. How can I keep the letter-spacing effect without having the other buttons move? Here is the bttn.css code
.bttn-default {
color: #fff;
}
.bttn-primary, .bttn, .bttn-md {
color: #fff;
}
.bttn, .bttn-md {
margin: 0;
padding: 0;
border-width: 0;
border-color: transparent;
background: transparent;
font-weight: 400;
cursor: pointer;
position: relative;
}
.bttn-md {
font-size: 6px;
font-family: inherit;
padding: 1% 2%;
}
.bttn-stretch {
margin: 0;
padding: 0;
border-width: 0;
border-color: transparent;
background: transparent;
font-weight: 400;
cursor: pointer;
position: relative;
font-family: inherit;
padding: 1px 2px;
overflow: hidden;
border-width: 0;
border-radius: 0;
background: transparent;
color: #fff;
letter-spacing: 0;
-webkit-transition: all 0.2s cubic-bezier(0.02, 0.01, 0.47, 1);
transition: all 0.2s cubic-bezier(0.02, 0.01, 0.47, 1);
}
.bttn-stretch:after, .bttn-stretch:before {
position: absolute;
left: 0;
width: 100%;
height: 1px;
background: currentColor;
content: '';
opacity: 0.65;
-webkit-transition: all 0.2s cubic-bezier(0.02, 0.01, 0.47, 1);
transition: all 0.2s cubic-bezier(0.02, 0.01, 0.47, 1);
-webkit-transform: scaleX(0);
transform: scaleX(0);
}
.bttn-stretch:after {
top: 0;
}
.bttn-stretch:before {
bottom: 0;
}
.bttn-stretch:hover, .bttn-stretch:focus {
letter-spacing: 2px;
opacity: 0.9;
-webkit-transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
}
.bttn-stretch:hover:after, .bttn-stretch:focus:after {
opacity: 1;
-webkit-transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
.bttn-stretch:hover:before, .bttn-stretch:focus:before {
opacity: 1;
-webkit-transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
.bttn-stretch.bttn-md {
font-size: 120%;
font-family: inherit;
padding: 1px 2px;
}
.bttn-stretch.bttn-default {
color: #fff;
}
.bttn-stretch.bttn-primary {
color: #FFF;
}
Hopefully what I'm trying to do is possible, I'm not sure if it is. Thanks for the help <3

You can add a min-width to the buttons so that they're already big enough to display the text with the expanded letter spacing:
.bttn-stretch { min-width: 5.25em; }
Using em units helps ensure this will still work regardless of the font-size. I'd recommend specifying your letter-spacing in fractional ems as well.
I would also scope the hover effect to non-touch devices. Something like:
#media only screen and (min-width: 420px) { /* this media query targets screens at least 420px wide. The intent here is to only apply the :hover styles on devices with a mouse. Admittedly, 420 pixels is a bit of an arbitrary value here, you might find a better way to target the right devices for your use case. */
.bttn-stretch { min-width: 5.25em; } /* this sets a minimum value for the width of the buttons so that they're already big enough to accommodate the letter-spaced text before the :hover styles are applied */
.bttn-stretch:hover, .bttn-stretch:focus {
letter-spacing: 0.104em; /* Currently you've got this set to 2px. I prefer to use em units because it keeps the spacing proportional to the size of your font. Because your font size is set at 19.2px, a value of 0.104em gets you very close to your current letter-spacing of 2px. You could just use 0.1em if you're not bothered by the 0.004em difference */
/* the following lines were in your existing style sheet, I've just copied them over */
opacity: 0.9;
-webkit-transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
transition: all 0.3s cubic-bezier(0.02, 0.01, 0.47, 1);
}
}

Setting the width of the parent div of your buttons and also giving your buttons a set width should give you the functionality that you want, just be mindful that you will have to adjust the values as the value i used was just to test, also make sure it carries over when the screen is reduced to mobile size you may need to edit some css in that case also
#second-nav{
list-style: none;
float: right;
margin-top: 60px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
margin-top: 0;
margin-bottom: 0;
padding-top: 15px;
padding-bottom: 15px;
display: block;
width: 480px;
}
#second-nav li{
position: relative;
display: inline-table;
padding: 5px 20px;
width: 70px;
}

Related

Need help styling button

I need some help combing the styling of this span-button which is provided by the website I use. I don't think I can change the button type to another type, and since im using Squarespace to add the button to the site, the whole code needs to be in HTML.
The code for the button is provided, and a link to how I want the button to look. Im looking forward to your guys' ideas and ways to do it!
Ive tried to style it using different ways, but can't seem to understand how to exactly implement the css into the span-element.
This is the provided code for the button:
<span class="glf-button" data-glf-cuid="44e34391-d2c4-489d-90d7-22b985839fe4" data-glf-ruid="8c4c9138-a45f-41bb-8e6b-042c85a98586" > Se Meny & Bestill</span>
<script src="https://www.fbgcdn.com/embedder/js/ewm2.js" defer async ></script>
Here you can find the desired styling of the button: https://codepen.io/romeg33/pen/mrdGMe
<div class="block-center">
<button class="btn" role="button"><span>Hover and click!</span></button>
</div>
#import 'https://fonts.googleapis.com/css?family=Roboto:300';
body {
background: #F5F5F5;
}
.block-center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
$btn-color: #03A9F4;
$line-color: #0288D1;
$txt-color: #fff;
$btn-font-family: 'Roboto', sans-serif;
$btn-font-size: 24px;
$transition-in: width .2s cubic-bezier(0.770, 0.000, 0.175, 1.000), height .2s .2s cubic-bezier(0.770, 0.000, 0.175, 1.000), border-color .4s;
$transition-out: width .4s cubic-bezier(0.770, 0.000, 0.175, 1.000), height .2s .4s cubic-bezier(0.770, 0.000, 0.175, 1.000);
.btn {
position: relative;
padding: 15px 20px;
background-color: $btn-color;
border: none;
text-decoration: none;
color: $txt-color;
font-family: $btn-font-family;
font-size: $btn-font-size;
letter-spacing: 1px;
z-index: 1;
cursor: pointer;
outline: none;
& span {
position: relative;
z-index: 2;
}
&:before {
content: '';
position: absolute;
box-sizing: border-box;
border-bottom: 4px solid transparent;
left: 0;
bottom: 0;
width: 0;
height: 4px;
background-color: $line-color;
transition: $transition-out;
}
&:hover {
&:before {
width: 100%;
height: 100%;
transition: $transition-in;
}
}
&:active {
&:before {
border-bottom: 4px solid $btn-color;
}
}
}
A couple of things to point out. In the codepen example they're targeting the button with the class 'btn' but your span has the class 'glf-button'. That's why the styles aren't binding.
The styling is also written in SCSS, not normal CSS. Here is the styling with the correct class and converted to vanilla CSS.
#import 'https://fonts.googleapis.com/css?family=Roboto:300';
.glf-button {
position: relative;
padding: 15px 20px;
background-color: #03a9f4;
border: none;
text-decoration: none;
color: #fff;
font-family: 'Roboto', sans-serif;
font-size: 24px;
letter-spacing: 1px;
z-index: 1;
cursor: pointer;
outline: none;
}
.glf-button span {
position: relative;
z-index: 2;
}
.glf-button:before {
content: '';
position: absolute;
box-sizing: border-box;
border-bottom: 4px solid transparent;
left: 0;
bottom: 0;
width: 0;
height: 4px;
background-color: #0288d1;
transition: width 0.4s cubic-bezier(0.77, 0, 0.175, 1), height 0.2s 0.4s cubic-bezier(0.77, 0, 0.175, 1);
}
.glf-button:hover:before {
width: 100%;
height: 100%;
transition: width 0.2s cubic-bezier(0.77, 0, 0.175, 1), height 0.2s 0.2s cubic-bezier(0.77, 0, 0.175, 1), border-color 0.4s;
}
.glf-button:active:before {
border-bottom: 4px solid #03a9f4;
}
i think you need this codepen output purely in html and css . try like below,
#import 'https://fonts.googleapis.com/css?family=Roboto:300';
body {
background: #f5f5f5;
}
.block-center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.btn {
position: relative;
padding: 15px 20px;
background-color: #03a9f4;
border: none;
text-decoration: none;
color: #fff;
font-family: 'Roboto', sans-serif;
font-size: 24px;
letter-spacing: 1px;
z-index: 1;
cursor: pointer;
outline: none;
}
.btn span {
position: relative;
z-index: 2;
}
.btn:before {
content: '';
position: absolute;
box-sizing: border-box;
border-bottom: 4px solid transparent;
left: 0;
bottom: 0;
width: 0;
height: 4px;
background-color: #0288d1;
transition: width 0.4s cubic-bezier(0.77, 0, 0.175, 1), height 0.2s 0.4s cubic-bezier(0.77, 0, 0.175, 1);
}
.btn:hover:before {
width: 100%;
height: 100%;
transition: width 0.2s cubic-bezier(0.77, 0, 0.175, 1), height 0.2s 0.2s cubic-bezier(0.77, 0, 0.175, 1), border-color 0.4s;
}
.btn:active:before {
border-bottom: 4px solid #03a9f4;
}
<div class="block-center">
<button class="btn" role="button"><span>Hover and click!</span></button>
</div>
please comment if any query

Something goes wrong when I unhover the div

I'm trying to change the text on hover, it works, but I'm wondering why the text goes to the right when you unhover the div.
I want to make the same effect when you unhover the div. Is it because the position absolute? I'm pretty new to web development.
.article-title {
opacity: 1;
width: 24%;
position: absolute;
padding-bottom: 10px;
color: #ff0099;
font-size: 30px;
transition: all .5s ease-in-out, width 0s linear, absolute 0s linear;
}
.article-desc {
width: 23%;
position: absolute;
opacity: 0;
transition: all .5s ease-in-out, width 0s linear, absolute 0s linear;
}
.box-link {
display: flex;
flex-direction: column;
padding: 10px;
border: 2px solid black;
border-radius: 10px;
height: 200px;
width: 25%;
text-align: center;
cursor: pointer;
transition: transform .5s, box-shadow .2s;
}
.box-link:hover {
transform: scale(1.15);
box-shadow: 0 0 51px rgba(33, 33, 33, .4);
}
.box-link:hover .article-title {
width: 89%;
position: absolute;
opacity: 0;
}
.box-link:hover .article-desc {
width: 95%;
opacity: 1;
}
<div class="box-link article-1">
<a class="article-title">The ultimate guide to Australian native flowers</a>
<a class="article-desc">Looking to add a touch of Australiana when building a bouquet or growing your garden? There are so many stunning Australian native flowers to choose from.</a>
</div>
Change your CSS to :
.article-title {
opacity: 1;
position: absolute;
padding-bottom: 10px;
color: #ff0099;
font-size: 30px;
transition: all .5s ease-in-out, width 0s linear, absolute 0s linear;
}
.article-desc {
position: absolute;
opacity: 0;
transition: all .5s ease-in-out, width 0s linear, absolute 0s linear;
}
.box-link {
display: flex;
flex-direction: column;
padding: 10px;
border: 2px solid black;
border-radius: 10px;
height: 200px;
width: 25%;
text-align: center;
cursor: pointer;
transition: transform .5s, box-shadow .2s;
position: relative;
}
.box-link:hover {
transform: scale(1.15);
box-shadow: 0 0 51px rgba(33, 33, 33, .4);
}
.box-link:hover .article-title {
position: absolute;
opacity: 0;
}
.box-link:hover .article-desc {
opacity: 1;
}
<div class="box-link article-1">
<a class="article-title">The ultimate guide to Australian native flowers</a>
<a class="article-desc">Looking to add a touch of Australiana when building a bouquet or growing your garden? There are so
many stunning Australian native flowers to choose from.</a>
</div>
The idea is to make the parent position relative so that you no longer need width explicitly to containerize the childs.

Set own styles to content in before element

I've just created a button. I've found a problem where my content doesn't fit on it's place.
Here is my code:
.btn-red {
display: inline-block;
padding: 13px 20px;
color: #fff;
text-decoration: none;
position: relative;
background: #f42f2c;
font: 10px "Oswald", sans-serif;
letter-spacing: 0.4em;
text-align: center;
text-indent: 2px;
text-transform: uppercase;
transition: color 0.1s linear 0.05s;
border-radius: 0;
border: 1px solid #f42f2c;
}
.btn-red:focus {
box-shadow:none !important;
}
.btn-red::before {
content: "READ MORE";
display: block;
position: absolute;
top: 50%;
left: 0;
width: 100%;
height: 1px;
background: #f9f9ff;
color:#f42f2c !important;
z-index: 1;
opacity: 0;
transition: height 0.2s ease, top 0.2s ease, opacity 0s linear 0.2s;
}
.btn-red::after {
transition: border 0.1s linear 0.05s;
}
.btn-red .btn-red-inner {
position: relative;
z-index: 2;
}
.btn-red:hover {
transition: color 0.1s linear 0s;
text-decoration: none;
color: #f42f2c !important;
}
.btn-red:hover::before {
top: 0;
height: 100%;
opacity: 1;
transition: height 0.2s ease, top 0.2s ease, opacity 0s linear 0s;
}
.btn-red:hover::after {
transition: border 0.1s linear 0s;
}
<a href="o-nas.php" class="btn-red">
<span class="btn-inner">READ MORE</span>
</a>
I tried to add padding: 13px 20px to .btn-red::before, but it has some bugs and I don't know how to solve this.
I think I achieve the same thing that you wanted without using :before to control the button text. Look below:
.btn-red {
position: relative;
display: inline-flex;
box-sizing: border-box;
padding: 13px 20px;
text-decoration: none;
background-color: #f42f2c;
border: 1px solid #f42f2c;
}
.btn-red:before {
position: absolute;
top: 50%;
left: 0;
width: 100%;
height: 0;
content: "";
background-color: #fff;
transform: translateY(-50%);
transition: height 0.2s ease-in-out;
}
.btn-red .btn-inner {
font: 10px "Oswald", sans-serif;
color: #fff;
line-height: 1em;
letter-spacing: 0.4em;
text-transform: uppercase;
z-index: 1;
transition: color 0.2s ease-in-out;
}
.btn-red:hover:before {
height: 100%;
}
.btn-red:hover .btn-inner {
color: #f42f2c;
}
<a class="btn-red" href="#" title="Read More">
<span class="btn-inner">Read more</span>
</a>
Hope this can help you anyway. If you have any doubt about the code, please, just let me know :)
Cheers!

Sizing sliding underline

I want to make the sliding underline to run from left to right when i hover, and also set up the width of the line from the 1st letter to the last, and not bigger. How can i do that?
.nav-bar a:hover {
color: #000;
}
.nav-bar a:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0;
left: 0;
background-color: #000;
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
.nav-bar a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
<div class="nav-bar">
<ul>
<li>RETROSPECTIVE SHOW /2006/</li>
<li>TEXTS</li>
<li>BIBLOGRAPHY</li>
</ul>
</div>
You can use display: inline-block; to keep the fixed width. And for underlining you can use pseudo-classes like :before and :after.
Have a look at the snippet below:
/* LEFT TO RIGHT */
.sliding-left-to-right {
display: inline-block;
margin: 0;
}
.sliding-left-to-right:after {
content: '';
display: block;
height: 3px;
width: 0;
background: transparent;
transition: width .5s ease, background-color .5s ease;
}
.sliding-left-to-right:hover:after {
width: 100%;
background: blue;
}
/* LAYOUT STYLING */
body {
margin: 20px;
}
a {
text-decoration: none;
font-size: 20px;
font-weight: bold;
color: blue;
}
a:hover {
color: blue;
text-decoration: none;
cursor: pointer;
}
<a class="sliding-left-to-right">Underline – Left to Right</a>
Hope this helps!

Is there a way to bypass overflow:hidden so an absolute positioned div could appear outside of it?

I have a menu, and on each <li> there's a class making it overflow: hidden; so I can achieve an animation on it. The thing is on one of these list-item's there's a sub-menu. This sub-menu is position: absolute;. The overflow is making it so you can't see it when it's being clicked on. If I remove overflow: hidden; the animation breaks. I'm not sure what to do. Unless there's a way to bypass, I'm thinking for my sub-menu to appear I'd have to scrap the animation entirely.
Animation
/* Wayra */
.wayra {
overflow: hidden;
-webkit-transition: border-color 0.3s, color 0.3s;
transition: border-color 0.3s, color 0.3s;
-webkit-transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}
/*.wayra.contact-item {
overflow: visible;
}*/
.wayra::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 150%;
height: 100%;
background: #281879;
/*z-index: -1;*/
-webkit-transform: rotate3d(0, 0, 1, -45deg) translate3d(0, -3em, 0);
transform: rotate3d(0, 0, 1, -45deg) translate3d(0, -3em, 0);
-webkit-transform-origin: 0% 100%;
transform-origin: 0% 100%;
-webkit-transition: -webkit-transform 0.3s, opacity 0.3s, background-color 0.3s;
transition: transform 0.3s, opacity 0.3s, background-color 0.3s;
}
.wayra a {
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.wayra a:hover {
color: #fff;
}
.wayra:hover::before {
opacity: 1;
background-color: #281879;
-webkit-transform: rotate3d(0, 0, 1, 0deg);
transform: rotate3d(0, 0, 1, 0deg);
-webkit-transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}
Dropdown
.dropdown-menu {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
padding: 5px 0;
margin: 2px 0 0;
font-size: 14px;
text-align: left;
list-style: none;
background-color: #fff;
-webkit-background-clip: padding-box;
background-clip: padding-box;
border: 1px solid #ccc;
border: 1px solid rgba(0,0,0,.15);
border-radius: 4px;
-webkit-box-shadow: 0 6px 12px rgba(0,0,0,.175);
box-shadow: 0 6px 12px rgba(0,0,0,.175);
}
Here's a link to a demo.
How about adding that effect to a instead of li? Let's translate:
.wyara should get overflow:visible,
.wyara > a should get overflow:hidden,
.wayra::before becomes .wayra > a::before,
.wayra:hover::before becomes .wyara:hover > a::before, .wayra.open > a::before
Just tried it with Stylish, looks good.
Yes, you can override it when hovering over the element:
.wayra:hover {
overflow: visible;
}
I strongly believe that is not possible. But there have to be other methods to do something like this. If you want to have an animation, you will have to rewrite your menu from scratch.