I want to move my hamburger menu icon on the mobile to the right side of the screen. Currently it resides on the left. I have tried but couldn't find a way to move it to right. As I am not a CSS and HTML expert, I really need to do this but i am stuck. I am posting the html and CSS code below please have look. Can anyone suggest a way to do this?
`/* Hamburger Menu */
/* Mixin */
/* reset */
* {
padding: 0;
margin: 0;
}
nav {
background-color: #91cfa1;
height: 50px;
padding: 0 16px;
display: -ms-flexbox;
display: -webkit-box;
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
/* fade in checked menu */
}
nav .m-menu__checkbox {
display: none;
}
nav label.m-menu__toggle {
cursor: pointer;
}
nav .m-menu {
position: absolute;
top: 0;
left: 0;
max-width: 450px;
width: calc(100vw - 30px);
height: 100%;
-moz-transform: translate3d(-450px, 0, 0);
-o-transform: translate3d(-450px, 0, 0);
-ms-transform: translate3d(-450px, 0, 0);
-webkit-transform: translate3d(-450px, 0, 0);
transform: translate3d(-450px, 0, 0);
-moz-transition: transform 0.35s;
-o-transition: transform 0.35s;
-webkit-transition: transform 0.35s;
transition: transform 0.35s;
z-index: 1;
overflow: hidden;
background-color: #fff;
}
nav .m-menu__overlay {
background-color: rgba(103, 103, 103, 0.5);
position: absolute;
top: 0;
width: 100%;
bottom: 0;
z-index: 1;
display: none;
}
nav .m-menu__header {
padding: 0 16px;
height: 50px;
display: -ms-flexbox;
display: -webkit-box;
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-around;
justify-content: space-around;
-ms-flex-pack: space-around;
-webkit-align-items: center;
align-items: center;
border-bottom: 1px solid #e8e8e8;
}
nav .m-menu__header span {
font-size: 1.2rem;
font-weight: bold;
text-align: center;
width: 100%;
}
nav .m-menu .m-menu {
-moz-transform: translate3d(480px, 0, 0);
-o-transform: translate3d(480px, 0, 0);
-ms-transform: translate3d(480px, 0, 0);
-webkit-transform: translate3d(480px, 0, 0);
transform: translate3d(480px, 0, 0);
}
nav .m-menu ul {
height: 100%;
overflow-y: auto;
}
nav .m-menu ul li a, nav .m-menu ul li label {
display: block;
text-align: left;
padding: 0 15px;
line-height: 47px;
text-decoration: none;
color: #333;
cursor: pointer;
font-size: 1rem;
border-bottom: 1px solid #e8e8e8;
position: relative;
}
nav .m-menu ul li label.a-label__chevron::after {
content: "";
position: absolute;
display: inline-block;
height: 10px;
width: 10px;
border-color: #333;
border-style: solid;
border-width: 1px 1px 0 0;
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
top: 50%;
margin-top: -5px;
right: 16px;
}
nav .m-menu ul li .-invisible {
border-bottom: 0;
}
nav .m-menu .m-menu label.m-menu__toggle {
display: -ms-flexbox;
display: -webkit-box;
display: -webkit-flex;
display: flex;
border-bottom: 0;
padding: 0;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
nav .m-menu__checkbox:checked ~ .m-menu__overlay {
display: block;
}
nav .m-menu__checkbox:checked ~ .m-menu {
-moz-transform: translate3d(0, 0, 0);
-o-transform: translate3d(0, 0, 0);
-ms-transform: translate3d(0, 0, 0);
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.wrapper {
width: 480px;
height: 667px;
margin: 0 auto;
overflow: hidden;
background-color: #fff;
position: relative;
}
body {
background-color: #f1f1f1;
padding: 0;
margin: 0;
font-family: sans-serif;
}
<div class="wrapper">
<nav>
<input type="checkbox" id="menu" name="menu" class="m-menu__checkbox">
<label class="m-menu__toggle" for="menu">
<svg width="35" height="35" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="butt" stroke-linejoin="arcs"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>
</label>
<label class="m-menu__overlay" for="menu"></label>
<div class="m-menu">
<div class="m-menu__header">
<label class="m-menu__toggle" for="menu">
<svg width="35" height="35" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="butt" stroke-linejoin="arcs">
<line x1="18" y1="6" x2="6" y2="18"></line>
<line x1="6" y1="6" x2="18" y2="18"></line>
</svg>
</label>
<span>MENU</span>
</div>
<ul>
<li><label>Item 1</label></li>
<li>
<label class="a-label__chevron" for="item-2">Item 2</label>
<input type="checkbox" id="item-2" name="item-2" class="m-menu__checkbox">
<div class="m-menu">
<div class="m-menu__header">
<label class="m-menu__toggle" for="item-2">
<svg width="35" height="35" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="butt" stroke-linejoin="arcs">
<path d="M19 12H6M12 5l-7 7 7 7"/>
</svg>
</label>
<span>Item 2</span>
</div>
<ul>
<li><label>Item 2.1</label></li>
<li><label>Item 2.2</label></li>
<li>
<label class="a-label__chevron" for="item-2-3">Item 2.3</label>
<input type="checkbox" id="item-2-3" name="item-2" class="m-menu__checkbox">
<div class="m-menu">
<div class="m-menu__header">
<label class="m-menu__toggle" for="item-2-3">
<svg width="35" height="35" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="butt" stroke-linejoin="arcs">
<path d="M19 12H6M12 5l-7 7 7 7"/>
</svg>
</label>
<span>Item 2.3 </span>
</div>
<ul>
<li><label>Item 2.3.1</label></li>
<li><label>Item 2.3.2</label></li>
<li><label>Item 2.3.3</label></li>
<li><label>Item 2.3.4</label></li>
<li><label>Item 2.3.5</label></li>
</ul>
</li>
<li><label>Item 2.4</label></li>
<li><label>Item 2.5</label></li>
<li><label>Item 2.6</label></li>
<li><label>Item 2.7</label></li>
<li><label>Item 2.8</label></li>
<li><label>Item 2.9</label></li>
</div>
</li>
<li><label>Item 3</label></li>
<li><label>Item 4</label></li>
<li><label>Item 5</label></li>
<li><label>Item 6</label></li>
</ul>
</div>
</nav>
</div>
Apply margin-left: auto to your m-menu__toggle class.
Related
I am new into web development, I am learning CSS right now. I have chosen as project for beginning my personal portfolio.
I am creating an easy navigation bar, I wanted to add hamburger Icon, but when I have added Icon to navbar the icon is stack at the bottom of the navbar and the animation(the lines are crossed like X, when button is toggled). I want the Icon in the left corner of the navbar.
I have tried to add the Icon outside the list, to nav but it overflow <h1> tag, so I have tried to add to <aside> parent, but it overflows the <h1> tag as well.
body {
background: linear-gradient(180deg, rgb(70, 65, 70), rgb(172, 34, 32));
}
.menu {
border: 2px solid white;
position: sticky;
display: flex;
flex-direction: row;
height: 95vh;
width: 17%;
background: linear-gradient(180deg, #241023ff, #6b0504ff);
/*linear-gradient(180deg, #2274a5ff, #f75c03ff);*/
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
transition: 0.5s;
}
.wrapper {
width: 100%;
margin: auto;
display: flex;
justify-content: flex-start;
}
.container {
margin-top: 10px;
width: 100%;
height: 25px;
margin-bottom: 10px;
display: flex;
flex-direction: column;
justify-content: space-between;
cursor: pointer;
}
.menu-logo {
height: 3px;
width: 30px;
background-color: white;
}
.showmenu {
width: 25%;
}
/* #endregion Toggle button animation*/
/* #region Hover effect*/
nav:hover,
nav:active {
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
li a:hover,
li a:active {
font-weight: bold;
border: 1px solid white;
border-radius: 10px;
background: rgb(246, 246, 246);
transition: 0.5s;
}
li a:hover svg,
li a:active svg {
fill: #f75c03ff;
}
li a:hover span,
li a:active span {
color: #f75c03ff;
stroke: #f75c03ff;
}
/* #endregion Hover effect*/
nav {
width: 100%;
display: list-item;
text-align: center;
justify-content: center;
}
/* #region Welcome text*/
nav .welcome-text {
width: 100%;
margin-left: auto;
display: flex;
justify-content: center;
font-size: 3.5vw;
margin-bottom: 60px;
color: white;
text-align: center;
}
/* #endregion Welcome text*/
/* #region Main content*/
/* #region Wave animation*/
.wave {
width: 50%;
animation-name: wave-animation;
/* Refers to the name of your #keyframes element below */
animation-duration: 2.5s;
/* Change to speed up or slow down */
animation-iteration-count: infinite;
/* Never stop waving :) */
transform-origin: 70% 70%;
/* Pivot around the bottom-left palm */
display: inline-block;
}
#keyframes wave-animation {
0% {
transform: rotate( 0.0deg)
}
10% {
transform: rotate(14.0deg)
}
/* The following five values can be played with to make the waving more or less extreme */
20% {
transform: rotate(-8.0deg)
}
30% {
transform: rotate(14.0deg)
}
40% {
transform: rotate(-4.0deg)
}
50% {
transform: rotate(10.0deg)
}
60% {
transform: rotate( 0.0deg)
}
/* Reset for the last half to pause */
100% {
transform: rotate( 0.0deg)
}
}
/* #endregion Wave animation*/
nav ul {
width: 100%;
height: 100%;
display: list-item;
}
nav ul li {
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
}
li a {
width: 100%;
height: 7%;
text-decoration: none;
display: flex;
text-align: left;
font-size: 100%;
justify-content: center;
margin-bottom: 10px;
}
li a span {
width: 100%;
font-size: 2.7vw;
align-self: center;
color: white;
margin-left: 10px;
}
li a svg {
width: 20%;
height: 20%;
}
<aside class="menu">
<div class="container nav-container">
<input class="checkbox" type="checkbox" name="" id="" />
<div class="hamburger-lines">
<span class="line line1"></span>
<span class="line line2"></span>
<span class="line line3"></span>
</div>
</div>
<nav>
<ul>
<li>
<h1 class="welcome-text">Welcome <span class="wave">👋</span></h1>
</li>
<li>
<a href="#">
<svg viewBox="0 0 24 24" fill="transparent" stroke="white" xmlns="http://www.w3.org/2000/svg">
<path
d="M21 8.77217L14.0208 1.79299C12.8492 0.621414 10.9497 0.621413 9.77817 1.79299L3 8.57116V23.0858H10V17.0858C10 15.9812 10.8954 15.0858 12 15.0858C13.1046 15.0858 14 15.9812 14 17.0858V23.0858H21V8.77217ZM11.1924 3.2072L5 9.39959V21.0858H8V17.0858C8 14.8767 9.79086 13.0858 12 13.0858C14.2091 13.0858 16 14.8767 16 17.0858V21.0858H19V9.6006L12.6066 3.2072C12.2161 2.81668 11.5829 2.81668 11.1924 3.2072Z" />
</svg>
<span>Home</span>
</a>
</li>
</ul>
</nav>
</aside>
Full code here:
https://jsfiddle.net/Lhawck59/
<div class="hamburger-lines">,
You didn't write a closing tag for this tag, so your code didn't work
you can add oppacity: 0; on the class menu, and add oppacity: 1; on the class showmenu
var logo = document.querySelector('.container');
var menu = document.querySelector('.menu');
logo.addEventListener('click',function(){
menu.classList.toggle('showmenu');
});
body {
background: linear-gradient(180deg, rgb(70, 65, 70), rgb(172, 34, 32));
}
.menu {
border: 2px solid white;
position: sticky;
display: flex;
flex-direction: row;
height: 95vh;
width: 17%;
background: linear-gradient(180deg, #241023ff, #6b0504ff);
/*linear-gradient(180deg, #2274a5ff, #f75c03ff);*/
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
transition: 0.5s;
opacity: 0;
}
/* #region Toggle button animation*/
.wrapper {
width: 100%;
margin: auto;
display: flex;
justify-content: flex-start;
}
.container {
margin-top: 10px;
width: 100%;
height: 25px;
margin-bottom: 10px;
display: flex;
flex-direction: column;
justify-content: space-between;
cursor: pointer;
}
.menu-logo {
height: 3px;
width: 30px;
background-color: white;
}
.showmenu {
width: 25%;
opacity: 1;
}
/* #endregion Toggle button animation*/
/* #region Hover effect*/
nav:hover,
nav:active {
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
li a:hover,
li a:active {
font-weight: bold;
border: 1px solid white;
border-radius: 10px;
background: rgb(246, 246, 246);
transition: 0.5s;
}
li a:hover svg,
li a:active svg {
fill: #f75c03ff;
}
li a:hover span,
li a:active span {
color: #f75c03ff;
stroke: #f75c03ff;
}
/* #endregion Hover effect*/
nav {
width: 100%;
display: list-item;
text-align: center;
justify-content: center;
}
/* #region Welcome text*/
nav .welcome-text {
width: 100%;
margin-left: auto;
display: flex;
justify-content: center;
font-size: 3.5vw;
margin-bottom: 60px;
color: white;
text-align: center;
}
/* #endregion Welcome text*/
/* #region Main content*/
/* #region Wave animation*/
.wave {
width: 50%;
animation-name: wave-animation;
/* Refers to the name of your #keyframes element below */
animation-duration: 2.5s;
/* Change to speed up or slow down */
animation-iteration-count: infinite;
/* Never stop waving :) */
transform-origin: 70% 70%;
/* Pivot around the bottom-left palm */
display: inline-block;
}
#keyframes wave-animation {
0% {
transform: rotate(0.0deg)
}
10% {
transform: rotate(14.0deg)
}
/* The following five values can be played with to make the waving more or less extreme */
20% {
transform: rotate(-8.0deg)
}
30% {
transform: rotate(14.0deg)
}
40% {
transform: rotate(-4.0deg)
}
50% {
transform: rotate(10.0deg)
}
60% {
transform: rotate(0.0deg)
}
/* Reset for the last half to pause */
100% {
transform: rotate(0.0deg)
}
}
/* #endregion Wave animation*/
nav ul {
width: 100%;
height: 100%;
display: list-item;
}
nav ul li {
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
}
li a {
width: 100%;
height: 7%;
text-decoration: none;
display: flex;
text-align: left;
font-size: 100%;
justify-content: center;
margin-bottom: 10px;
}
li a span {
width: 100%;
font-size: 2.7vw;
align-self: center;
color: white;
margin-left: 10px;
}
li a svg {
width: 20%;
height: 20%;
}
/* #endregion Main content*/
/* #region footer of navbar*/
ul li div {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 7%;
display: flex;
flex-direction: row;
text-align: left;
justify-content: flex-start;
}
li div img {
width: auto;
height: auto;
border-radius: 50%;
border: 2px solid white;
}
nav div span {
width: 100%;
font-size: 0;
align-self: center;
color: white;
margin-left: 10px;
font-weight: bolder;
}
/* #endregion footer of navbar*/
/*TEST*/
.nav-container {
display: flex;
justify-content: space-between;
align-items: left;
width: 5%;
}
.nav-container .checkbox {
position: absolute;
display: block;
width: 5%;
z-index: 5;
opacity: 0;
cursor: pointer;
}
.nav-container .hamburger-lines {
display: block;
height: 26px;
width: 32px;
position: absolute;
z-index: 2;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.nav-container .hamburger-lines .line {
display: block;
height: 4px;
width: 100%;
border-radius: 10px;
background: rgb(255, 255, 255);
}
.nav-container .hamburger-lines .line1 {
transform-origin: 0% 0%;
transition: transform 0.4s ease-in-out;
}
.nav-container .hamburger-lines .line2 {
transition: transform 0.2s ease-in-out;
}
.nav-container .hamburger-lines .line3 {
transform-origin: 0% 100%;
transition: transform 0.4s ease-in-out;
}
.nav-container input[type="checkbox"]:checked ~ .menu-items {
transform: translateX(0);
}
.nav-container input[type="checkbox"]:checked ~ .hamburger-lines .line1 {
transform: rotate(45deg);
}
.nav-container input[type="checkbox"]:checked ~ .hamburger-lines .line2 {
transform: scaleY(0);
}
.nav-container input[type="checkbox"]:checked ~ .hamburger-lines .line3 {
transform: rotate(-45deg);
}
.nav-container input[type="checkbox"]:checked ~ .logo{
display: none;
}
*{
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
/*font-family: 'Noto Sans', sans-serif;*/
}
header{
border: 1px solid black;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/content/content.css">
<link rel="stylesheet" href="css/navbar/navbar.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght#0,100;0,700;1,300;1,500&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="css/navbar/hamburgerIcon/hamburgerIcon.css">
<title>Portfolio</title>
</head>
<body>
<header>
<h1>Header</h1>
<div class="container nav-container">
<input class="checkbox" type="checkbox" name="" id="" />
<div class="hamburger-lines">
<span class="line line1"></span>
<span class="line line2"></span>
<span class="line line3"></span>
</div>
</header>
<aside class="menu">
<nav>
<ul>
<li>
<h1 class="welcome-text">Welcome <span class="wave">👋</span></h1>
</li>
<li>
<a href="#">
<svg viewBox="0 0 24 24" fill="transparent" stroke="white" xmlns="http://www.w3.org/2000/svg">
<path d="M21 8.77217L14.0208 1.79299C12.8492 0.621414 10.9497 0.621413 9.77817 1.79299L3 8.57116V23.0858H10V17.0858C10 15.9812 10.8954 15.0858 12 15.0858C13.1046 15.0858 14 15.9812 14 17.0858V23.0858H21V8.77217ZM11.1924 3.2072L5 9.39959V21.0858H8V17.0858C8 14.8767 9.79086 13.0858 12 13.0858C14.2091 13.0858 16 14.8767 16 17.0858V21.0858H19V9.6006L12.6066 3.2072C12.2161 2.81668 11.5829 2.81668 11.1924 3.2072Z" />
</svg>
<span>Home</span>
</a>
</li>
<li>
<a href="#">
<svg fill="transparent" stroke="white" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M21 2H6a2 2 0 0 0-2 2v3H2v2h2v2H2v2h2v2H2v2h2v3a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1V3a1 1 0 0 0-1-1zm-8 2.999c1.648 0 3 1.351 3 3A3.012 3.012 0 0 1 13 11c-1.647 0-3-1.353-3-3.001 0-1.649 1.353-3 3-3zM19 18H7v-.75c0-2.219 2.705-4.5 6-4.5s6 2.281 6 4.5V18z" />
</svg>
<span>Contact</span>
</a>
</li>
<li>
<a href="#">
<svg fill="transparent" stroke="white" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M17 7C17 5.34315 15.6569 4 14 4H10C8.34315 4 7 5.34315 7 7H6C4.34315 7 3 8.34315 3 10V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V10C21 8.34315 19.6569 7 18 7H17ZM14 6H10C9.44772 6 9 6.44772 9 7H15C15 6.44772 14.5523 6 14 6ZM6 9H18C18.5523 9 19 9.44772 19 10V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V10C5 9.44772 5.44772 9 6 9Z" />
</svg>
<span>My work</span>
</a>
</li>
<li>
<a href="#">
<svg fill="transparent" stroke="white" xmlns="http://www.w3.org/2000/svg" class="bi bi-chat-dots-fill" viewBox="0 0 16 16">
<path d="M16 8c0 3.866-3.582 7-8 7a9.06 9.06 0 0 1-2.347-.306c-.584.296-1.925.864-4.181 1.234-.2.032-.352-.176-.273-.362.354-.836.674-1.95.77-2.966C.744 11.37 0 9.76 0 8c0-3.866 3.582-7 8-7s8 3.134 8 7zM5 8a1 1 0 1 0-2 0 1 1 0 0 0 2 0zm4 0a1 1 0 1 0-2 0 1 1 0 0 0 2 0zm3 1a1 1 0 1 0 0-2 1 1 0 0 0 0 2z" />
</svg>
<span>References</span>
</a>
</li>
<li>
<a href="#">
<svg xmlns="http://www.w3.org/2000/svg" fill="white" class="bi bi-person-circle" viewBox="0 0 16 16">
<path d="M11 6a3 3 0 1 1-6 0 3 3 0 0 1 6 0z" />
<path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-5.468 11.37C3.242 11.226 4.805 10 8 10s4.757 1.225 5.468 2.37A7 7 0 0 0 8 1z" />
</svg>
<span>About</span>
</a>
</li>
</ul>
</nav>
</aside>
<script src="js/script.js"></script>
</body>
</html>
I have this structure and it works perfectly only in chrome!!:
.audio-controls {
display: none;
flex-direction: row;
gap: 1226px;
justify-content: center;
width: 100%;
position: absolute;
top: 82%;
left: 0%;
z-index: 99;
}
.prompt {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
cursor: not-allowed;
background: #000000;
border-radius: 35px;
}
.prompt .stim {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 124px;
width: 126px;
border-radius: 30%;
background: linear-gradient(#1f1f20, #040404);
transform: translateY(-6px);
overflow: hidden;
box-shadow: 0px 9px 3px #000000, 0 10px 20px rgb(0 0 0 / 25%);
}
.prompt .stim::before {
content: "";
opacity: 0.35;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
background-image: url(../img/hexellence.png);
}
.audio-controls .record {
transform: translate(0px, 40px);
zoom: 0.042;
}
.prompt .stim p {
transition: color 0.05s ease;
}
.stim p {
color: #b9b7b7;
font-family: "Open Sans Regular";
font-size: .7em;
margin-bottom: 4px;
transition: color 0.1s ease-in-out;
z-index: 1;
}
<div class="audio-controls" style="display: flex;">
<div id="start-recognition" class="prompt activated">
<div class="record-dot record-dot-position on" style="transform: translateY(-6px);"></div>
<div class="record-dot-container record-dot-position" style="transform: translateY(-6px);"></div>
<div class="stim">
<svg class="record" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" enable-background="new 0 0 1000 1000" xml:space="preserve" style="fill: rgb(123, 55, 32);" width="1000" height="1000">
<rect id="backgroundrect" width="100%" height="100%" x="0" y="0" fill="none" stroke="none"></rect>
<g class="currentLayer" style="">
<g id="svg_1" class="selected" fill="#dadada" fill-opacity="1">
<path d="M500,683.8c84.6,0,153.1-68.6,153.1-153.1V163.1C653.1,78.6,584.6,10,500,10c-84.6,0-153.1,68.6-153.1,153.1v367.5C346.9,615.2,415.4,683.8,500,683.8z M714.4,438.8v91.9C714.4,649,618.4,745,500,745c-118.4,0-214.4-96-214.4-214.4v-91.9h-61.3v91.9c0,141.9,107.2,258.7,245,273.9v124.2H346.9V990h306.3v-61.3H530.6V804.5c137.8-15.2,245-132.1,245-273.9v-91.9H714.4z" id="record-icon" fill="#dadada57" style="fill: rgba(218, 218, 218, 0.34);"></path>
</g>
</g>
</svg>
<p id="record-icon-text" style="color: rgb(185, 183, 183);">Hold Space Key</p>
</div>
</div>
</div>
The issue is in the above code I used zoom here:
.audio-controls .record {
transform: translate(0px, 40px);
zoom: 0.042;
}
And zoom is not working in Firefox so it only works in chrome.
In order to make this work I need to use scale instead right? I used scale in the below snippet but I ruined the graphic !
Have a look: ( I only removed zoom and replaces scale here)
.audio-controls {
display: none;
flex-direction: row;
gap: 1226px;
justify-content: center;
width: 100%;
position: absolute;
top: 82%;
left: 0%;
z-index: 99;
}
.prompt {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
cursor: not-allowed;
background: #000000;
border-radius: 35px;
}
.prompt .stim {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 124px;
width: 126px;
border-radius: 30%;
background: linear-gradient(#1f1f20, #040404);
transform: translateY(-6px);
overflow: hidden;
box-shadow: 0px 9px 3px #000000, 0 10px 20px rgb(0 0 0 / 25%);
}
.prompt .stim::before {
content: "";
opacity: 0.35;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
background-image: url(../img/hexellence.png);
}
.audio-controls .record {
transform: scale(0.042) translate(0px, 40px);
/*zoom: 0.042;*/
}
.prompt .stim p {
transition: color 0.05s ease;
}
.stim p {
color: #b9b7b7;
font-family: "Open Sans Regular";
font-size: .7em;
margin-bottom: 4px;
transition: color 0.1s ease-in-out;
z-index: 1;
}
<div class="audio-controls" style="display: flex;">
<div id="start-recognition" class="prompt activated">
<div class="record-dot record-dot-position on" style="transform: translateY(-6px);"></div>
<div class="record-dot-container record-dot-position" style="transform: translateY(-6px);"></div>
<div class="stim">
<svg class="record" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" enable-background="new 0 0 1000 1000" xml:space="preserve" style="fill: rgb(123, 55, 32);" width="1000" height="1000">
<rect id="backgroundrect" width="100%" height="100%" x="0" y="0" fill="none" stroke="none"></rect>
<g class="currentLayer" style="">
<g id="svg_1" class="selected" fill="#dadada" fill-opacity="1">
<path d="M500,683.8c84.6,0,153.1-68.6,153.1-153.1V163.1C653.1,78.6,584.6,10,500,10c-84.6,0-153.1,68.6-153.1,153.1v367.5C346.9,615.2,415.4,683.8,500,683.8z M714.4,438.8v91.9C714.4,649,618.4,745,500,745c-118.4,0-214.4-96-214.4-214.4v-91.9h-61.3v91.9c0,141.9,107.2,258.7,245,273.9v124.2H346.9V990h306.3v-61.3H530.6V804.5c137.8-15.2,245-132.1,245-273.9v-91.9H714.4z" id="record-icon" fill="#dadada57" style="fill: rgba(218, 218, 218, 0.34);"></path>
</g>
</g>
</svg>
<p id="record-icon-text" style="color: rgb(185, 183, 183);">Hold Space Key</p>
</div>
</div>
</div>
How can I fix using scale ?
How do I shift the content over to the next row when browser width is 915px?
This is what I have now:
<div class="body">
<div class="container">
<div class="card">
<div class="box">
<div class="percent">
<svg>
<circle cx="70" cy="70" r="70"></circle>
<circle cx="70" cy="70" r="70"></circle>
</svg>
<div class="number">
<h2>90<span>%</span></h2>
</div>
</div>
<h2 class="text">Html</h2>
</div>
</div>
<div class="card">
<div class="box">
<div class="percent">
<svg>
<circle cx="70" cy="70" r="70"></circle>
<circle cx="70" cy="70" r="70"></circle>
</svg>
<div class="number">
<h2>85<span>%</span></h2>
</div>
</div>
<h2 class="text">CSS</h2>
</div>
</div>
<div class="card">
<div class="box">
<div class="percent">
<svg>
<circle cx="70" cy="70" r="70"></circle>
<circle cx="70" cy="70" r="70"></circle>
</svg>
<div class="number">
<h2>60<span>%</span></h2>
</div>
</div>
<h2 class="text">Javascript</h2>
</div>
</div>
</div>
</div>
And my css
.body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
display: flex;
justify-content: space-around;
}
.container .card {
margin-left: 20px;
position: relative;
width: 250px;
background: #222;
background: linear-gradient(0deg, #1b1b1b, #222, #1b1b1b);
display: flex;
justify-content: center;
align-items: center;
height: 300px;
border-radius: 4px;
text-align: center;
overflow: hidden;
transition: 0.5s;
}
.container .card:hover {
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
transform: translateY(-10px);
}
.container .card:before {
content: "";
position: absolute;
top: 0;
left: -50%;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.03);
pointer-events: none;
z-index: 1;
}
.percent {
position: relative;
width: 150px;
height: 150px;
border-radius: 50%;
box-shadow: inset 0 0 50px #000;
background: #222;
z-index: 100;
}
.percent .number {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
}
.percent .number h2 {
color: #777;
font-weight: 700;
font-size: 40px;
transition: 0.5s;
}
.card:hover .percent .number h2 {
color: #fff;
font-size: 60px;
}
.percent .number h2 span {
font-size: 24px;
color: #777;
}
.text {
color: #777;
margin-top: 20px;
font-weight: 700;
font-size: 18px;
letter-spacing: 1px;
text-transform: uppercase;
transition: 0.5s;
}
.card:hover .text {
color: #fff;
}
svg {
position: relative;
width: 150px;
height: 150px;
z-index: 1000;
}
circle {
width: 100%;
height: 100%;
fill: none;
stroke: #191919;
stroke-width: 10;
stroke-linecap: round;
transform: translate(5px, 5px);
}
circle:nth-child(2) {
stroke-dasharray: 440;
stroke-dashoffset: 440;
}
.card:nth-child(1) svg circle:nth-child(2) {
stroke-dashoffset: calc(440 - (440 * 90) / 100);
stroke: #00ff43;
}
.card:nth-child(2) svg circle:nth-child(2) {
stroke-dashoffset: calc(440 - (440 * 85) / 100);
stroke: #00a1ff;
}
.card:nth-child(3) svg circle:nth-child(2) {
stroke-dashoffset: calc(440 - (440 * 60) / 100);
stroke: #c104ff;
}
#media only screen and (max-width: 915px) {
/* your css of 1024 px screen size */
.card {
flex: 10% !important;
}
}
How do I make the content shift downwards when on 915px browser width so it looks good on mobile. I've tried flex, change display, change width but nothing works. I don't know if it has to do with any of that but I'd appreciate the help.
You can use the grid layout. First, set the container to display: grid;. After you can set how your grid will be with the grid-template-columns: 1fr; (1fr = one column, 1fr 1fr = 2 column, 1fr 2fr = 2 column, but the right one is bigger... etc). After that, you can add gap: 1rem; to have a gap between you column and row.
The Grid Documentation on W3School
Here is a example:
.body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
display: flex;
justify-content: space-around;
}
.container .card {
margin-left: 20px;
position: relative;
width: 250px;
background: #222;
background: linear-gradient(0deg, #1b1b1b, #222, #1b1b1b);
display: flex;
justify-content: center;
align-items: center;
height: 300px;
border-radius: 4px;
text-align: center;
overflow: hidden;
transition: 0.5s;
}
.container .card:hover {
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
transform: translateY(-10px);
}
.container .card:before {
content: "";
position: absolute;
top: 0;
left: -50%;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.03);
pointer-events: none;
z-index: 1;
}
.percent {
position: relative;
width: 150px;
height: 150px;
border-radius: 50%;
box-shadow: inset 0 0 50px #000;
background: #222;
z-index: 100;
}
.percent .number {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
}
.percent .number h2 {
color: #777;
font-weight: 700;
font-size: 40px;
transition: 0.5s;
}
.card:hover .percent .number h2 {
color: #fff;
font-size: 60px;
}
.percent .number h2 span {
font-size: 24px;
color: #777;
}
.text {
color: #777;
margin-top: 20px;
font-weight: 700;
font-size: 18px;
letter-spacing: 1px;
text-transform: uppercase;
transition: 0.5s;
}
.card:hover .text {
color: #fff;
}
svg {
position: relative;
width: 150px;
height: 150px;
z-index: 1000;
}
circle {
width: 100%;
height: 100%;
fill: none;
stroke: #191919;
stroke-width: 10;
stroke-linecap: round;
transform: translate(5px, 5px);
}
circle:nth-child(2) {
stroke-dasharray: 440;
stroke-dashoffset: 440;
}
.card:nth-child(1) svg circle:nth-child(2) {
stroke-dashoffset: calc(440 - (440 * 90) / 100);
stroke: #00ff43;
}
.card:nth-child(2) svg circle:nth-child(2) {
stroke-dashoffset: calc(440 - (440 * 85) / 100);
stroke: #00a1ff;
}
.card:nth-child(3) svg circle:nth-child(2) {
stroke-dashoffset: calc(440 - (440 * 60) / 100);
stroke: #c104ff;
}
#media only screen and (max-width: 915px) {
/* your css of 1024 px screen size */
.card {
flex: 10% !important;
}
.grid-class{
display: grid;
grid-template-columns: 1fr;
gap: 1rem;
}
}
<div class="body">
<div class="container grid-class">
<div class="card">
<div class="box">
<div class="percent">
<svg>
<circle cx="70" cy="70" r="70"></circle>
<circle cx="70" cy="70" r="70"></circle>
</svg>
<div class="number">
<h2>90<span>%</span></h2>
</div>
</div>
<h2 class="text">Html</h2>
</div>
</div>
<div class="card">
<div class="box">
<div class="percent">
<svg>
<circle cx="70" cy="70" r="70"></circle>
<circle cx="70" cy="70" r="70"></circle>
</svg>
<div class="number">
<h2>85<span>%</span></h2>
</div>
</div>
<h2 class="text">CSS</h2>
</div>
</div>
<div class="card">
<div class="box">
<div class="percent">
<svg>
<circle cx="70" cy="70" r="70"></circle>
<circle cx="70" cy="70" r="70"></circle>
</svg>
<div class="number">
<h2>60<span>%</span></h2>
</div>
</div>
<h2 class="text">Javascript</h2>
</div>
</div>
</div>
</div>
I have a simple settings menu and I want to position the toggle open and close button at the right position:
So far I'm here:
.base {
position: absolute;
max-width: 30em;
background-color: #fff;
padding: 1.125em 1.5em;
font-size: 1.25em;
border-radius: 1rem;
box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.3), 0 0.0625rem 0.125rem rgba(0, 0, 0, 0.2);
}
.base::before {
content: "";
position: absolute;
width: 0;
height: 0;
bottom: 100%;
right: 1.5em;
border: 0.75rem solid transparent;
border-top: none;
border-bottom-color: #fff;
filter: drop-shadow(0 -0.0625rem 0.0625rem rgba(0, 0, 0, 0.1));
}
html {
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 300;
color: #192229;
background: linear-gradient(135deg, #F4F2F3, #BFC6D0);
}
html, body {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
body {
padding: 0 2rem;
}
label {
font-family: "Montserrat", sans-serif;
font-size: 1.2rem;
cursor: pointer;
display: block;
margin: 1em;
}
label > input {
display: none;
}
label span {
color: #6A759B;
}
label i {
display: inline-block;
width: 64px;
height: 40px;
border-radius: 20px;
vertical-align: middle;
transition: 0.25s 0.09s;
position: relative;
background: #deeff7;
}
label i:after {
content: " ";
display: block;
width: 30px;
height: 30px;
top: 5px;
left: 5px;
border-radius: 50%;
background: #fff;
position: absolute;
box-shadow: 1px 2px 4px 0 rgba(0, 0, 0, 0.4);
transition: 0.15s;
}
label > input:checked + i {
background: #1094fb;
}
label > input:checked + i + span {
color: #29316b;
}
label > input:checked + i:after {
transform: translateX(25px);
}
.filter {
position: absolute;
}
.burger {
display: flex;
flex-direction: column;
filter: url(#gooeyness);
padding: 30px;
}
.rect {
background: black;
display: inline-block;
height: 32px;
margin-top: 40px;
transition: transform 500ms;
width: 200px;
}
.rect:nth-child(2) {
transition-delay: 100ms;
}
.rect:nth-child(3) {
transition-delay: 100ms;
}
.burger.active .rect:nth-child(1) {
transform: rotate(-45deg) translateX(-51px) translateY(50px);
}
.burger.active .rect:nth-child(2) {
transform: rotate(45deg);
}
.burger.active .rect:nth-child(3) {
transform: rotate(-45deg) translateX(51px) translateY(-50px);
}
.close {
position: absolute;
cursor: pointer;
transform: scale(0.1);
z-index: 2500;
}
.settings-container {
display: flex;
flex-direction: column;
width: 500px;
justify-content: center;
height: 250px;
align-items: center;
}
<div class="settings-container">
<div class="close">
<svg class="filter" version="1.1">
<defs>
<filter id="gooeyness">
<feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 20 -10" result="gooeyness" />
<feComposite in="SourceGraphic" in2="gooeyness" operator="atop" />
</filter>
</defs>
</svg>
<div class="burger">
<div class="rect"></div>
<div class="rect"></div>
<div class="rect"></div>
</div>
</div>
<div class="base">
<label>
<input class="cb cb1" type="checkbox" name="social" checked/>
<i></i>
<span>آموزش کارت حتی در صورت پاسخ صحیح</span>
</label>
<label>
<input class="cb cb1" type="checkbox" name="social" checked/>
<i></i>
<span>ضبط صدا در صورت استفاده از تشخیص گفتار</span>
</label>
<label>
<input class="cb cb1" type="checkbox" name="social" checked/>
<i></i>
<span>نمایش جلوه های ویژه ی صوتی و بصری</span>
</label>
</div>
</div>
The issue is I don't know how to position the toggle button at the right place! here is where I want it to be:
Notice that here on SO you can not see the button here is a codepen for it:
https://codepen.io/pixy-dixy/pen/OJjJygg?editors=1100
So the fist issue is that your code produces an different to the one you show in your screenshot. The hamburger menu is in a different place as shown in the image below.
But your problem really stems from a few issues in your css. You can see the step by step below or just jump to the full css at the end. The first is to get it to do what your screen shot is showing you need to do this. Please not I have just uncommented out the code so you can see the changes
.close {
/*position: absolute;*/
cursor: pointer;
transform: scale(0.1);
z-index: 2500;
}
.settings-container {
/*display: flex;
flex-direction: column;*/
width: 500px;
justify-content: center;
/*height: 250px;*/
align-items: center;
}
this now produces the below
Then for reference purposes I have added a border to your settings-container to illustrate what is happening.
The code that cause this is the transform: scale(0.1) shown below and commented out.
.close {
/*position: absolute;*/
cursor: pointer;
/*transform: scale(0.1);*/
z-index: 2500;
}
This now produces this result.
Now you can change the burger menu rectangles to the correct size rather than using transform.
.rect {
background: black;
display: inline-block;
height: 5px;
margin-top: 5px;
transition: transform 500ms;
width: 30px;
}
.close {
/*position: absolute;*/
cursor: pointer;
/*transform: scale(0.1);*/
z-index: 2500;
}
This produces the below result
now you can just position the hamburger menu to right.
.close {
display: flex;
justify-content:end;
/*position: absolute;*/
cursor: pointer;
/*transform: scale(0.1);*/
z-index: 2500;
}
it will look like this
final touches add margin (red border is removed as it was only for illustrative purposes). Your filter was also causing layout issues so I have commented it out.
.burger {
margin-bottom: 20px;
margin-right: 35px;
display: flex;
flex-direction: column;
filter: url(#gooeyness);
/*padding: 30px;*/
}
full css with commented our code
.base {
position: absolute;
max-width: 30em;
background-color: #fff;
padding: 1.125em 1.5em;
font-size: 1.25em;
border-radius: 1rem;
box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.3), 0 0.0625rem 0.125rem rgba(0, 0, 0, 0.2);
}
.base::before {
content: "";
position: absolute;
width: 0;
height: 0;
bottom: 100%;
right: 1.5em;
border: 0.75rem solid transparent;
border-top: none;
border-bottom-color: #fff;
filter: drop-shadow(0 -0.0625rem 0.0625rem rgba(0, 0, 0, 0.1));
}
html {
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 300;
color: #192229;
background: linear-gradient(135deg, #F4F2F3, #BFC6D0);
}
html, body {
height: 100%;
display: flex;
justify-content: center;
/*align-items: center;*/
}
body {
padding: 0 2rem;
}
label {
font-family: "Montserrat", sans-serif;
font-size: 1.2rem;
cursor: pointer;
display: block;
margin: 1em;
}
label > input {
display: none;
}
label span {
color: #6A759B;
}
label i {
display: inline-block;
width: 64px;
height: 40px;
border-radius: 20px;
vertical-align: middle;
transition: 0.25s 0.09s;
position: relative;
background: #deeff7;
}
label i:after {
content: " ";
display: block;
width: 30px;
height: 30px;
top: 5px;
left: 5px;
border-radius: 50%;
background: #fff;
position: absolute;
box-shadow: 1px 2px 4px 0 rgba(0, 0, 0, 0.4);
transition: 0.15s;
}
label > input:checked + i {
background: #1094fb;
}
label > input:checked + i + span {
color: #29316b;
}
label > input:checked + i:after {
transform: translateX(25px);
}
.filter {
position: absolute;
}
.burger {
margin-bottom: 20px;
margin-right: 35px;
display: flex;
flex-direction: column;
filter: url(#gooeyness);
/*padding: 30px;*/
}
.rect {
background: black;
display: inline-block;
height: 5px;
margin-top: 5px;
transition: transform 500ms;
width: 30px;
}
.rect:nth-child(2) {
transition-delay: 100ms;
}
.rect:nth-child(3) {
transition-delay: 100ms;
}
.burger.active .rect:nth-child(1) {
transform: rotate(-45deg) translateX(-6px) translateY(6px);
}
.burger.active .rect:nth-child(2) {
transform: rotate(45deg);
}
.burger.active .rect:nth-child(3) {
transform: rotate(-45deg) translateX(6px) translateY(-8px);
}
.close {
display: flex;
justify-content:end;
/*position: absolute;*/
cursor: pointer;
/*transform: scale(0.1);*/
z-index: 2500;
}
.border{
border:1px solid red;
}
.settings-container {
/*display: flex;
flex-direction: column;*/
width: 500px;
/*justify-content: center;
height: 250px;
align-items: center;*/
}
MDN
CSS positioning is used here to place the element in the desired spot.
Notice that I added position: relative to .settings-container and position: absolute to .close.
The addition of position: relative is used because...
It (the absolutely positioned element) is positioned relative to its closest positioned ancestor, if any;
otherwise, it is placed relative to the initial containing block.
Then the element you are positioning gets position: absolute which will place the element relative to .settings-container which is now the "closest positioned ancestor".
.base {
position: relative;
max-width: 30em;
background-color: #fff;
padding: 1.125em 1.5em;
font-size: 1.25em;
border-radius: 1rem;
box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.3), 0 0.0625rem 0.125rem rgba(0, 0, 0, 0.2);
}
.base::before {
content: "";
position: absolute;
width: 0;
height: 0;
bottom: 100%;
right: 1.5em;
border: 0.75rem solid transparent;
border-top: none;
border-bottom-color: #fff;
filter: drop-shadow(0 -0.0625rem 0.0625rem rgba(0, 0, 0, 0.1));
}
html {
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 300;
color: #192229;
background: linear-gradient(135deg, #F4F2F3, #BFC6D0);
}
html,
body {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
body {
padding: 0 2rem;
}
label {
font-family: "Montserrat", sans-serif;
font-size: 1.2rem;
cursor: pointer;
display: block;
margin: 1em;
}
label>input {
display: none;
}
label span {
color: #6A759B;
}
label i {
display: inline-block;
width: 64px;
height: 40px;
border-radius: 20px;
vertical-align: middle;
transition: 0.25s 0.09s;
position: relative;
background: #deeff7;
}
label i:after {
content: " ";
display: block;
width: 30px;
height: 30px;
top: 5px;
left: 5px;
border-radius: 50%;
background: #fff;
position: absolute;
box-shadow: 1px 2px 4px 0 rgba(0, 0, 0, 0.4);
transition: 0.15s;
}
label>input:checked+i {
background: #1094fb;
}
label>input:checked+i+span {
color: #29316b;
}
label>input:checked+i:after {
transform: translateX(25px);
}
.filter {
position: absolute;
}
.burger {
display: flex;
flex-direction: column;
filter: url(#gooeyness);
padding: 30px;
}
.rect {
background: black;
display: inline-block;
height: 32px;
margin-top: 40px;
transition: transform 500ms;
width: 200px;
}
.rect:nth-child(2) {
transition-delay: 100ms;
}
.rect:nth-child(3) {
transition-delay: 100ms;
}
.burger.active .rect:nth-child(1) {
transform: rotate(-45deg) translateX(-51px) translateY(50px);
}
.burger.active .rect:nth-child(2) {
transform: rotate(45deg);
}
.burger.active .rect:nth-child(3) {
transform: rotate(-45deg) translateX(51px) translateY(-50px);
}
.close {
cursor: pointer;
transform: scale(0.1);
position: absolute; /* added */
top: -170px; /* added */
right: -88px; /* added */
}
.settings-container {
display: flex;
flex-direction: column;
position: relative; /* added */
}
<div class="settings-container">
<div class="close">
<svg class="filter" version="1.1">
<defs>
<filter id="gooeyness">
<feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 20 -10" result="gooeyness" />
<feComposite in="SourceGraphic" in2="gooeyness" operator="atop" />
</filter>
</defs>
</svg>
<div class="burger">
<div class="rect"></div>
<div class="rect"></div>
<div class="rect"></div>
</div>
</div>
<div class="base">
<label>
<input class="cb cb1" type="checkbox" name="social" checked/>
<i></i>
<span>آموزش کارت حتی در صورت پاسخ صحیح</span>
</label>
<label>
<input class="cb cb1" type="checkbox" name="social" checked/>
<i></i>
<span>ضبط صدا در صورت استفاده از تشخیص گفتار</span>
</label>
<label>
<input class="cb cb1" type="checkbox" name="social" checked/>
<i></i>
<span>نمایش جلوه های ویژه ی صوتی و بصری</span>
</label>
</div>
</div>
move it using the position tag in CSS
https://www.w3schools.com/css/css_positioning.asp
Just add position relative to settings-container so the children of this container will count space Regarding to its boundries and then try this.
.base {
position: absolute;
top: 10px: // Change 10px according to your requirement.
right: 10px: // Change 10px according to your requirement.
max-width: 30em;
background-color: #fff;
padding: 1.125em 1.5em;
font-size: 1.25em;
border-radius: 1rem;
box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.3), 0 0.0625rem 0.125rem
rgba(0, 0, 0, 0.2);
}
First, please do not mark this as duplicate, cause I want to ask a little modification from this QnA, here. I'm using this answer to achieve what I want, but it almost meets what I need. Here is his demo.
I am trying to achieve what he did, this is what I've made so far. But, when I click the image, because of the border, it makes the images a little get bigger. What I want is, when the image (checkbox) checked, there are checkboxes icon on the top left (its done) and the image surrounds with a border without making the image get bigger. Here is the code in my snippet:
here is the HTML:
<ul>
<li><input type="checkbox" id="cb1" />
<label for="cb1"><img src="http://lorempixel.com/103/103" /></label>
</li>
<li><input type="checkbox" id="cb2" />
<label for="cb2"><img src="http://lorempixel.com/102/102" /></label>
</li>
</ul>
this is the CSS:
ul {
list-style-type: none;
}
li {
display: inline-block;
}
input[type="checkbox"][id^="cb"] {
display: none;
}
label {
display: block;
position: relative;
cursor: pointer;
width: 100%;
height: 100%;
}
label:before {
background-color: red;
color: white;
display: block;
border: 1px solid red;
position: absolute;
width: 20px;
height: 20px;
text-align: center;
line-height: 20px;
transition-duration: 0.4s;
-webkit-transition-duration: 0.4s;
-moz-transition-duration: 0.4s;
-ms-transition-duration: 0.4s;
}
label img {
height: 100%;
width: 100%;
}
:checked + label {
border-color: red;
}
:checked + label:before {
content: "✓";
background-color: red;
border: 1px solid red;
z-index: 99;
}
:checked + label img {
z-index: -1;
border: 1px solid red;
}
Thank you!
Add Border for img with transparent
label img {
height: 100%;
width: 100%;
border: 1px solid transparent;
}
https://codepen.io/anon/pen/PVRxRM
I gave fixed height and width to li and when the checkbox is checked i am changing the height and width of an image and aligning it in the center. hope this is what you are looking for. thanks.
ul {
list-style-type: none;
}
li {
display: inline-block;
}
input[type="checkbox"][id^="cb"] {
display: none;
}
label {
display: block;
position: relative;
cursor: pointer;
height: 120px;
border: 1px solid;
width: 120px;
}
label:before {
background-color: red;
color: white;
display: block;
position: absolute;
width: 20px;
height: 20px;
text-align: center;
line-height: 20px;
transition-duration: 0.4s;
}
label img {
height: 100%;
width: 100%;
}
:checked + label {
border-color: red;
}
:checked + label:before {
content: "✓";
background-color: red;
border: 1px solid red;
z-index: 99;
}
:checked + label img {
z-index: -1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
height: 100px;
width: 100px;
}
<ul>
<li><input type="checkbox" id="cb1" />
<label for="cb1"><img src="http://lorempixel.com/100/100" /></label>
</li>
<li><input type="checkbox" id="cb2" />
<label for="cb2"><img src="http://lorempixel.com/101/101" /></label>
</li>
<li><input type="checkbox" id="cb3" />
<label for="cb3"><img src="http://lorempixel.com/102/102" /></label>
</li>
<li><input type="checkbox" id="cb4" />
<label for="cb4"><img src="http://lorempixel.com/103/103" /></label>
</li>
</ul>
Try This:
ul {
list-style-type: none;
}
li {
display: inline-block;
}
input[type="checkbox"][id^="cb"] {
display: none;
}
label {
border: 1px solid #fff;
display: block;
position: relative;
cursor: pointer;
}
label:before {
background-color: red;
color: white;
content: "";
display: block;
border: 1px solid red;
position: absolute;
width: 20px;
height: 20px;
text-align: center;
line-height: 20px;
transition-duration: 0.4s;
transform: scale(0);
}
label img {
height: 100%;
width: 100%;
transition-duration: 0.2s;
transform-origin: 50% 50%;
}
:checked + label {
border-color: red;
}
:checked + label:before {
content: "✓";
background-color: red;
z-index: 99;
transform: scale(1);
}
:checked + label img {
z-index: -1;
transform: scale(0.9);
}
<ul>
<li><input type="checkbox" id="cb1" />
<label for="cb1"><img src="http://lorempixel.com/103/103" /></label>
</li>
<li><input type="checkbox" id="cb2" />
<label for="cb2"><img src="http://lorempixel.com/102/102" /></label>
</li>
</ul>
So if requirement is when you click on image, you need to show ✓ on left top corner of image, and you also want to show some border around image, then what you have done is absolutely right.
If you are concerned about image moving by n pixel, then keep in mind that border occupy some space unlike outline which doesnt need any space. Outline takes n pixel around object and apply border type effect.
So there are 2 solution -
what #lalji suggested above. when you load page, apply border on image with color as transparent so it will reserve the space for your border and actually you will not see any border around it, and on clicking (selecting image) just change the color of border.
Fiddle for border transparent
label img {
height: 100%;
width: 100%;
border: 1px solid transparent;
}
another will be when you click it, apply the outline instead of border.
Fiddle for outline
:checked + label img {
z-index: -1;
outline: 1px solid red;
}
UPADTE if we want to show some image/text also when image selected. if you see here I have added another node saying details that will be shown only when image selected and will be aligned in centre of the image.
Fiddle
This below css rule to hide the details initially and making them in centre etc.
label img + .details
{
color:white;
position:absolute;
top:0px;
width:100%;
display:none;
margin-top:50%;
transform: translatey(-50%);
text-align:center;
}
Now, we will show the details section if image selected.
:checked + label img + .details
{
display:block;
}
You can use a "label" tag that contains an "img" tag inside.
Here's an example of using an image as a checkbox and radio.
* {
font-family: Lato;
margin: 0;
padding: 0;
--transition: 0.15s;
--border-radius: 0.5rem;
--background: #ffc107;
--box-shadow: #ffc107;
}
.cont-bg {
min-height: 100vh;
background-image: radial-gradient(
circle farthest-corner at 7.2% 13.6%,
rgba(37, 249, 245, 1) 0%,
rgba(8, 70, 218, 1) 90%
);
padding: 1rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.cont-title {
color: white;
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 1rem;
}
.cont-main {
display: flex;
flex-wrap: wrap;
align-content: center;
justify-content: center;
}
.cont-checkbox {
width: 150px;
height: 100px;
border-radius: var(--border-radius);
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
background: white;
transition: transform var(--transition);
}
.cont-checkbox:first-of-type {
margin-bottom: 0.75rem;
margin-right: 0.75rem;
}
.cont-checkbox:active {
transform: scale(0.9);
}
input {
display: none;
}
input:checked + label {
opacity: 1;
box-shadow: 0 0 0 3px var(--background);
}
input:checked + label img {
-webkit-filter: none; /* Safari 6.0 - 9.0 */
filter: none;
}
input:checked + label .cover-checkbox {
opacity: 1;
transform: scale(1);
}
input:checked + label .cover-checkbox svg {
stroke-dashoffset: 0;
}
label {
display: inline-block;
cursor: pointer;
border-radius: var(--border-radius);
overflow: hidden;
width: 100%;
height: 100%;
position: relative;
opacity: 0.6;
}
label img {
width: 100%;
height: 70%;
object-fit: cover;
clip-path: polygon(0% 0%, 100% 0, 100% 81%, 50% 100%, 0 81%);
-webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
filter: grayscale(100%);
}
label .cover-checkbox {
position: absolute;
right: 5px;
top: 3px;
z-index: 1;
width: 20px;
height: 20px;
border-radius: 50%;
background: var(--box-shadow);
border: 2px solid #fff;
transition: transform var(--transition),
opacity calc(var(--transition) * 1.2) linear;
opacity: 0;
transform: scale(0);
}
label .cover-checkbox svg {
width: 13px;
height: 11px;
display: inline-block;
vertical-align: top;
fill: none;
margin: 5px 0 0 3px;
stroke: #fff;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
transition: stroke-dashoffset 0.4s ease var(--transition);
stroke-dashoffset: 16px;
}
label .info {
text-align: center;
margin-top: 0.2rem;
font-weight: 600;
font-size: 0.8rem;
}
<div class="cont-bg">
<div class="cont-title">Checkbox</div>
<div class="cont-main">
<div class="cont-checkbox">
<input type="checkbox" id="myCheckbox-1" />
<label for="myCheckbox-1">
<img
src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/2021-mazda-mx-5-miata-mmp-1-1593459650.jpg?crop=0.781xw:0.739xh;0.109xw,0.0968xh&resize=480:*"
/>
<span class="cover-checkbox">
<svg viewBox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<div class="info">Mazda MX-5 Miata</div>
</label>
</div>
<div class="cont-checkbox">
<input type="checkbox" id="myCheckbox-2" />
<label for="myCheckbox-2">
<img
src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/2020-chevrolet-corvette-c8-102-1571146873.jpg?crop=0.548xw:0.411xh;0.255xw,0.321xh&resize=980:*"
/>
<span class="cover-checkbox">
<svg viewBox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<div class="info">Toyota Supra</div>
</label>
</div>
</div>
<div class="cont-title">Radio</div>
<div class="cont-main">
<div class="cont-checkbox">
<input type="radio" name="myRadio" id="myRadio-1" />
<label for="myRadio-1">
<img
src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/2021-mazda-mx-5-miata-mmp-1-1593459650.jpg?crop=0.781xw:0.739xh;0.109xw,0.0968xh&resize=480:*"
/>
<span class="cover-checkbox">
<svg viewBox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<div class="info">Mazda MX-5 Miata</div>
</label>
</div>
<div class="cont-checkbox">
<input type="radio" name="myRadio" id="myRadio-2" />
<label for="myRadio-2">
<img
src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/2020-chevrolet-corvette-c8-102-1571146873.jpg?crop=0.548xw:0.411xh;0.255xw,0.321xh&resize=980:*"
/>
<span class="cover-checkbox">
<svg viewBox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<div class="info">Toyota Supra</div>
</label>
</div>
</div>
</div>