In what manner, rotation is 90 degrees here? - html

In the code below, the button with close id, is rotated 90 degrees. But I don't get how that button moved 90 degrees and with respect to what origin. transform-origin: top left; But top left of what element?
body {
margin: 0;
}
.circle-container {
position: fixed;
top: 100px;
left: 100px;
}
.circle {
background-color: #ff7979;
height: 200px;
width: 200px;
/* border-radius: 50%; */
position: relative;
transition: transform 0.5s linear;
}
.circle button {
position: absolute;
top: 50%;
left: 50%;
height: 100px;
background: transparent;
border: 0;
font-size: 26px;
color: #fff;
}
.circle button:focus {
outline: none;
}
.circle button#open {
left: 60%;
}
.circle button#close {
top: 60%;
transform: rotate(90deg);
transform-origin: top left;
}
<script src="https://kit.fontawesome.com/e057ae8bc6.js"></script>
<div class="circle-container">
<div class="circle">
<button id="close">
<i class="fas fa-times"></i>
</button>
<button id="open">
<i class="fas fa-bars"></i>
</button>
</div>

Ok, I got it. The top-left is of that button's top-left. I button has been stretched vertically by using height property as well as pushed from the top using absolute positioning. I got confused because, in my mind, I was viewing button element as having an equal size of icon element inside.

Related

Why do my items go left when you hover more of them simultaneously?

I have a navigation on the right side of the page, and I made an animation where when you hover on a button it enlarges and shows the page name.
// This is the JavaScript code where I make the Buttons Wider:
document.querySelectorAll(".nav-button").forEach(elem => elem.addEventListener("mouseover",
() => {
elem.querySelector(".nav-hover").style.width = "300%";
}));
document.querySelectorAll(".nav-button").forEach(elem => elem.addEventListener("mouseout",
() => {
elem.querySelector(".nav-hover").style.width = "";
}));
.navigation {
z-index: 10;
position: absolute;
right: 0px;
}
.navigation .buttons {
position: absolute;
top: 50%;
transform: translate(-50%, -50%) !important;
}
.button-el {
height: 65px;
margin-bottom: 30px;
}
.button-el i {
color: var(--text-color);
font-size: 28px;
position: relative;
float: right;
margin-top: 15px;
margin-right: 15px;
}
.nav-hover {
z-index: -1;
transition: width .5s ease-out, opacity 0s, all 1s;
position: relative;
width: 65px;
height: 65px;
border-radius: 500px;
float: right;
background-color: var(--dark1);
border: var(--accent1) 3px solid;
}
<div class="buttons">
<div class="nav-button button-el home">
<div class="active"></div>
<div class="nav-hover">
<i class="fa-solid fa-house"></i>
</div>
</div>
<div class="nav-button button-el home">
<div class="active"></div>
<div class="nav-hover">
<i class="fa-solid fa-user-large"></i>
</div>
</div>
<div class="nav-button button-el home">
<div class="active"></div>
<div class="nav-hover">
<i class="fa-solid fa-house"></i>
</div>
</div>
</div>
I think that the cause might be in the Javascript since the .buttons DIV moves when you activate very fast multiple addEventListener (mouseover and mouseout).
The problem is in the .navigation .buttons selector:
.navigation .buttons {
position: absolute;
top: 50%;
transform: translate(-50%, -50%) !important;
}
It seems like what did change it was the x in translate(x, -50%). Now it looks like this:
.navigation .buttons {
position: absolute;
top: 50%;
right: 67%;
transform: translate(0, -50%) !important;
}

overflow:hidden not working with border-radius in Chrome

I'm trying to make a circle-shaped image with an overlay that shows on hover. However, the "hitbox" of hovering (and clicking) is incorrect, as shown in the snippet below.
This issue seems to only occur in Chrome (not sure about Safari). I've found some fixes on the Internet, but none of them worked. JSFiddle for testing
$(document).ready(function() {
$(".circle").click(function() {
alert($(this).attr("id"));
});
});
#canvas {
width: 100%;
padding-bottom: 75%;
position: relative;
overflow: hidden;
background-color: #eee;
}
.circle {
position: absolute;
width: 25%;
padding-bottom: 25%;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
overflow: hidden;
cursor: pointer;
/*https://stackoverflow.com/a/32987370/5532169*/
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
/*https://stackoverflow.com/a/25206004/5532169*/
z-index: 1;
/*https://stackoverflow.com/a/10296258/5532169*/
-webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC);
/*https://stackoverflow.com/a/16878347/5532169*/
-webkit-mask-image: -webkit-radial-gradient(circle, white, black);
}
.mid {
width: 100%;
height: 100%;
position: absolute;
}
.inner {
width: 100%;
height: 100%;
position: relative;
}
.inner>* {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
height: 100%;
}
.hover {
background-color: rgba(255, 255, 255, 0.6);
opacity: 0;
transition: opacity 0.5s;
}
.hover:hover {
opacity: 100;
transition: opacity 0.5s;
}
span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 72%;
text-align: center;
font-family: monospace;
font-size: 2em;
font-weight: bold;
color: #08f;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="canvas">
<div id="div1" class="circle">
<div class="mid">
<div class="inner">
<img src="https://dummyimage.com/320x320/000/fff" alt="">
<div class="hover">
<span>Hello World!</span>
</div>
</div>
</div>
</div>
</div>
Edit: Tested in Firefox 57, works without problem. IE and Edge were tested already, so it's a Chrome-/webkit-specific issue.
The blocks in HTML are square defined by position (x, y) and size (width, height) so the browser can have a simplified idea of what is on the page and interact with. So even with border-radius, mask-image, etc... your .circle div is still a square with coming drawn within.
To avoid that, you can't use a dynamic selector like :hover because it will use the shape of the div and that is a square. You need to use javascript to detect mouse position when hovering your block and with that execute an animation (with sinus and cosinus calculation).
You can get the mouse position with something like this :
<div class="circle" onmouseover="hoverFunction(e)"></div>
<script>
function hoverFunction(e) {
var x = e.clientX;
var y = e.clientY;
}
</script>
I also found this topic talking about getting elements position on the page.
You can change only .circle class these properties:
width: 26%;
padding-bottom: 26%;
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;

Marking navigation button as active using CSS

I have square navigation buttons where I want to visually show which are active, for example using:
At the moment I use background: linear-gradient for this purpose. This however is hard to animate and I therefore am looking for alternatives. The HTML structures looks like:
<div class='navigation-button'>
<div class='navigation-button-container'>
<i class='fa fa-bars'></i>
</div>
</div>
with corresponding CSS:
.navigation-button {
width: 50px;
height: 50px;
background: purple;
}
.navigation-button-container {
width: 100%;
height: 100%;
text-align: center;
}
.navigation-button-container i {
margin-top: 25%;
margin-bottom: 25%;
color: white;
}
.active {
background: linear-gradient(right, blue 0%, blue 10%, rgba(0,0,0,0) 10%);
}
The active class can be applied to the navigation-button-container to get the desired effect. I want to however fade this in and out and as I understand linear-gradients cannot be animated.
I have looked in adding a element before the navigation-button-container and animate it's width and using the CSS ::before syntax but neither seemed to be of help. Is there an efficient CSS way to get the desired effect using #keyframes or transition?
Is this what you needed? There is a ::before pseudo-element on .nb-container which has a width transition.
.nb {
background-color: #f00;
display: block;
height: 50px;
width: 50px;
}
.nb-container {
width: 100%;
height: 100%;
position: relative;
text-align: center;
}
.nb-container i {
color: white;
display: inline-block;
margin: 25% 0 25%;
}
.nb-container ::before {
background-color: #00f;
content: "";
display: block;
height: 100%;
left: 0;
position: absolute;
top: 0;
transition: width .2s;
width: 0;
}
.nb-container:hover ::before, .nb-container:focus ::before {
width: 20%;
}
Mouse over the elements to see the effect:
<div class="nb">
<div class="nb-container">
<i class="fa fa-bars">∆</i>
</div>
</div>
<div class="nb">
<div class="nb-container">
<i class="fa fa-bars">®</i>
</div>
</div>
<div class="nb">
<div class="nb-container">
<i class="fa fa-bars">©</i>
</div>
</div>
The ::before element is very versatile in the way it can be animated. So if you wanted a fade-in instead of a slide-in:
.nb {
background-color: #f00;
display: block;
height: 50px;
width: 50px;
}
.nb-container {
width: 100%;
height: 100%;
position: relative;
text-align: center;
}
.nb-container i {
color: white;
display: inline-block;
margin: 25% 0 25%;
}
.nb-container ::before {
background-color: #00f;
content: "";
display: block;
height: 100%;
left: 0;
opacity: 0;
position: absolute;
top: 0;
transition: opacity .2s;
width: 20%;
}
.nb-container:hover ::before, .nb-container:focus ::before {
opacity: 1;
}
Mouse over the elements to see the effect:
<div class="nb">
<div class="nb-container">
<i class="fa fa-bars">∆</i>
</div>
</div>
<div class="nb">
<div class="nb-container">
<i class="fa fa-bars">®</i>
</div>
</div>
<div class="nb">
<div class="nb-container">
<i class="fa fa-bars">©</i>
</div>
</div>

Css issue bars to move left to right on percentage bassis

I am trying to create a graoh to show positive and negative value by percentage so if value will be negative it will be red bar if value will be positive it will run red bar so the thing is that I am having issue when I set width to 46 or 50% the bar is showing to be of full size as it shouldn't be can anyone help me out with this please
.box {
position: relative;
width: 400px;
height: 30px;
background-color: #333
}
.bar_red {
background-color: #d40216 !important;
left: 50%;
width: 13%;
max-width: 180px;
}
.bar_green {
right: 50%;
}
.bar_green,
.bar_red {
width: 42%;
height: 20px;
background-color: #88c500;
position: absolute;
top: 50%;
transform: translateY(-50%);
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
}
<div class="box">
<div class="bar_red" style="width: 50%;"></div>
<div class="bar_green" style="width: 50%;"></div>
</div>
https://jsfiddle.net/vck8wchh/
First of all your bars are pulled 50%. see example below
.bar_green {
right: 50%;
}
.bar_red {
left: 50%;
}
So this means that if you fill in 50% or higher in your <div style="50%"> it will be full width. Go to your fiddle and for example replace your HTML with the following:
<div class="box">
<div class="bar_red" style="width: 10%;"></div>
<div class="bar_green" style="width: 30%;"></div>
</div>
You'll see that they won't be fully filled. new jsfiddle
May I suggest a simpler solution? In my snippet the green bar is 100% wide, while the red bar gets a percentage width, is right-aligned and covers the green one using a higher z-index. So you only have to set the percentage of the red bar.
.box {
position: relative;
width: 390px;
height: 20px;
background-color: #333;
border: 5px solid #333;
}
.bar_green,
.bar_red {
height: 20px;
position: absolute;
}
.bar_green {
left: 0;
width: 100%;
background-color: #88c500;
z-index: 1;
}
.bar_red {
background-color: #d40216 !important;
right: 0;
width: 42%;
z-index: 2;
}
<div class="box">
<div class="bar_red"></div>
<div class="bar_green"></div>
</div>

Alternative to vertical alignment with table and table-cell

I have this pen: http://codepen.io/helloworld/pen/VYWGbz
I have set these classes in my production code and they cause IE 11 to NOT render somehow the left black border WHEN the drawer is opened.
When I remove the vertical-alignment with table/table-cell as display property the error disappears... (In Chrome its fine...)
What choice do I have else to vertically align the drawer`s glyphicon/span instead of using table on parent and table-cell on child to make vertical align possible with middle?
Note: The drawer/sidebar always have a height of 100% recieved by its parent.
.drawer-left-trigger{
display:table;
}
.drawer-left-trigger > span{
display:table-cell;
vertical-align:middle;
}
HTML
<div id="idtView">
<div style="height:100%;background:blue;" class="col-xs-3">
test1
</div>
<div style="height:100%;background:yellow;" class="col-xs-4">
test2
</div>
<div id="availableSidebarColumn" style="background:orange;padding:0;height:100%;" class="col-xs-1">
<div class="drawer-wrapper">
<div id='drawer-left' class='closed'>
<div class='drawer-left-trigger'>
<span class='glyphicon glyphicon-chevron-left'></span>
</div>
<div class='drawer-left-content'>
<div style="background:orange;;" id="availableCommandsPagerNavigation">
<span class="previous disabled glyphicon glyphicon-chevron-left availableOptionsArrow availableOptionsPagerArrow"></span>
<span class="glyphicon glyphicon-chevron-right availableOptionsArrow availableOptionsPagerArrow"></span>
</div>
<div style="background:gray;" id="availableCommandsContainer">
contentcontentcontentcontentcontentcontentcontent contentcontent content
</div>
</div>
</div>
</div>
</div>
<div style="height:100%;background:pink;" class="col-xs-4">
test2
</div>
</div>
CSS
/*new stuff*/
*{
box-sizing: border-box;
}
.drawer-wrapper{
margin: 0 200px;
display: inline-block;
}
/*The left drawer*/
#drawer-left{/*set a container with the total width of both the container and the trigger*/
position: relative;
height: 100%; width: 205px;
overflow: hidden;
transition: all .35s ease-in-out;
}
#drawer-left:after{/*this will the right border, when the content will be pushed out*/
content: '';
position: absolute;
right: 0; top: 0; bottom: 0;
border-right: 1px solid #000;
}
.drawer-left-trigger{
/*set the triggers width here, borders etc.*/
position: absolute;
top: 0; bottom: 0; right: 100%;
margin-right: -25px;/*bring it back inside the wrapper*/
width: 25px;
background:yellow;
/*some styling stuff*/
cursor: pointer;
text-align: center;
font-size: 24px;
line-height: 100%;
}
.drawer-left-trigger > span{
transform: rotate(180deg);
transition: all .35s ease-in-out;
}
#drawer-left.closed .drawer-left-trigger > span{
transform: rotate(0);
}
#drawer-left.closed .drawer-left-trigger{
/*this will push the trigger on the right side*/
left: auto;
right: 25px;
}
.drawer-left-content{
/*this is the container for the header and content*/
position: absolute;
top: 0; bottom: 0; right: 0; left: 24px;/*the triggers width(+-1px from the border)*/
}
#drawer-left.closed .drawer-left-content{
/*this will push the content out*/
left: 100%;
right: -100%;
}
.drawer-left-trigger,
.drawer-left-content{
border-left: 1px solid #000;
border-bottom: 1px solid #000;
border-top: 1px solid #000;
transition: all .35s ease-in-out;
}
JS
$(function () {
/*the left one*/
$('.drawer-left-trigger').click(function(){
$(this).parent().toggleClass('opened closed');
});
});
You could use FlexBox.
http://css-tricks.com/snippets/css/a-guide-to-flexbox/
Browser Support
http://caniuse.com/#feat=flexbox
You can use translateY, and position relative.
.drawer-left-trigger > span{
transition: all .35s ease-in-out;
transform: rotate(180deg) translateY(-50%);
position: relative;
top: 50%;
}
If the .drawer-wrapper is the only element on the page, consider setting its height to 100% instead of 500px by adding
html,body,.drawer-wrapper {
height: 100%;
}
If you need to add some navigation bar on top, calculate drawer's height by calc(100% - 50px) where 50px is the height of navigation bar.
Working version
http://codepen.io/antraxis/pen/yyoNpg