How To Keep the Arrow Pointing Up When the Dropdown Is Visible? - html

I need help. I have a main button that has an arrow pointing down to indicate that there is a dropdown. Upon hover, the dropdown appears and the arrow rotates and pointing up. However, it should keep pointing up when I hover over the dropdown items. Could anyone help me with my codes? Thank you in advance.
Please see the link for codes on CodePen.
https://codepen.io/denzdoneza/pen/ZEjddQp
HTML:
<a href="#" class="mainButton">
<button>Resources<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 24 14.1" style="enable-background:new 0 0 24 14.1;" xml:space="preserve">
<path d="M12,14.1L0,2.1L2.1,0L12,9.9L21.8,0L24,2.2L12,14.1z"/>
</svg></button>
</a>
<div class="dropdown">
<button>Blackpaper</button>
<button>Whitepaper</button>
</div>
CSS:
button {
width: 256px;
height: 52px;
font-size: 16px;
background-color: #cd0d0d;
color: #ffffff;
}
a button svg {
fill: #ffffff;
position: absolute;
width: 12px;
margin: 6px 0 0 8px;
transform: rotate(0deg) translateX(0px) translateY(0px);
transition: transform 0.2s linear;
}
.dropdown {
display: none;
}
button:hover {
background-color: #8e0000;
}
a.mainButton:hover ~ .dropdown {
display: flex;
flex-direction: column;
}
a.mainButton:hover svg {
transform: rotate(180deg) translateX(0px) translateY(0px);
transition: transform 0.2s linear;
}
.dropdown:hover {
display: flex;
flex-direction: column;
}
.dropdown:hover ~ a.mainButton button svg {
transform: rotate(180deg) translateX(0px) translateY(0px) !important;
transition: transform 0.2s linear;
}
I tried a CSS :hover on the container of the dropdown and use ~ to point on the arrow but it didn't work.
CSS:
.dropdown:hover ~ a.mainButton button svg {
transform: rotate(180deg) translateX(0px) translateY(0px) !important;
transition: transform 0.2s linear;
}

You could just put all the code inside a container and then change:
a.mainButton:hover svg {
transform: rotate(180deg) translateX(0px) translateY(0px);
transition: transform 0.2s linear;
}
For:
.container:hover svg {
transform: rotate(180deg) translateX(0px) translateY(0px);
transition: transform 0.2s linear;
}
button {
width: 256px;
height: 52px;
font-size: 16px;
background-color: #cd0d0d;
color: #ffffff;
}
a button svg {
fill: #ffffff;
position: absolute;
width: 12px;
margin: 6px 0 0 8px;
transform: rotate(0deg) translateX(0px) translateY(0px);
transition: transform 0.2s linear;
}
.dropdown {
display: none;
}
a.mainButton:hover ~ .dropdown {
display: flex;
flex-direction: column;
}
.container:hover svg {
transform: rotate(180deg) translateX(0px) translateY(0px);
transition: transform 0.2s linear;
}
.dropdown:hover {
display: flex;
flex-direction: column;
}
.dropdown a:hover ~ a.mainButton button svg {
transform: rotate(180deg) translateX(0px) translateY(0px) !important;
transition: transform 0.2s linear;
}
<div class="container">
<a href="#" class="mainButton">
<button>Resources<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 24 14.1" style="enable-background:new 0 0 24 14.1;" xml:space="preserve">
<path d="M12,14.1L0,2.1L2.1,0L12,9.9L21.8,0L24,2.2L12,14.1z"/>
</svg></button>
</a>
<div class="dropdown">
<button>Blackpaper</button>
<button>Whitepaper</button>
</div>
</div>

You need to add the CSS rule "pointer-events: none" under the display: none; line
.dropdown {
display: none;
pointer-events: none;
}

Related

css closing sidebar when clicking in the main window

Hello there I searched for other people who has the same problem as me but I couldn't implement their problem to mine so I want to close the sidebar when clicking outside the sidebar.
html {
background-color: #161618;
overflow: hidden;
}
#menuToggle
{
display: block;
position: relative;
top: 10px;
left: 10px;
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle a
{
text-decoration: none;
color: #7e7e7e;
font-family: 'Microsoft Yahei';
transition: color 0.3s ease;
}
#menuToggle a:hover
{
color: white;
}
#menuToggle input
{
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: 2px;
cursor: pointer;
opacity: 0;
z-index: 2;
-webkit-touch-callout: none;
}
#menuToggle span
{
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease;
}
#menuToggle span:first-child
{
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2)
{
transform-origin: 0% 100%;
}
#menuToggle input:checked ~ span
{
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #FCFCFC;
}
#menuToggle input:checked ~ span:nth-last-child(3)
{
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
#menuToggle input:checked ~ span:nth-last-child(2)
{
transform: rotate(-45deg) translate(0, -1px);
}
#menu
{
position: fixed;
width: fit-content;
background-color: #141414;
margin: -100px 0 0 -50px;
padding: 50px;
box-shadow: 0 -2px 15px rgb(5, 5, 5);
height: 1400px;
padding-top: 125px;
list-style-type: none;
-webkit-font-smoothing: antialiased;
transform-origin: 0% 0%;
transform: translate(-100%, 0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
#menu li
{
padding: 10px 0;
font-size: 22px;
}
#menuToggle input:checked ~ ul
{
transform: none;
}
.github:hover {
filter: invert(100%) sepia(100%) saturate(0%) hue-rotate(308deg) brightness(101%) contrast(101%);
}
<nav role="navigation">
<div id="menuToggle">
<input type="checkbox" />
<span></span>
<span></span>
<span></span>
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>Info</li>
<li>Contact</li>
<li><svg class="github" style="position:absolute;fill: #7e7e7e;width:35px;height:35px;margin-top: 275%;margin-left: 25%;padding:0%;" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg></li>
</ul>
</div>
</nav>
as I should I have tried to solve the problem on my own and I did stuff with js with body onclick= ... but I am not that familiar with js and I don't know if it would work
Your toggle menu works by checking/unchecking a checkbox. This can only be done by clicking on the input element (incl. all child elements) itself or by clicking on the linked label.
None of that applies if you clicking outside that specific element. As such you require a script to listen for click events outside of that element. here you find a reference to this code
Last but not least to finish the code from the reference you can use:
document.querySelector("#menuToggle input").checked = false; to uncheck the checkbox in question to close it.
var ignoreElement = document.querySelector("#menuToggle");
document.addEventListener('click', function(event) {
var clickElement = ignoreElement.contains(event.target);
if (!clickElement) {
document.querySelector("#menuToggle input").checked = false;
}
});
html {
background-color: #161618;
overflow: hidden;
}
#menuToggle {
display: block;
position: relative;
top: 10px;
left: 10px;
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle a {
text-decoration: none;
color: #7e7e7e;
font-family: 'Microsoft Yahei';
transition: color 0.3s ease;
}
#menuToggle a:hover {
color: white;
}
#menuToggle input {
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: 2px;
cursor: pointer;
opacity: 0;
z-index: 2;
-webkit-touch-callout: none;
}
#menuToggle span {
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), background 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), opacity 0.55s ease;
}
#menuToggle span:first-child {
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2) {
transform-origin: 0% 100%;
}
#menuToggle input:checked~span {
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #FCFCFC;
}
#menuToggle input:checked~span:nth-last-child(3) {
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
#menuToggle input:checked~span:nth-last-child(2) {
transform: rotate(-45deg) translate(0, -1px);
}
#menu {
position: fixed;
width: fit-content;
background-color: #141414;
margin: -100px 0 0 -50px;
padding: 50px;
box-shadow: 0 -2px 15px rgb(5, 5, 5);
height: 1400px;
padding-top: 125px;
list-style-type: none;
-webkit-font-smoothing: antialiased;
transform-origin: 0% 0%;
transform: translate(-100%, 0);
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0);
}
#menu li {
padding: 10px 0;
font-size: 22px;
}
#menuToggle input:checked~ul {
transform: none;
}
.github:hover {
filter: invert(100%) sepia(100%) saturate(0%) hue-rotate(308deg) brightness(101%) contrast(101%);
}
<nav role="navigation">
<div id="menuToggle">
<input type="checkbox" />
<span></span>
<span></span>
<span></span>
<ul id="menu">
<a href="loading.html">
<li>Home</li>
</a>
<a href="#">
<li>About</li>
</a>
<a href="index.html">
<li>Info</li>
</a>
<a href="#">
<li>Contact</li>
</a>
<a href="#">
<li><svg class="github" style="position:absolute;fill: #7e7e7e;width:35px;height:35px;margin-top: 275%;margin-left: 25%;padding:0%;" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg></li>
</a>
</ul>
</div>
</nav>

Change the SVG label icon in a CSS dropdown menu

I found on CodePen a CSS dropdown menu, a checkbox solution that I liked. I adapted it a little to my needs, excepting that I can't figure out how to hide the close icon when the menu is closed. I know about existing solutions, for example like here, but I can't solve it in my case. Any suggestion?
SOLVED (see below code)
*{
box-sizing: border-box;
margin: 0;
padding: 0;
}
input#toggle-menu{
display: none;
}
#search-toggle {
position: relative;
border-bottom: 4px solid tomato;
perspective: 1000px;
}
.header-inner-wrapper{
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 10px;
height: 80px;
}
#searchform{
display: flex;
flex-direction: column;
text-align: center;
position: absolute;
top: 84px;
left: 0;
width: 100%;
transform: scaleY(0);
transition: all 0.3s ease;
transform-origin: 50% top;
}
#header-inner-wrapper label{
cursor: pointer;
position: relative;
width: 60px;
height: 30px;
font-size: 0;
margin-top: -18px;
}
input#toggle-menu ~ #searchform {
/* transform: scaleY(0); */
animation: nav-out 1s ease-in-out normal forwards;
}
input#toggle-menu:checked ~ #searchform {
/* transform: scaleY(1); */
animation: nav-in 1s ease-in-out normal forwards;
}
#keyframes nav-in {
0%{
transform-origin: 50% top;
transform: scaleY(0);
}
50%{
transform: scaleY(1.3);
}
80%{
transform: scaleY(0.9);
}
90%{
transform: scaleY(1.05);
}
100%{
transform: scaleY(1);
}
}
#keyframes nav-out {
0%{
transform-origin: left center;
transform: scaleY(1);
}
50%, 60%{
transform: translateX(-10%) rotateY(0);
}
80%{
transform: translateX(100%);
}
99.9%{
transform: translateX(100%) scaleX(1);
}
100%{
transform: translateX(100%) scaleX(0);
opacity: 1;
/* transform: translateX(100%) rotateY(-90deg); */
/* transform: translateX(0%) rotateY(60deg) scaleX(0.2) ;
opacity: 0; */
}
}
input#toggle-menu:checked ~ #header-inner-wrapper #iconsearch {
display: none;
}
input#toggle-menu:not(:checked) ~ #header-inner-wrapper #iconclose {
display: none;
}
<div id="search-toggle" class="float-left">
<input type="checkbox" id="toggle-menu">
<div id="header-inner-wrapper" class="header-inner-wrapper">
<label id="iconsearch" for="toggle-menu">
<svg id="icon icon-search" viewBox="0 0 30 32">
<path class="path1" d="M20.571 14.857q0-3.304-2.348-5.652t-5.652-2.348-5.652 2.348-2.348 5.652 2.348 5.652 5.652 2.348 5.652-2.348 2.348-5.652zM29.714 29.714q0 0.929-0.679 1.607t-1.607 0.679q-0.964 0-1.607-0.679l-6.125-6.107q-3.196 2.214-7.125 2.214-2.554 0-4.884-0.991t-4.018-2.679-2.679-4.018-0.991-4.884 0.991-4.884 2.679-4.018 4.018-2.679 4.884-0.991 4.884 0.991 4.018 2.679 2.679 4.018 0.991 4.884q0 3.929-2.214 7.125l6.125 6.125q0.661 0.661 0.661 1.607z"></path>
</svg>
</label>
<label id="iconclose" for="toggle-menu">
<svg id="icon icon-close" viewBox="0 0 25 32">
<path class="path1" d="M23.179 23.607q0 0.714-0.5 1.214l-2.429 2.429q-0.5 0.5-1.214 0.5t-1.214-0.5l-5.25-5.25-5.25 5.25q-0.5 0.5-1.214 0.5t-1.214-0.5l-2.429-2.429q-0.5-0.5-0.5-1.214t0.5-1.214l5.25-5.25-5.25-5.25q-0.5-0.5-0.5-1.214t0.5-1.214l2.429-2.429q0.5-0.5 1.214-0.5t1.214 0.5l5.25 5.25 5.25-5.25q0.5-0.5 1.214-0.5t1.214 0.5l2.429 2.429q0.5 0.5 0.5 1.214t-0.5 1.214l-5.25 5.25 5.25 5.25q0.5 0.5 0.5 1.214z"></path>
</svg>
</label>
</div>
<div id="searchform">
<form role="search" method="get" class="search-form" action="https://example.com">
<textarea>Here will be a search form</textarea>
</form>
</div>
</div>

Animation only happening on one checkbox despite different classes

I have found a checkbox which I really want to use but when I add more than 1 checkbox the animation only applies to the first one.
I have tried creating new class's like .cbx2 and .inp-cbx2 and applying the same style's but the animation still only applies to the first checkbox.
Could you please explain where I'm going wrong?
Thanks.
/* #### CHECKBOX STYLES AND ANIMATION #### */
.cbx {
margin: auto;
-webkit-user-select: none;
user-select: none;
cursor: pointer;
}
.cbx span {
display: inline-block;
vertical-align: middle;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child {
position: relative;
width: 50px;
height: 50px;
border-radius: 0px;
transform: scale(1);
vertical-align: middle;
border: 1px solid #9098A9;
transition: all 0.2s ease;
}
.cbx span:first-child svg {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
fill: none;
stroke: #FFFFFF;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
stroke-dashoffset: 16px;
transition: all 0.3s ease;
transition-delay: 0.1s;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child:before {
content: "";
width: 100%;
height: 100%;
background: #2bbfcb;
display: block;
transform: scale(0);
opacity: 1;
border-radius: 0%;
}
.cbx span:last-child {
padding-left: 8px;
}
.cbx:hover span:first-child {
border-color: #2bbfcb;
}
.inp-cbx:checked + .cbx span:first-child {
background: #2bbfcb;
border-color: #2bbfcb;
animation: wave 0.4s ease;
}
.inp-cbx:checked + .cbx span:first-child svg {
stroke-dashoffset: 0;
}
.inp-cbx:checked + .cbx span:first-child:before {
transform: scale(3.5);
opacity: 0;
transition: all 0.6s ease;
}
#keyframes wave {
50% {
transform: scale(0.9);
}
}
/* #### CHECKBOX STYLES AND ANIMATION #### */
.cbx2 {
margin: auto;
-webkit-user-select: none;
user-select: none;
cursor: pointer;
}
.cbx2 span {
display: inline-block;
vertical-align: middle;
transform: translate3d(0, 0, 0);
}
.cbx2 span:first-child {
position: relative;
width: 50px;
height: 50px;
border-radius: 0px;
transform: scale(1);
vertical-align: middle;
border: 1px solid #9098A9;
transition: all 0.2s ease;
}
.cbx2 span:first-child svg {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
fill: none;
stroke: #FFFFFF;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
stroke-dashoffset: 16px;
transition: all 0.3s ease;
transition-delay: 0.1s;
transform: translate3d(0, 0, 0);
}
.cbx2 span:first-child:before {
content: "";
width: 100%;
height: 100%;
background: #2bbfcb;
display: block;
transform: scale(0);
opacity: 1;
border-radius: 0%;
}
.cbx2 span:last-child {
padding-left: 8px;
}
.cbx2:hover span:first-child {
border-color: #2bbfcb;
}
.inp-cbx2:checked + .cbx2 span:first-child {
background: #2bbfcb;
border-color: #2bbfcb;
animation: wave 0.4s ease;
}
.inp-cbx2:checked + .cbx2 span:first-child svg {
stroke-dashoffset: 0;
}
.inp-cbx2:checked + .cbx2 span:first-child:before {
transform: scale(3.5);
opacity: 0;
transition: all 0.6s ease;
}
#keyframes wave {
50% {
transform: scale(0.9);
}
}
<input class="inp-cbx" id="cbx" type="checkbox" style="display: none;"/>
<label class="cbx" for="cbx"><span>
<svg width="40px" height="40px" viewbox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg></span><span>DIRECT</span></label>
<input class="inp-cbx2" id="cbx2" type="checkbox" style="display: none;"/>
<label class="cbx2" for="cbx"><span>
<svg width="40px" height="40px" viewbox="0 0 12 10" class="c">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg></span><span>MUTI ROUTE</span></label>
The whole reason classes exist in CSS is to make your styles reusable across multiple elements. There is no need to duplicate your CSS.
The reason the second check box doesn't work when using the same classes as the first is because you haven't updated the second labels for property. This property tells the browser the id of the form element that should be effected when the label is clicked.
In your case, the second label should look like this:
<label class="cbx" for="cbx2"><span>
/* #### CHECKBOX STYLES AND ANIMATION #### */
.cbx {
margin: auto;
-webkit-user-select: none;
user-select: none;
cursor: pointer;
}
.cbx span {
display: inline-block;
vertical-align: middle;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child {
position: relative;
width: 50px;
height: 50px;
border-radius: 0px;
transform: scale(1);
vertical-align: middle;
border: 1px solid #9098A9;
transition: all 0.2s ease;
}
.cbx span:first-child svg {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
fill: none;
stroke: #FFFFFF;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
stroke-dashoffset: 16px;
transition: all 0.3s ease;
transition-delay: 0.1s;
transform: translate3d(0, 0, 0);
}
.cbx span:first-child:before {
content: "";
width: 100%;
height: 100%;
background: #2bbfcb;
display: block;
transform: scale(0);
opacity: 1;
border-radius: 0%;
}
.cbx span:last-child {
padding-left: 8px;
}
.cbx:hover span:first-child {
border-color: #2bbfcb;
}
.inp-cbx:checked+.cbx span:first-child {
background: #2bbfcb;
border-color: #2bbfcb;
animation: wave 0.4s ease;
}
.inp-cbx:checked+.cbx span:first-child svg {
stroke-dashoffset: 0;
}
.inp-cbx:checked+.cbx span:first-child:before {
transform: scale(3.5);
opacity: 0;
transition: all 0.6s ease;
}
#keyframes wave {
50% {
transform: scale(0.9);
}
}
<input class="inp-cbx" id="cbx" type="checkbox" style="display: none;" />
<label class="cbx" for="cbx"><span>
<svg width="40px" height="40px" viewbox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg></span><span>DIRECT</span></label>
<input class="inp-cbx" id="cbx2" type="checkbox" style="display: none;" />
<label class="cbx" for="cbx2"><span>
<svg width="40px" height="40px" viewbox="0 0 12 10" class="c">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg></span><span>MUTI ROUTE</span></label>

How to hide svg element

I have a problem with hiding svg element. Maybe display: none or visibility? I tried but it hasn't any results. As here (IMAGE). Please help.
This is my site with example text "KAWAŁY":
#kawaly-div {
text-align: center;
background: #fda9a9;
}
.link {
text-decoration: none;
position: relative;
line-height: 1;
color: #9e9ba4;
display: inline-block;
}
.link--kawaly {
font-family: 'Oswald', sans-serif;
font-size: 10em;
color: #e78383;
-webkit-transition: color 0s 0.5s;
transition: color 0s 0.5s;
}
.link--kawaly:hover {
color: transparent;
-webkit-transition: none;
transition: none;
}
.link--kawaly::before,
.link--kawaly::after {
content: attr(data-letters);
position: absolute;
top: 0;
left: 0;
color: #e78383;
overflow: hidden;
-webkit-backface-visibility: hidden;
-webkit-transition: color 0.5s, -webkit-transform 0.5s;
transition: color 0.5s, transform 0.5s;
}
.link--kawaly::before {
-webkit-clip-path: url(#cp_up);
clip-path: url(../index.html#cp_up);
}
.link--kawaly::after {
-webkit-clip-path: url(#cp_down);
clip-path: url(../index.html#cp_down);
}
.link--kawaly:hover::before,
.link--kawaly:hover::after {
color: #fff;
-webkit-transition: color 0.5s, -webkit-transform 0.5s;
transition: color 0.5s, transform 0.5s;
}
.link--kawaly:hover::before {
-webkit-transform: translate3d(20px, 1px, 0);
transform: translate3d(20px, 1px, 0);
}
.link--kawaly:hover::after {
-webkit-transform: translate3d(-10px, -1px, 0);
transform: translate3d(-10px, -1px, 0);
}
<link href='http://fonts.googleapis.com/css?family=Raleway:400,500,700,900|Dosis:800|Playfair+Display:400,400italic,900italic|Lora:700|Syncopate:700|Roboto+Condensed:300italic|Oswald:700' rel='stylesheet' type='text/css'>
<div id="kawaly-div">
<svg class="kawaly-tekst">
<clippath id="cp_up">
<polygon id="cp_poly_up" points="0,0 550,0 550,160" />
</clippath>
<clippath id="cp_down">
<polygon id="cp_poly_down" points="0,0 550,160 0,160" />
</clippath>
</svg>
<div class=" color-5">
<a class="link link--kawaly" href="#" data-letters="KAWAŁY">KAWAŁY</a>
</div>
</div>
Thanks in advience!
The most-often recommended way is:
<svg class="kawaly-tekst" width="0" height="0">

Internet Explorer 11 - Different behavior on measuring percent?

I have a tricky problem which I have been unable to solve.
$(".btn-nav").on("click tap", function() {
$(".nav-container")
.toggleClass("showNav hideNav")
.removeClass("hidden");
$(this).toggleClass("animated");
});
html {
margin: 0 auto;
height: 100% -ms-content-zooming: none;
-ms-touch-action: pan-x pan-y;
-webkit-content-zooming: none;
content-zooming: none;
}
body {
font-family: 'PT Sans', arial, serif;
margin: 0;
background-color: black;
}
button {
z-index: 1070;
background: none;
border: none;
}
button::-moz-focus-inner {
border: 0
}
:focus {
outline: none
}
::-moz-focus-inner {
border: 0
}
.btn-nav:hover {
cursor: pointer
}
.btn-nav:hover .bar {
background: #17BEBB
}
.bar {
display: block;
height: 50%;
width: 100%;
background: #fff;
margin: 22% auto;
}
.btn-nav {
z-index: 1070;
display: block;
padding: 0.8% 0;
width: 3%;
height: 4%;
position: fixed;
left: 2%;
margin: 0 auto;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
}
.btn-nav:focus {
outline: none
}
.middle {
margin: 0 auto
}
.bar {
-webkit-transition: all .7s ease;
-moz-transition: all .7s ease;
-ms-transition: all .7s ease;
-o-transition: all .7s ease;
transition: all .7s ease;
}
.animated {
z-index: 1070;
}
.animated .arrow-top-r {
-webkit-transform: rotateZ(-45deg) translateY(180%);
-moz-transform: rotateZ(-45deg) translateY(180%);
-ms-transform: rotateZ(-45deg) translateY(180%);
-o-transform: rotateZ(-45deg) translateY(180%);
transform: rotateZ(-45deg) translateY(180%);
width: 55%;
}
.animated .arrow-middle-r {
-webkit-transform: translateX(50%);
-moz-transform: translateX(50%);
-ms-transform: translateX(50%);
-o-transform: translateX(50%);
transform: translateX(50%);
}
.animated .arrow-bottom-r {
-webkit-transform: rotateZ(45deg) translateY(-180%);
-moz-transform: rotateZ(45deg) translateY(-180%);
-ms-transform: rotateZ(45deg) translateY(-180%);
-o-transform: rotateZ(45deg) translateY(-180%);
transform: rotateZ(45deg) translateY(-180%);
width: 55%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<button class="btn-nav">
<div class="bar arrow-top-r"></div>
<div class="bar arrow-middle-r"></div>
<div class="bar arrow-bottom-r"></div>
</button>
</body>
https://jsfiddle.net/6t04y9wo/6/
As you can see, the top-left navigation button is shown differently between Chrome and IE.
I tried to get everything work in percent units to avoid incompatibility with 4k monitors (or very different resolutions) or zooming (which is really hard to avoid on a touchscreen-monitor+ windows).
As far as I can see, the height of the buttonelement is measured really differently, and so the inner heights will be. I've tried many different settings for that, but I can't get it work and look good for both Chrome and Internet Explorer.
It seems that the margin here:
.bar {
display: block;
height: 50%;
width: 100%;
background: #fff;
margin: 22% auto;
}
Is not correct, but I don't know how to fix it.
Maybe there is someone with some useful hints?
This would appear to be due to IE not calculating the height of the button correctly.
When using position: fixed; the position and dimensions of the element should be calculated in relation to the initial containing block:
Whereas the position and dimensions of an element with position:absolute are relative to its containing block, the position and dimensions of an element with position:fixed are always relative to the initial containing block. This is normally the viewport: the browser window or the paper’s page box.
Fixed positioning (https://www.w3.org/wiki/CSS_absolute_and_fixed_positioning)
It appears that IE is sizing the button in relation to the body. As you are using percentage height and no height has been specified on body this will result in the height for the button being set as auto. This can be overcome by adding height: 100%; to body so that the button's height can be calculated in relation to it.
The height of the bars in the button is set to 50% which with the padding will mean they exceed the height of the button. To overcome this you should set overflow: visible; on the button to allow them to be visible.
There is also a small typo that you will want to fix:
height: 100% -ms-content-zooming: none;
Should be:
height: 100%;
-ms-content-zooming: none;
You may also want to set a min-height and min-width to ensure the button shows when the viewport height is very small.
$(".btn-nav").on("click tap", function() {
$(".nav-container")
.toggleClass("showNav hideNav")
.removeClass("hidden");
$(this).toggleClass("animated");
});
html {
margin: 0 auto;
height: 100%;
-ms-content-zooming: none;
-ms-touch-action: pan-x pan-y;
-webkit-content-zooming: none;
content-zooming: none;
}
body {
height: 100%;
font-family: 'PT Sans', arial, serif;
margin: 0;
background-color: black;
}
button {
overflow: visible;
z-index: 1070;
background: none;
border: none;
}
button::-moz-focus-inner {
border: 0
}
:focus {
outline: none
}
::-moz-focus-inner {
border: 0
}
.btn-nav:hover {
cursor: pointer
}
.btn-nav:hover .bar {
background: #17BEBB
}
.bar {
display: block;
height: 50%;
width: 100%;
background: #fff;
margin: 22% auto;
}
.btn-nav {
z-index: 1070;
display: block;
padding: 0.8% 0;
width: 3%;
height: 4%;
position: fixed;
left: 2%;
margin: 0 auto;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
min-height: 20px;
min-width: 50px;
}
.btn-nav:focus {
outline: none
}
.middle {
margin: 0 auto
}
.bar {
-webkit-transition: all .7s ease;
-moz-transition: all .7s ease;
-ms-transition: all .7s ease;
-o-transition: all .7s ease;
transition: all .7s ease;
}
.animated {
z-index: 1070;
}
.animated .arrow-top-r {
-webkit-transform: rotateZ(-45deg) translateY(180%);
-moz-transform: rotateZ(-45deg) translateY(180%);
-ms-transform: rotateZ(-45deg) translateY(180%);
-o-transform: rotateZ(-45deg) translateY(180%);
transform: rotateZ(-45deg) translateY(180%);
width: 55%;
}
.animated .arrow-middle-r {
-webkit-transform: translateX(50%);
-moz-transform: translateX(50%);
-ms-transform: translateX(50%);
-o-transform: translateX(50%);
transform: translateX(50%);
}
.animated .arrow-bottom-r {
-webkit-transform: rotateZ(45deg) translateY(-180%);
-moz-transform: rotateZ(45deg) translateY(-180%);
-ms-transform: rotateZ(45deg) translateY(-180%);
-o-transform: rotateZ(45deg) translateY(-180%);
transform: rotateZ(45deg) translateY(-180%);
width: 55%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<button class="btn-nav">
<div class="bar arrow-top-r"></div>
<div class="bar arrow-middle-r"></div>
<div class="bar arrow-bottom-r"></div>
</button>
</body>
Alternatively, you could use viewport units to specify the dimensions of the button.
$(".btn-nav").on("click tap", function() {
$(".nav-container")
.toggleClass("showNav hideNav")
.removeClass("hidden");
$(this).toggleClass("animated");
});
html {
margin: 0 auto;
height: 100%;
-ms-content-zooming: none;
-ms-touch-action: pan-x pan-y;
-webkit-content-zooming: none;
content-zooming: none;
}
body {
font-family: 'PT Sans', arial, serif;
margin: 0;
background-color: black;
}
button {
overflow: visible;
z-index: 1070;
background: none;
border: none;
}
button::-moz-focus-inner {
border: 0
}
:focus {
outline: none
}
::-moz-focus-inner {
border: 0
}
.btn-nav:hover {
cursor: pointer
}
.btn-nav:hover .bar {
background: #17BEBB
}
.bar {
display: block;
height: 50%;
width: 100%;
background: #fff;
margin: 22% auto;
}
.btn-nav {
z-index: 1070;
display: block;
padding: 0.8% 0;
width: 4vh;
height: 4vh;
position: fixed;
left: 2%;
margin: 0 auto;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
min-height: 20px;
min-width: 50px;
}
.btn-nav:focus {
outline: none
}
.middle {
margin: 0 auto
}
.bar {
-webkit-transition: all .7s ease;
-moz-transition: all .7s ease;
-ms-transition: all .7s ease;
-o-transition: all .7s ease;
transition: all .7s ease;
}
.animated {
z-index: 1070;
}
.animated .arrow-top-r {
-webkit-transform: rotateZ(-45deg) translateY(180%);
-moz-transform: rotateZ(-45deg) translateY(180%);
-ms-transform: rotateZ(-45deg) translateY(180%);
-o-transform: rotateZ(-45deg) translateY(180%);
transform: rotateZ(-45deg) translateY(180%);
width: 55%;
}
.animated .arrow-middle-r {
-webkit-transform: translateX(50%);
-moz-transform: translateX(50%);
-ms-transform: translateX(50%);
-o-transform: translateX(50%);
transform: translateX(50%);
}
.animated .arrow-bottom-r {
-webkit-transform: rotateZ(45deg) translateY(-180%);
-moz-transform: rotateZ(45deg) translateY(-180%);
-ms-transform: rotateZ(45deg) translateY(-180%);
-o-transform: rotateZ(45deg) translateY(-180%);
transform: rotateZ(45deg) translateY(-180%);
width: 55%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<button class="btn-nav">
<div class="bar arrow-top-r"></div>
<div class="bar arrow-middle-r"></div>
<div class="bar arrow-bottom-r"></div>
</button>
</body>
Just use pixels, 4k displays are scaled, my uhd notebook shows exactly the same page when I'm looking at a page with a 1200px width body.