How to add an arrow at the end of the lines - html

I actually have some styles that allow me to display a text surrounded by lines. The text can be displayed horizontally or vertically. I would like to add an arrow a the end of the surrounding lines. Something like this:
------------------------- My horizontal label ------------------------>
or
^
|
|
M
y
t
e
x
t
|
|
My vertical text is displayed differently in my following example.
I tried several Technics i found in the net but no way to make it work in horizontal and vertical context.
Someone has an idea of how it can be implemented?
This is my starting css in which i would like to add these arrows:
h1 {
display: flex;
flex-direction: row;
}
h1:before, h1:after{
content: "";
flex: 1 1;
border-bottom: 1px solid;
margin: auto;
}
h1:before {
margin-right: 10px
}
h1:after {
margin-left: 10px
}
h2 {
display: flex;
flex-direction: row;
writing-mode: vertical-rl;
transform: scale(-1);
text-align: -webkit-center;
height: 100%;
}
h2:before, h2:after{
content: "";
flex: 1 1;
border-right: 1px solid;
margin: auto;
}
h2:before {
margin-bottom: 10px
}
h2:after {
margin-top: 10px
}
<h1>My horizontal text</h1>
<h2>My vertical text</h2>

Thank you for your solution. I tried this that seems to be nice too:
.line-container {
display: flex;
width: 100%;
margin: 20px auto;
align-items: center;
}
.line {
flex-grow: 1;
height: 2px;
background: black;
position: relative;
}
.line.arrow-right:after {
position: absolute;
content: '';
bottom: -4px;
right: -1px;
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 10px solid black;
}
.line-container span.label {
margin: 0 10px;
}
.line-container-vertical {
display: flex;
height: 100%;
margin: auto 20px;
align-items: center;
writing-mode: vertical-rl;
transform: scale(-1);
}
.line-vertical {
flex-grow: 1;
width: 2px;
background: black;
position: relative;
}
.line-vertical.arrow-top:after {
position: absolute;
content: '';
bottom: -2px;
left: -4px;
width: 0;
height: 0;
border-top: 10px solid black;
border-right: 5px solid transparent;
border-left: 5px solid transparent;
}
.line-container-vertical span.label {
margin: 10px 0;
}
<div class="line-container">
<span class="line arrow-left"></span>
<span class="label">Horizontal Label</span>
<span class="line arrow-right"></span>
</div>
<div class="line-container-vertical">
<span class="line-vertical"></span>
<span class="label">Vertical Label</span>
<span class="line-vertical arrow-top"></span>
</div>
What do you think?

[EDIT 20221125 - Added an alternative approach]
I am not all sure that your approach is the best, but based on your approach, the following might be of use:
h1 {
display: flex;
flex-direction: row;
}
h1 > div:nth-of-type(1) {
margin-right: -0.05em;
}
h1 > div:nth-of-type(2),
h1 > div:nth-of-type(4) {
flex: 1 1;
border-bottom: 0.05em solid;
margin: auto;
padding-top: 0.17em;
}
h1 > div:nth-of-type(3) {
margin-right: 10px;
margin-left: 10px;
}
h1 > div:nth-of-type(5) {
margin-left: -0.05em;
}
h2 {
display: flex;
flex-direction: row;
writing-mode: vertical-rl;
transform: scale(-1);
height: 100%;
}
h2 > div:nth-of-type(1) {
margin-bottom: -0.05em;
}
h2 > div:nth-of-type(2),
h2 > div:nth-of-type(4) {
flex: 1 1;
border-left: 0.05em solid;
margin: auto;
padding-left: 0.17em;
margin-top: -0.05em;
margin-bottom: -0.05em;
}
h2 > div:nth-of-type(3) {
margin-top: 10px;
margin-bottom: 10px;
}
h2 > div:nth-of-type(5) {
margin-bottom: -0.05em;
}
<h1><div>←</div><div></div><div>My horizontal text</div><div></div><div>→</div></h1>
<h2><div>←</div><div></div><div>My vertical text</div><div></div><div>→</div></h2>
The following is an alternative approach and should be more robust:
.horizontal {
display: flex;
flex-direction: row;
justify-content: space-between;
background-repeat: repeat-x;
background-position-y: center;
background-image: url('data:image/svg+xml; utf8, <svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none" viewBox="0 0 20 3"><line x1="0" y1="1" x2="20" y2="1" stroke="black" stroke-width="3" /></svg>');
background-size: 100% 0.2em;
}
.horizontal > span {
background: white;
padding-left: 10px;
padding-right: 10px;
font-weight: bold;
}
leftarrow {
content: url('data:image/svg+xml; utf8, <svg xmlns="http://www.w3.org/2000/svg" height="1.1em" viewBox="0 0 40 14"><line x1="0" y1="7" x2="38" y2="2" stroke="black" stroke-width="2" /><line x1="0" y1="7" x2="38" y2="12" stroke="black" stroke-width="2" /></svg>');
}
rightarrow {
content: url('data:image/svg+xml; utf8, <svg xmlns="http://www.w3.org/2000/svg" height="1.1em" viewBox="0 0 40 14"><line x1="1" y1="2" x2="39" y2="7" stroke="black" stroke-width="2" /><line x1="1" y1="12" x2="39" y2="7" stroke="black" stroke-width="2" /></svg>');
}
<div class="horizontal"><leftarrow></leftarrow><span>Horizontally aligned text</span><rightarrow></rightarrow></div>

Related

How to add hamburger icon to navbar

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>

How to make search bar responsive?

I want to make my html/css search bar responsive for example iphone 11.
Search button drops down after hovering over it, when i open it from my phone.
Here's the link: https://irinachikviladze.github.io/
How can I make it responsive using CSS?
<div class="search-box">
<input class="search-txt" type="text" name="" placeholder="Type to search">
<a class="search-btn" href="#">
<i class="fa-solid fa-magnifying-glass"></i>
</a>
</div>
Every HTML element has a default display value depending on what type of element it is. The default display value for most elements is block or inline.
So just overwrite the default display for your search box and set it to flex with flex-direction: row;
that's it.
body{
margin: 0;
padding: 0;
background:#e74c3c;
}
.search-box{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #34495e;
height: 40px;
border-radius: 40px;
padding: 10px;
display: flex;
flex-direction: row;
}
.search-box:hover > .search-txt{
width: 240px;
padding: 0 6px;
}
.search-box:hover > .search-btn{
background : white ;
}
.search-btn{
color: #e74c3c;
float: right;
width: 40px;
height: 40px;
border-radius: 50%;
background:#34495e;
display: flex;
justify-content: center;
align-items: center;
text-decoration: none;
overflow: hidden;
}
.search-txt{
border:none;
background: none;
outline: none;
float: left;
padding: 0;
color: white;
font-size: 16px;
transition: 0.4s;
line-height: 40px;
width: 0px;
}
/* responsive*/
#media only screen and (max-width: 828px){
.search-box:hover > .search-txt{
width: 125px;
}
}
<body>
<div class="search-box">
<input class="search-txt" type="text" name="" placeholder="Type to search">
<a class="search-btn" href="#">
<i class="fa-solid fa-magnifying-glass"></i>
</a>
</div>
</body>
Html element
<div class="Card">
<div class="CardInner">
<label>Search for your stack :)</label>
<div class="container">
<div class="Icon">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#657789" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
</div>
<div class="InputContainer">
<input placeholder="search here...."/>
</div>
</div>
</div>
</div>
CSS Element
#import url('https://fonts.googleapis.com/css?family=Orbitron&display=swap');
#import url('https://fonts.googleapis.com/css?family=Hind&display=swap');
* {
-webkit-font-smoothing: antialiased;
color: #acbdce;
}
:root {
--border-radius: 10px;
}
body, html {
background: #e2e9f4;
display: grid;
height: 100%;
grid-template: 1fr/100%;
place-items: center;
}
.Card {
padding: 1px;
border-radius: var(--border-radius);
background: linear-gradient(-67deg, rgba(#c8d8e7, .7), rgba(255,255,255,.8));
overflow: hidden;
box-shadow:
-2px -2px 6px rgba(#fff, .6),
2px 2px 12px #c8d8e7;
width: 380px;
}
.CardInner {
padding: 16px 16px;
background-color: #e2e9f4;
border-radius: var(--border-radius);
}
.container {
display: flex;
}
.Icon {
min-width: 46px;
min-height: 46px;
display: flex;
align-items: center;
justify-content: center;
border-radius: var(--border-radius);
margin-right: 12px;
box-shadow:
-2px -2px 6px rgba(#fff, .6),
2px 2px 12px #c8d8e7;
svg {
transform: translate(-1px, -1px);
}
}
label {
font-family: "Hind", sans-serif;
display: block;
color: #3c4b66;
margin-bottom: 12px;
background: linear-gradient(45deg, rgba(#6b7b8f, 1), #3c4b66);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.InputContainer {
width: 100%;
}
input {
background-color: #e3edf7;
padding: 16px 32px;
border: none;
display: block;
font-family: 'Orbitron', sans-serif;
font-weight: 600;
color: #a9b8c9;
-webkit-appearance: none;
transition: all 240ms ease-out;
width: 100%;
&::placeholder {
color: #6d7f8f;
}
&:focus {
outline: none;
color: #6d7f8f;
background-color: lighten(#e3edf7, 3%);
}
};
.InputContainer {
--top-shadow: inset 1px 1px 3px #c5d4e3, inset 2px 2px 6px #c5d4e3;
--bottom-shadow: inset -2px -2px 4px rgba(255,255,255, .7);
position: relative;
border-radius: var(--border-radius);
overflow: hidden;
&:before,
&:after {
left: 0;
top: 0;
display: block;
content: "";
pointer-events: none;
width: 100%;
height: 100%;
position: absolute;
}
&:before {
box-shadow: var(--bottom-shadow);
}
&:after {
box-shadow: var(--top-shadow);
}
}

Shift cards over to next row when browser size is 915px width

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>

How to set width of element to its absolute nested element?

I want the main div, .secondNavLinksInSmall, to be of width as of the .secondNavLinksDisplayInSmall element. How can I do it? Note that the last is an element with position: absolute. Also, I wish to do it without setting any fixed width to the code.
Here is the HTML:
<div class="secondNavLinksInSmall">
<button id="secondNavLinksButtonInSmall" class="secondNavLinksButtonInSmall" type="button">
<svg id="secondNavLinksButtonInSmallSVG" class="secondNavLinksButtonInSmall__svg" viewBox="0 0 213.333 213.333">
<polygon points="0,53.333 106.667,160 213.333,53.333"/>
</svg>
<span><?php echo $buttonTextInsmall; ?></span>
</button>
<div id="secondNavLinksDisplayInSmall" class="secondNavLinksDisplayInSmall">
<a class="secondNavLinkInSmall" href="/">דילים חדשים</a>
<a class="secondNavLinkInSmall" href="hotdeals.php">דילים חמים</a>
<a class="secondNavLinkInSmall" href="forum.php">פורום</a>
</div>
</div>
Here is the SCSS code:
.secondNavLinksInSmall {
margin-right: 10px;
position: relative;
height: 100%;
display: none;
background-color: transparent;
}
.secondNavLinksButtonInSmall {
cursor: pointer;
height: 100%;
width: 100%;
padding: 0 12px;
display: flex;
justify-content: center;
align-items: center;
background-color: transparent;
color: white;
font-size: 20px;
text-align: center;
white-space: nowrap;
&:hover {
background-color: map-get($webColors, 'main-dark');
}
&__svg {
height: 12px;
fill: white;
margin-left: 10px;
transition: transform .4s;
}
}
.secondNavLinksDisplayInSmall {
background-color: white;
z-index: 2;
display: none;
flex-direction: column;
position: absolute;
top: 48px;
left: 0;
width: min-content;
border: 1px solid black;
}
.secondNavLinkInSmall {
border-bottom: 1px solid map-get($webColors, 'main-dark');
white-space: nowrap;
text-align: center;
font-size: 20px;
text-decoration: none;
color: black;
padding: 5px;
&:last-child {
border-bottom: none;
}
&:hover {
background-color: map-get($webColors, 'dark-white');
}
}
The short answer is no, it can't be done using only CSS. If you want a parent element to inherit the dimensions of a child element that is position absolutely the only solution is using javascript.

How to allow space evenly to each div in flex

Demo site here.
When it is in large screen, apply button has too much space. I want to make it flex: space-around
When it starts to shrink, each div is not aligned evenly. (Again, flex: space-round will be nice)
full sass:
body {
font-family: 'Lato', sans-serif;
}
.errors {
color: red;
font-size: 70%;
}
.mainContainer {
background-color: #EAEDF1;
}
.banner {
position: relative;
color: white;
}
.banner .topLeft {
position: absolute;
top: 8px;
left: 16px;
font-size: 1.5vw;
}
.banner .centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 4.5vw;
}
.banner img {
width: 100%;
height: 400px;
object-fit: cover;
}
.banner i {
border: solid white;
border-width: 0 3px 3px 0;
display: inline-block;
padding: 3px;
position: absolute;
bottom: 10%;
left: 50%;
cursor: pointer;
}
.banner .arrowDown {
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
.bodyContainer {
padding: 20px 10px 10px 10px;
}
.bodySelf {
background-color: white;
}
.filter {
display: flex;
flex-wrap: wrap;
background-color: #f9fafa;
padding: 20px;
}
.filter .inputComponent {
min-width: 150px;
max-width: 200px;
}
.filter .inputComponent input {
width: 100%;
height: 27px;
}
.filter .dorpdownComponent {
min-width: 110px;
max-width: 200px;
}
.filter .applyButtonContainer {
width: 100px;
}
.filter .keywordMain {
flex-grow: 3;
padding-right: 20px;
padding-bottom: 10px;
}
.filter .launchpadMain {
flex-grow: 4;
padding-right: 20px;
padding-bottom: 10px;
}
.filter .minYearMain {
flex-grow: 2;
padding-right: 20px;
padding-bottom: 10px;
}
.filter .maxYearMain {
flex-grow: 2;
padding-right: 20px;
}
.filter .applyButtonMain {
flex-grow: 1;
padding-right: 20px;
}
.filter select {
-moz-appearance:none; /* Firefox */
-webkit-appearance:none; /* Safari and Chrome */
-webkit-border-radius: 0;
border-radius: 0;
appearance:none;
background-image: url("data:image/svg+xml;utf8,<svg fill='black' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
background-repeat: no-repeat;
background-position-x: 100%;
background-position-y: 3px;
border: 1px solid #ccc;
padding: 8px;
width: 100%;
}
.filter select option {
background-color: white;
color: white;
}
.filter .applyButton {
height: 30px;
width: 100px;
font-weight: 600;
color: white;
background-color: #2dbaba;
}
In your css
.filter{
justify-content: space-around;
}
.filter .applyButtonMain {
//flex-grow: 1; //remove it
padding-right: 20px;
}
.filter .applyButtonContainer {
//width: 100px; //remove this too
}
Not final answer, may need edit base on OP reply
.filter > div {
flex-basis: 0;
flex-grow: 1;
}
Demo (run and check in full page mode):
.filter select {
-moz-appearance: none;
/* Firefox */
-webkit-appearance: none;
/* Safari and Chrome */
-webkit-border-radius: 0;
border-radius: 0;
appearance: none;
background-image: url("data:image/svg+xml;utf8,<svg fill='black' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
background-repeat: no-repeat;
background-position-x: 100%;
background-position-y: 3px;
border: 1px solid #ccc;
padding: 8px;
width: 100%;
}
.filter select option {
background-color: white;
color: white;
}
.filter {
display: flex;
flex-wrap: wrap;
background-color: #f9fafa;
padding: 20px 10px;
/* one */
}
.filter > div {
flex-basis: 0;
flex-grow: 1;
padding: 0 10px 10px 10px;
min-width: 110px;
}
.filter .inputComponent input {
width: 100%;
height: 27px;
}
.filter .applyButton {
height: 30px;
width: 100%;
font-weight: 600;
color: white;
background-color: #2dbaba;
}
<div class="filter">
<div class="inputComponent keywordMain">
<div class="labelText">Keywords</div>
<input placeholder="eg Falcon">
</div>
<div class="dorpdownComponent launchpadMain">
<div class="labelText">Launch Pad</div>
<select>
<option value="">Any</option>
<option value="kwajalein_atoll">Kwajalein Atoll</option>
<option value="ccafs_slc_40">Cape Canaveral Air Force Station Space Launch Complex 40</option>
<option value="stls">SpaceX South Texas Launch Site</option>
</select>
</div>
<div class="dorpdownComponent minYearMain">
<div class="labelText">Min Year</div>
<select>
<option value="">Any</option>
<option value="2017">2017</option>
</select>
</div>
<div class="dorpdownComponent maxYearMain">
<div class="labelText">Max Year</div>
<select>
<option value="">Any</option>
<option value="2006">2006</option>
</select>
</div>
<div class="applyButtonContainer applyButtonMain">
<div> </div>
<button class="applyButton">Apply</button>
</div>
</div>