CSS flexbox adds random spacing between elements - html

I have a problem. I want to use a animated checkbox and tried adding it to my code. The first problem I have is that the checkbox was floating a row above the <p> tag. For that I tried to create a flexbox with align-items: center;, but that results in a row that is aligned for some reason to the right side and the checkbox is still not at the same height as the <p> tag.
Here is the code snippet:
._checkbox
{
display: none;
}
label
{
width: 20px;
height: 20px;
margin: 0 auto;
background-color: #3f97fc;
transform: translateY(-50%);
border-radius: 50%;
cursor: pointer;
transition: 0.2s ease transform, 0.2s ease background-color, 0.2s;
overflow: hidden;
z-index: 1;
}
label:before
{
content: "";
position: absolute;
top: 50%;
right: .5%;
left: 0;
width: 15px;
height: 15px;
margin: 0 auto;
background-color: #fff;
transform: translateY(-50%);
border-radius: 50%;
transition: 0.2s ease width, 0.2s ease height;
}
#tick_mark
{
position: absolute;
top: 3px;
right: 0;
left: -11px;
width: 12px;
height: 10px;
margin: 0 auto;
margin-left: 14px;
transform: rotateZ(-40deg);
}
#tick_mark:before, #tick_mark:after
{
content: "";
position: absolute;
background-color: #fff;
border-radius: 2px;
opacity: 0;
transition: 0.2s ease transform, 0.2s ease opacity;
}
#tick_mark:before
{
left: 0;
bottom: 0;
width: 3px;
height: 8px;
transform: translateY(-68px)
}
#tick_mark:after
{
left: 0;
bottom: 0;
width: 100%;
height: 3px;
transform: translateX(78px)
}
._checkbox:checked + label
{
background-color: #07d410;
}
._checkbox:checked + label:before
{
width: 0;
height: 0;
}
._checkbox:checked + label #tick_mark:before, ._checkbox:checked + label #tick_mark:after
{
transform: translate(0);
opacity: 1;
}
.checkbox_container
{
display: flex;
align-items: center;
space-between: 0px
}
.teskt {
padding: 0px;
}
<div class="option 0, checkbox_container"><input type="checkbox" id="Air Quality" class="_checkbox"><label for="Air Quality"><div id="tick_mark"></div></label><p class="tekst"> Air Quality - 7 Project(s)</p></div>
So just to be clear... I want the checkbox next to the <p> tag and the height of them needs to be on the same level. Also, the content needs to be aligned to the right side!
Can someone tell me how to achieve this?

Everything aligned to left, vertically on the same level, like this?
I removed transform from label, not sure why you had it there and set it to position relative and replaced margin with margin right for spacing. On the flex container I updated it to
.checkbox_container {
display: flex;
align-items: center; // vertically centers flex items
}
._checkbox {
display: none;
}
label {
width: 20px;
height: 20px;
background-color: #3f97fc;
position: relative;
border-radius: 50%;
cursor: pointer;
transition: 0.2s ease transform, 0.2s ease background-color, 0.2s;
overflow: hidden;
z-index: 1;
margin-right: 10px;
}
label:before {
content: "";
position: absolute;
top: 50%;
right: .5%;
left: 0;
width: 15px;
height: 15px;
margin: 0 auto;
background-color: #fff;
transform: translateY(-50%);
border-radius: 50%;
transition: 0.2s ease width, 0.2s ease height;
}
#tick_mark {
position: absolute;
top: 3px;
right: 0;
left: -11px;
width: 12px;
height: 10px;
margin: 0 auto;
margin-left: 14px;
transform: rotateZ(-40deg);
}
#tick_mark:before,
#tick_mark:after {
content: "";
position: absolute;
background-color: #fff;
border-radius: 2px;
opacity: 0;
transition: 0.2s ease transform, 0.2s ease opacity;
}
#tick_mark:before {
left: 0;
bottom: 0;
width: 3px;
height: 8px;
transform: translateY(-68px)
}
#tick_mark:after {
left: 0;
bottom: 0;
width: 100%;
height: 3px;
transform: translateX(78px)
}
._checkbox:checked+label {
background-color: #07d410;
}
._checkbox:checked+label:before {
width: 0;
height: 0;
}
._checkbox:checked+label #tick_mark:before,
._checkbox:checked+label #tick_mark:after {
transform: translate(0);
opacity: 1;
}
.checkbox_container {
display: flex;
align-items: center;
}
.teskt {
padding: 0px;
}
<div class="option 0, checkbox_container">
<input type="checkbox" id="Air Quality" class="_checkbox">
<label for="Air Quality">
<span id="tick_mark"></span>
</label>
<p class="tekst"> Air Quality - 7 Project(s)</p>
</div>

Related

Div border in curve shape

I'm trying to achieve div border in the convex shape and on hover it should be in normal square shape. I have added in the bottom as same I want to add on the top I tried using before but unable to achieve the result. Can anyone help me Below is my code so far I have done.
Any help will be appreciated
* {
box-sizing: border-box;
}
.services {
position: relative;
width: 500px;
height: 420px;
margin: 100px;
background-color: #cccccc;
transition: all 0.2s ease;
animation: down-bump 0.4s ease;
}
.services:before {
}
.serv_section {
top: 83%;
position: relative;
overflow: hidden;
padding: 50px 0 0;
}
.serv_inner {
position: relative;
background: #fff;
height: 25px;
}
.serv_inner:after {
box-shadow: 0 0 0 80px #fff;
border-radius: 100%;
position: absolute;
height: 150px;
content: '';
right: -20%;
left: -20%;
top: -150px;
transition: all 0.4s ease-in-out;
}
.services:hover .serv_inner:after {
top: -120px;
}
.serv_inner:before {
/* box-shadow: 0 0 0 80px #fff;
border-radius: 100%;
position: absolute;
height: 150px;
content: '';
right: -20%;
left: -20%;
top: 130px;
transition: all 0.4s ease-in-out; */
}
span.image_caption {
position: absolute;
color: red;
padding: 10px 20px;
font-size: 30px;
z-index: 10;
animation-duration: 2.5s;
animation-fill-mode: both;
}
span.image_caption p {
font-size: 32px;
font-weight: 900;
font-family: 'Dancing Script', cursive;
color: cadetblue;
}
<div class='services'>
<div class="serv_section">
<div class="serv_inner">
</div>
</div>
</div>
You can use the before and after elements to make the curve, on hover hide the psuedo elements behind the element and remove the curve like this:
.services {
position: relative;
width: 100px;
height: 60px;
margin: 100px;
background-color: #cccccc;
z-index: 0;
}
.services:hover:before{
top: 0px;
border-radius: 0;
}
.services:hover:after{
bottom: 0px;
border-radius: 0;
}
.services:before, .services:after{
content: ' ';
position: absolute;
width: 100%;
height: 40px;
background-color: #cccccc;
border-radius: 50%;
z-index: -1;
transition: all .4s;
}
.services:before {
top: -20px;
}
.services:after {
bottom: -20px;
}
<div class='services'>
</div>
If I understand it right you can achieve this by simple using of different values for horizontal and vertical dimensions of the border-radius property (more info at https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius):
div {
background: grey;
height: 100px;
width: 200px;
transition: border-radius .15s ease-out;
}
/* border-radius on default state */
div {
border: 4px solid black;
border-radius: 50%/20px;
}
div:hover {
border-radius: 0;
}
<div></div>

three dot transform into X symbol using css

Hi I have menu which is three dots with animation. I have to transform to X when I click the three dots. The demo link is: demo
HTML:
<div class="dots">
<div class="dot"></div>
</div>
CSS:
html, body {
height: 100%;
background: black;
}
.dots {
position: absolute;
right: 20px;
}
.dot,
.dot:before,
.dot:after {
position: absolute;
width: 6px;
height: 6px;
border-radius: 20px;
background-color: #fff;
transform: rotate(270deg);
cursor: pointer;
}
.dot {
top: 50px;
right: 0;
}
.dot:before,
.dot:after {
content: "";
}
.dot:before {
right: 10px;
transition: right .3s ease-out;
}
.dot:after {
left: 10px;
transition: left .3s ease-out;
}
.dots:hover .dot:before {
right: -10px;
}
.dots:hover .dot:after {
left: -10px;
}
In the current code on hover the dots moves left to right.What I wanted is on hover the the dots should move from it's position and then transform to X on click. Confused how to fix this I want something like hamberger menu but with the dots instead of three lines. Any suggestions?
So the author confirmed, that the following fiddle solved the problem:
https://jsfiddle.net/dhmr44ua/6/
HTML:
<div class="dots">
<label for="toggle"></label>
<input id="toggle" type="checkbox" />
<div class="dot"></div>
</div>
CSS:
html, body {
height: 100%;
background: black;
}
.dots {
position: absolute;
right: 20px;
}
.dots input[type=checkbox] {
position: absolute;
top: -9999px;
left: -9999px;
}
.dots label {
display: inline-block;
cursor: pointer;
position: absolute;
width: 15px;
height: 32px;
top: 38px;
left: -10px;
z-index: 999;
}
.dot,
.dot:before,
.dot:after {
position: absolute;
width: 6px;
height: 6px;
border-radius: 20px;
background-color: #fff;
transform: rotate(270deg);
cursor: pointer;
}
.dot {
top: 50px;
right: 0;
}
.dot:before,
.dot:after {
content: "";
}
.dot:before {
right: 10px;
transition: right .3s ease-out, width .3s ease-out;
}
.dot:after {
left: 10px;
transition: left .3s ease-out, width .3s ease-out;
}
.dots:hover .dot:before {
right: -10px;
}
.dots:hover .dot:after {
left: -10px;
}
.dots input[type=checkbox]:checked ~ .dot:before {
right: -8px;
width: 22px;
transform: rotate(225deg);
}
.dots input[type=checkbox]:checked ~ .dot:after {
left: -8px;
width: 22px;
transform: rotate(135deg);
}
I used the css checkbox trick mentioned in this answer: https://stackoverflow.com/a/13975505/1293849

Animate CSS Pseudo Class

I am trying to create a search icon that transforms into an input when hovered over. I am using the pseudo class ::after for the handle of the magnifying glass. Essentially, I want the handle to smoothly disappear when the icon is hovered over. Here is a link to my codepen.
body {
text-align: center;
}
#magnifying-glass {
display: flex;
justify-content: center;
height: 100px;
width: 100px;
border-radius: 100px;
border: 14px solid red;
margin: 0 auto;
margin-top: 200px;
transition: 1s;
}
#magnifying-glass::after {
content: "";
height: 50px;
width: 14px;
background-color: red;
transform: rotate(-45deg);
position: relative;
top: 85px;
left: 50px;
-webkit-transition: 1s;
-moz-transition: 1s;
-o-transition: 1s;
transition: 1s;
}
input {
display: none;
border: none;
width: 70%;
font-size: 2.5em;
border-radius: 40px;
}
input:focus {
outline: none;
}
#magnifying-glass:hover {
width: 300px;
}
#magnifying-glass:hover #magnifying-glass::after {
width: 0px;
}
#magnifying-glass:hover input {
display: block;
}
<div id="magnifying-glass">
<input type="text" placeholder="Search">
</div>
Thanks so much!
If you want it to smoothly disappear and not so sharp change the transition times below to the following.
#magnifying-glass::after {
content: "";
height: 50px;
width: 14px;
border-radius: 10px;
background-color: red;
transform: rotate(-45deg);
position: absolute;
top: 88px;
left: 100px;
-webkit-transition: 2.5s;
-moz-transition: 2.5s;
-o-transition: 2.5s;
transition: 2.5s;
}
And to make it even smoother you can add:
#magnifying-glass:hover::after {
transform: rotate(360deg);
height: 0;
opacity: 0;
}
Heres a codepen with these changes. https://codepen.io/Ballard/pen/EgYLKG
Add an opacity: 0 to hover state
#magnifying-glass:hover::after {
transform: rotate(360deg);
height: 0;
opacity: 0;
}
DEMO: https://jsfiddle.net/2691pjod/3/
Snippet
body {
text-align: center;
background: #fff;
}
#magnifying-glass {
display: flex;
justify-content: center;
height: 100px;
width: 100px;
border-radius: 100px;
border: 14px solid red;
margin: 0 auto;
margin-top: 200px;
transition: 1s;
}
#magnifying-glass::after {
content: "";
height: 50px;
width: 14px;
border-radius: 10px;
background-color: red;
transform: rotate(-45deg);
position: relative;
top: 85px;
left: 50px;
-webkit-transition: 1s;
-moz-transition: 1s;
-o-transition: 1s;
transition: 1s;
}
input {
display: none;
border: none;
width: 70%;
font-size: 2.5em;
border-radius: 40px;
}
input:focus {
outline: none;
}
#magnifying-glass:hover {
width: 300px;
}
#magnifying-glass:hover::after {
transform: rotate(360deg);
height: 0;
opacity: 0;
}
#magnifying-glass:hover input {
display: block;
}
<div id="magnifying-glass">
<input type="text" placeholder="Search">
</div>

How to center horizontally a position: absolute elment on a position: fixed container

I need to center horizontally a button with aboslute position (because it must keep on top when to click and launch overlay and click to close overlay) on a position fixed topbar, here is the code:
.topbar {
text-align: center;
min-width: 100%;
height: 50px;
background-color: #29343a;
position: fixed;
top: 0;
}
.button {
display: inline-block;
margin-right: auto;
margin-left: auto;
width: 60px;
height: 50px;
cursor: pointer;
background-color: #00c1e2;
border-bottom: 2px solid #00a8c6;
z-index: 100;
position: absolute;
}
.overlay {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(153,204,51,0.9);
}
Thats is just the css of the three parts, the website is more complex but i think that 3 parts are the key. the topbar must be fixed on top, the buton have to be centered into the topbar div, and the overlay launch and the buttop keeps on top of the overlay.
What is working: the overlay works fine and the button keeps on top but its not horizontally centered on the topbar.
How i can hack this?
You could to the left:0 and right:0 trick.
.button {
display: inline-block;
margin-right: auto;
margin-left: auto;
width: 60px;
height: 50px;
cursor: pointer;
background-color: #00c1e2;
border-bottom: 2px solid #00a8c6;
z-index: 100;
position: absolute;
left: 0; /*added*/
right: 0; /*added*/
}
Or do the left:50% with negative left margin (half width).
.button {
display: inline-block;
width: 60px;
height: 50px;
cursor: pointer;
background-color: #00c1e2;
border-bottom: 2px solid #00a8c6;
z-index: 100;
position: absolute;
left: 50%; /*added*/
margin-left: -30px; /*added*/
}
Or use CSS3 transform.
.button {
display: inline-block;
width: 60px;
height: 50px;
cursor: pointer;
background-color: #00c1e2;
border-bottom: 2px solid #00a8c6;
z-index: 100;
position: absolute;
left: 50%; /*added*/
transform: translateX(-50%); /*added*/
}
Based on the information you provided this is what I could come up with:
/* CSS */
.topBar {
position:fixed;
top:0;
left:0;
width:100%;
height:auto;
background-color:#29343a;
}
.overlay {
display:none;
width: 100%;
background: rgba(153,204,51,0.9);
margin:0;
}
.button, .button:active, .button:visited, .button:hover {
display: block;
position:relative;
text-align:center;
cursor: pointer;
background-color: #00c1e2;
border-bottom: 2px solid #00a8c6;
margin:0 auto;
padding:10px;
}
.topBar:hover > .overlay {
display:block;
}
And I added some html because you didn't provide any:
<!-- HTML -->
<div class="topBar">
Button
<div class="overlay">
<p>Some text shows when button hover</p>
</div>
</div>
JSFIDDLE: https://jsfiddle.net/0napm6y3/
Here is the complete code of this component made on react:
This is the react component, the overlay launch is the overlay var, the other one is for one animation on the button:
var React = require('react');
var StatusBarButtonView = React.createClass({
getInitialState: function() {
return {cliked: false};
},
handleClick: function(event) {
this.setState({cliked: !this.state.cliked});
},
render: function() {
var fondo = this.state.cliked ? 'active' : '';
var overlay = this.state.cliked ? 'open' : '';
return (
<div>
<div className={"aui-profit-statusbar-button-container " + (fondo)} onClick={this.handleClick}>
<img src="images/aui-navbar-element-icon-cross.png" className={"rotate " + (fondo)}/>
</div>
<div className={"overlay overlay-slidedown " + (overlay)}>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Clients</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
);
}
});
module.exports = StatusBarButtonView;
Here is the topbar scss:
.aui-profit-statusbar-container {
text-align: center;
min-width: 100%;
height: 50px;
background-color: #29343a;
position: fixed;
top: 0;
}
Here is the button scss:
.aui-profit-statusbar-button-container {
display: inline-block;
margin-right: auto;
margin-left: auto;
width: 60px;
height: 50px;
cursor: pointer;
background-color: #00c1e2;
border-bottom: 2px solid #00a8c6;
z-index: 100;
position: absolute;
left: 0;
right: 0;
&:hover {
background-color: #56d9f6;
}
&.active {
background-color: #ff4b39;
border-bottom: 2px solid #e43f30;
}
.rotate {
margin-top: 13px;
width: 23px;
height: 23px;
-webkit-transition-duration: 0.2s;
-moz-transition-duration: 0.2s;
-ms-transition-duration: 0,2s;
-o-transition-duration: 0.2s;
transition-duration: 0.2s;
-webkit-transition-property: -webkit-transform;
-moz-transition-property: -moz-transform;
-ms-transition-property: -ms-transform;
-o-transition-property: -o-transform;
transition-property: transform;
}
.active {
-webkit-transform: rotate(135deg);
-moz-transform: rotate(135deg);
-ms-transform: rotate(135deg);
-o-transform: rotate(135deg);
transform: rotate(135deg);
}
}
Here is the overlay css:
/* Overlay style */
.overlay {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(153,204,51,0.9);
}
/* Overlay closing cross */
.overlay .overlay-close {
width: 80px;
height: 80px;
position: absolute;
right: 20px;
top: 20px;
overflow: hidden;
border: none;
background: url(../img/cross.png) no-repeat center center;
text-indent: 200%;
color: transparent;
outline: none;
z-index: 100;
}
/* Menu style */
.overlay nav {
text-align: center;
position: relative;
top: 50%;
height: 60%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.overlay ul {
list-style: none;
padding: 0;
margin: 0 auto;
display: inline-block;
height: 100%;
position: relative;
}
.overlay ul li {
display: block;
height: 20%;
height: calc(100% / 5);
min-height: 54px;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.overlay ul li a {
font-size: 54px;
font-weight: 300;
display: block;
color: #fff;
-webkit-transition: color 0.2s;
transition: color 0.2s;
}
.overlay ul li a:hover,
.overlay ul li a:focus {
color: #e3fcb1;
}
/* Effects */
.overlay-slidedown {
visibility: hidden;
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
-webkit-transition: -webkit-transform 0.4s ease-in-out, visibility 0s 0.4s;
transition: transform 0.4s ease-in-out, visibility 0s 0.4s;
}
.overlay-slidedown.open {
visibility: visible;
-webkit-transform: translateY(0%);
transform: translateY(0%);
-webkit-transition: -webkit-transform 0.4s ease-in-out;
transition: transform 0.4s ease-in-out;
}
#media screen and (max-height: 30.5em) {
.overlay nav {
height: 70%;
font-size: 34px;
}
.overlay ul li {
min-height: 34px;
}
}
Now it works perfectly, thanks to all.
Next thing i have to do is separate overlay of buttom component. and keep it running, but im wondering to to pass the action to one component to another.... i have to learn more about react.js

Dynamically resizing sprite images with CSS

I'm trying to make the image on the left of the following page resize like the images on the right when the browser window is made smaller/bigger:
http://www.hugoproject.com/test.html
I am using a sprite for the image on the left. My code is as follows:
HTML
<div id="home-projects">
<div id="projects">
<div class="project-group">
<div class="project">
Arrow<span></span>
</div>
</div>
</div>
CSS
#home-projects {
text-align: center;
overflow: hidden;
position: relative;
}
#projects {
width: 100%;
}
.project-group {
width: 100%;
height: 100%;
position: absolute;
}
.project {
float: left;
text-align: center;
width: 33.3%;
}
.project-link {
background-size: cover;
background-repeat: no-repeat;
background-position: center;
background-color: #adadad;
position: relative;
overflow: hidden;
display: inline-block;
width: 80%;
}
.circle .project-link, .circle .project-link .hover {
border-radius: 100%;
-moz-border-radius: 100%;
-webkit-border-radius: 100%;
}
.project-link .hexagon-top {
content: '';
display: block;
position: absolute;
left: 0;
border-style: solid;
border-bottom-color: transparent;
border-left-color: #dfdfdf;
border-right-color: #dfdfdf;
width: 0;
height: 0;
z-index: 2;
}
.project-link .hexagon-bottom {
content: '';
display: block;
position: absolute;
left: 0;
bottom: 0;
border-style: solid;
border-top-color: transparent;
border-left-color: #dfdfdf;
border-right-color: #dfdfdf;
width: 0;
height: 0;
z-index: 2;
}
.project-link .hover {
position: absolute;
width: 100%;
height: 100%;
font-size: 14px;
text-align: center;
color: #fff;
background: #ec6136;
text-decoration: none;
text-transform: uppercase;
display: block;
opacity: 0;
transition: all .3s;
-moz-transition: all .3s;
-webkit-transitin: all .3s;
}
.project-link .hover-text {
display: block;
margin-top: 45%;
}
.project-link .hover-text:after {
content: '>';
font-family: 'icon';
font-size: 12px;
margin-left: 15px;
}
.project-link:hover > .hover {
opacity: .9;
}
.HS {
display: inline-block;
position: relative;
text-indent: -9999px;
width: 283px;
height: 213px;
background: url(http://www.hugoproject.com/ftp1/images/icons.png) no-repeat;
}
.HS span {
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
background: url(http://www.hugoproject.com/ftp1/images/icons.png) no-repeat;
background-position: 0 -214px;
opacity: 0;
-webkit-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
-o-transition: opacity 0.5s;
}
.HS:hover span {
opacity: 1;
}
What am I doing wrong?
This resizes it like you want (in Firefox at least, haven't tested elsewhere). Mainly have to use %'s, not fixed size in order to scale.
.HS {
display: inline-block;
position: relative;
text-indent: -9999px;
width: 100%;
height: 75%;
background-image: url("http://www.hugoproject.com/ftp1/images/icons.png");
background-position: 0px 0px;
background-size: 800%;
}
.HS span {
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
background-image: url("http://www.hugoproject.com/ftp1/images/icons.png");
background-position: 0px -100%;
opacity: 0;
width: 100%;
height: 100%;
background-size: 800%;
-webkit-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
-o-transition: opacity 0.5s;
}
.project {
float: left;
text-align: center;
width: 33.3%;
height:100%;
}
Another, possibly better, option would be to actually crop your PNG into separate images rather than selecting the position so that you can use the same CSS as with your other images.