I'm currently trying to program a progress bar:
.create-progress-bar {
padding: 0 !important;
margin: 25px 0;
display: flex;
}
.create-progress-bar li {
display: flex;
flex-direction: column;
list-style-type: none;
position: relative;
width: 33.3333333333%;
}
.create-progress-bar .step-inner-wrapper {
display: flex;
flex-direction: column;
align-items: center;
}
.create-progress-bar li span.step-title {
text-transform: uppercase;
font-weight: 600;
}
.create-progress-bar li span.step-icon {
font-size: 22px;
padding: 18px;
border: 3px solid;
border-radius: 100%;
margin-bottom: 6px;
font-weight: 600;
width: 26px;
text-align: center;
}
.create-progress-bar li:first-child {
align-items: flex-start;
}
.create-progress-bar li:nth-child(2) {
align-items: center;
}
.create-progress-bar li:last-child {
align-items: flex-end;
}
.create-progress-bar li::after {
content: '';
position: absolute;
width: 100%;
height: 3px;
background: #666666;
border-radius: 3px;
top: 31px;
left: -50%;
z-index: -1;
}
<ul class="create-progress-bar">
<li class="active">
<span class="step-inner-wrapper">
<span class="step-icon">✔</span>
<span class="step-title">Create</span>
</span>
</li>
<li>
<span class="step-inner-wrapper">
<span class="step-icon">✔</span>
<span class="step-title">Check</span>
</span>
</li>
<li>
<span class="step-inner-wrapper">
<span class="step-icon">✔</span>
<span class="step-title">Done</span>
</span>
</li>
</ul>
Now I've the problem that I can't get the progress bars styled between each elements. It should look like this depending on the class active in each li element:
Is there someone how has an idea how to get this done?
You can do this using flexbox and :before pseudo-elements. You can create line before every li element except the first one and if the li has active class you change border color and line color.
ul {
display: flex;
align-items: center;
justify-content: space-between;
list-style-type: none;
padding-left: 0;
margin-bottom: 50px;
}
li:not(:first-child) {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
}
li:not(:first-child):before {
flex: 1;
height: 1px;
background: black;
content: '';
margin: 0 10px;
}
li.active .step-inner-wrapper {
border-color: red;
color: red;
}
li.active:before {
background: red;
}
.step-inner-wrapper {
width: 50px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid black;
border-radius: 50%;
position: relative;
}
.step-title {
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, 100%);
}
<ul class="create-progress-bar">
<li class="active">
<span class="step-inner-wrapper">
<span class="step-icon">✔</span>
<span class="step-title">Create</span>
</span>
</li>
<li>
<span class="step-inner-wrapper">
<span class="step-icon">✔</span>
<span class="step-title">Check</span>
</span>
</li>
<li>
<span class="step-inner-wrapper">
<span class="step-icon">✔</span>
<span class="step-title">Done</span>
</span>
</li>
</ul>
<ul class="create-progress-bar">
<li class="active">
<span class="step-inner-wrapper">
<span class="step-icon">✔</span>
<span class="step-title">Create</span>
</span>
</li>
<li class="active">
<span class="step-inner-wrapper">
<span class="step-icon">✔</span>
<span class="step-title">Check</span>
</span>
</li>
<li class="active">
<span class="step-inner-wrapper">
<span class="step-icon">✔</span>
<span class="step-title">Check</span>
</span>
</li>
<li>
<span class="step-inner-wrapper">
<span class="step-icon">✔</span>
<span class="step-title">Check</span>
</span>
</li>
<li>
<span class="step-inner-wrapper">
<span class="step-icon">✔</span>
<span class="step-title">Done</span>
</span>
</li>
</ul>
So I changed your CSS completely and made some minor changes to your HTML structure. This is my fiddle:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.progress-bar {
display: flex;
width: 100%;
justify-content: space-around;
flex-flow: row;
align-items: center;
max-width: calc(100% - 40px);
margin: 0 auto;
}
.progress-bar>li:first-child {
width: auto;
}
.progress-bar>li:first-child .line {
display: none;
}
.progress-bar>li.active .tick {
border-color: red;
color: red;
}
.progress-bar>li.active .line {
background: red;
}
.progress-bar>li {
display: flex;
flex-flow: row;
width: 100%;
align-items: center;
}
.tick {
border-radius: 100%;
border: 5px solid black;
height: 30px;
width: 30px;
padding: 30px;
display: flex;
align-items: center;
justify-content: center;
font-size: 22px;
font-weight: 600;
position: relative;
}
.tick>span {
position: absolute;
top: 70px;
}
.line {
width: 100%;
height: 5px;
display: block;
background: black;
margin: 0 15px;
}
<ul class="progress-bar">
<li class="active">
<div class="line"></div>
<div class="tick">
✔<span>CREATE</span>
</div>
</li>
<li>
<div class="line"></div>
<div class="tick">
✔<span>CHECK</span>
</div>
</li>
<li>
<div class="line"></div>
<div class="tick">
✔<span>DONE</span>
</div>
</li>
</ul>
You will see that I removed the approach of using pseudo-classes, such as ::after, and added a div.line instead. In CSS I removed the first progress line with display: none instead of removing the div tag because it is easier to use dynamically since you don't have to care about removing the first line when prepending content. But you can also just remove it like here:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.progress-bar {
display: flex;
width: 100%;
justify-content: space-around;
flex-flow: row;
align-items: center;
max-width: calc(100% - 40px);
margin: 0 auto;
}
.progress-bar>li:first-child {
width: auto;
}
.progress-bar>li.active .tick {
border-color: red;
color: red;
}
.progress-bar>li.active .line {
background: red;
}
.progress-bar>li {
display: flex;
flex-flow: row;
width: 100%;
align-items: center;
}
.tick {
border-radius: 100%;
border: 5px solid black;
height: 30px;
width: 30px;
padding: 30px;
display: flex;
align-items: center;
justify-content: center;
font-size: 22px;
font-weight: 600;
position: relative;
}
.tick>span {
position: absolute;
top: 70px;
}
.line {
width: 100%;
height: 5px;
display: block;
background: black;
margin: 0 15px;
}
<ul class="progress-bar">
<li class="active">
<div class="tick">
✔<span>CREATE</span>
</div>
</li>
<li>
<div class="line"></div>
<div class="tick">
✔<span>CHECK</span>
</div>
</li>
<li>
<div class="line"></div>
<div class="tick">
✔<span>DONE</span>
</div>
</li>
</ul>
Edit #1
Based on the comments, here is a version with a soft hyphen:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.progress-bar {
display: flex;
width: 100%;
justify-content: space-around;
flex-flow: row;
align-items: center;
max-width: calc(100% - 40px);
margin: 0 auto;
}
.progress-bar>li:first-child {
width: auto;
}
.progress-bar>li.active .tick {
border-color: red;
color: red;
}
.progress-bar>li.active .line {
background: red;
}
.progress-bar>li {
display: flex;
flex-flow: row;
width: 100%;
align-items: center;
}
.tick {
border-radius: 100%;
border: 5px solid black;
height: 30px;
width: 30px;
padding: 30px;
display: flex;
align-items: center;
justify-content: center;
font-size: 22px;
font-weight: 600;
position: relative;
}
.tick>span {
position: absolute;
top: 70px;
max-width: 100px;
text-align: center;
}
.line {
width: 100%;
height: 5px;
display: block;
background: black;
margin: 0 15px;
}
<ul class="progress-bar">
<li class="active">
<div class="tick">
✔<span>CREATEVERYLONGTEXT</span>
</div>
</li>
<li>
<div class="line"></div>
<div class="tick">
✔<span>CHECK</span>
</div>
</li>
<li>
<div class="line"></div>
<div class="tick">
✔<span>DONE</span>
</div>
</li>
</ul>
You could theoretically use hyphens: auto. But this has massive lack of browser support, as it can be seen here.
If you don't want the - dashes just use word-wrap: break-word;
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.progress-bar {
display: flex;
width: 100%;
justify-content: space-around;
flex-flow: row;
align-items: center;
max-width: calc(100% - 40px);
margin: 0 auto;
}
.progress-bar>li:first-child {
width: auto;
}
.progress-bar>li.active .tick {
border-color: red;
color: red;
}
.progress-bar>li.active .line {
background: red;
}
.progress-bar>li {
display: flex;
flex-flow: row;
width: 100%;
align-items: center;
}
.tick {
border-radius: 100%;
border: 5px solid black;
height: 30px;
width: 30px;
padding: 30px;
display: flex;
align-items: center;
justify-content: center;
font-size: 22px;
font-weight: 600;
position: relative;
}
.tick>span {
position: absolute;
top: 70px;
max-width: 100px;
text-align: center;
word-wrap: break-word;
}
.line {
width: 100%;
height: 5px;
display: block;
background: black;
margin: 0 15px;
}
<ul class="progress-bar">
<li class="active">
<div class="tick">
✔<span>CREATEVERYLONGTEXT</span>
</div>
</li>
<li>
<div class="line"></div>
<div class="tick">
✔<span>CHECK</span>
</div>
</li>
<li>
<div class="line"></div>
<div class="tick">
✔<span>DONE</span>
</div>
</li>
</ul>
Related
i need the navbar to display the dropdown div when i hover on the .nav-right.I have tried using position:absolute for the .nav-dropdown, but it just keeps going inside the nav itself and i want it underneath. Also, the .nav-right does not even also display the dropdown, what am i doing wrong?
``html
<div class="nav-left">
<span class="logo"></span>
</div><!--nav left-->
<div class="nav-middle">
<ul class="nav-list">
<li class="nav-item"><a class="nav-link" href="#">About Project</a></li>
<li class="nav-item"><a class="nav-link" href="#">Portfolio</a></li>
<li class="nav-item"><a class="nav-link" href="#">Shop</a></li>
<li class="nav-item"><a class="nav-link" href="#">Collections</a></li>
</ul>
</div><!--nav middle-->
<div class="nav-right">
<div class="user-image">
<img src="" />
</div><!--user image-->
<div class="lines">
<span class="line line-1"></span>
<span class="line line-2"></span>
</div><!--lines-->
</div><!--nav right-->
<div class="nav-dropdown">
dropdown nav bar
</div><!--nav dropdown-->
</nav><!--nav---->
``
``css
.nav {
height: auto;
width: 100%;
position: fixed;
top: 0;
align-items: center;
z-index: 1;
box-sizing: border-box;
display: flex;
align-items: center;
padding: 0 80px;
box-sizing: border-box;
border: solid 1px red;
}
.nav .nav-left {
display: flex;
flex-basis: 15%;
justify-content: left;
align-items: center;
height: 70px;
border: solid 1px green;
}
.nav .nav-left span {
height: 30px;
width: 30px;
background-color: #000;
}
.nav .nav-middle {
height: 70px;
flex-basis: 65%;
display: flex;
align-items: center;
border: solid 1px blue;
}
.nav .nav-middle ul {
display: flex;
list-style: none;
padding: 0;
margin: 0;
}
.nav .nav-middle ul li {
margin-right: 70px;
border: Solid 1px red;
}
.nav .nav-right {
display: flex;
height: 70px;
border: solid 1px purple;
flex-basis: 20%;
align-items: center;
justify-content: right;
}
.nav .nav-right .user-image {
height: 40px;
width: 40px;
background: #000;
border-radius: 50%;
margin-right: 40px;
}
.nav .nav-right .lines .line {
background-color: #000;
width: 30px;
height: 2px;
display: block;
margin-bottom: 5px;
}
.nav .nav-dropdown {
width: 100%;
display: none;
position: absolute;
top: 0;
height: 100px;
background-color: #000;
color: #fff;
border: solid 3px green;
box-sizing: border-box;
}
.nav .nav-right:hover + .nav-dropdown {
display: block;
}
.nav-link {
color: #000;
text-decoration: none;
font-family: selectric, helvetica, arial;
transition: linear 0.3s;
}
.nav-link:hover {
color: #484848;
``
Set top css value in pixels for the nav-dropdown, to position it where you like to position it.
.nav {
height: auto;
width: 100%;
position: fixed;
top: 0;
align-items: center;
z-index: 1;
box-sizing: border-box;
display: flex;
align-items: center;
padding: 0 80px;
box-sizing: border-box;
border: solid 1px red;
}
.nav .nav-left {
display: flex;
flex-basis: 15%;
justify-content: left;
align-items: center;
height: 70px;
border: solid 1px green;
}
.nav .nav-left span {
height: 30px;
width: 30px;
background-color: #000;
}
.nav .nav-middle {
height: 70px;
flex-basis: 65%;
display: flex;
align-items: center;
border: solid 1px blue;
}
.nav .nav-middle ul {
display: flex;
list-style: none;
padding: 0;
margin: 0;
}
.nav .nav-middle ul li {
margin-right: 70px;
border: Solid 1px red;
}
.nav .nav-right {
display: flex;
height: 70px;
border: solid 1px purple;
flex-basis: 20%;
align-items: center;
justify-content: right;
}
.nav .nav-right .user-image {
height: 40px;
width: 40px;
background: #000;
border-radius: 50%;
margin-right: 40px;
}
.nav .nav-right .lines .line {
background-color: #000;
width: 30px;
height: 2px;
display: block;
margin-bottom: 5px;
}
.nav .nav-dropdown {
width: 100%;
display: none;
position: absolute;
top: 100px;
height: 100px;
background-color: #000;
color: #fff;
border: solid 3px green;
box-sizing: border-box;
}
.nav .nav-right:hover+.nav-dropdown {
display: block;
}
.nav-link {
color: #000;
text-decoration: none;
font-family: selectric, helvetica, arial;
transition: linear 0.3s;
}
.nav-link:hover {
color: #484848;
}
<nav class='nav'>
<div class="nav-left">
<span class="logo"></span>
</div>
<!--nav left-->
<div class="nav-middle">
<ul class="nav-list">
<li class="nav-item"><a class="nav-link" href="#">About Project</a></li>
<li class="nav-item"><a class="nav-link" href="#">Portfolio</a></li>
<li class="nav-item"><a class="nav-link" href="#">Shop</a></li>
<li class="nav-item"><a class="nav-link" href="#">Collections</a></li>
</ul>
</div>
<!--nav middle-->
<div class="nav-right">
<div class="user-image">
<img src="" />
</div>
<!--user image-->
<div class="lines">
<span class="line line-1"></span>
<span class="line line-2"></span>
</div>
<!--lines-->
</div>
<!--nav right-->
<div class="nav-dropdown">
dropdown nav bar
</div>
<!--nav dropdown-->
</nav>
Move nav-dropdown to inside nav-right. This locates the dropdown as a child to nav-right
<div class="nav-right">
<div class="user-image">
<img src="" />
</div><!--user image-->
<div class="lines">
<span class="line line-1"></span>
<span class="line line-2"></span>
</div><!--lines-->
<div class="nav-dropdown">
dropdown nav bar
</div><!--nav dropdown-->
</div><!--nav right-->
Add position:relative to nav-right. This means we can position nav-dropdown using position:absolute.
.nav-right {
display: flex;
height: 70px;
border: solid 1px purple;
flex-basis: 20%;
align-items: center;
justify-content: right;
position:relative;
}
Because nav-dropdown is positioned:absolute, we can use the top: property to move the top down by however we want, so set this to, say: 4rem
.nav-dropdown {
width: 100%;
display: none;
position: absolute;
top: 4rem;
height: 100px;
background-color: #000;
color: #fff;
border: solid 3px green;
box-sizing: border-box;
}
Change the .nav-right:hover selector to select .nav-dropdown like this which displays the dropdown when we hover over .nav-right.
.nav-right:hover > .nav-dropdown {
display: block;
}
Basically what we're doing is putting a child elemnt in your navbar-right that we hide on document load. We position nav-right as position:relative which does nothing for .nav-right but allows us to positon the dropdown relative to this. We position nav-dropdown as absolute which doesn't interrupt your navbar rendering and we can then use the css properties left, top, bottom and right (using only the ones we need) to position the dropdown where we like. In this case we use 'top' to push the thing down and make it look like a menu.
There are some good examples here: https://www.w3schools.com/css/css_dropdowns.asp and here https://css-tricks.com/solved-with-css-dropdown-menus/
Good luck!
I'm styling some links with the following CSS code, I named the links with the className 'nav-menu-link':
.form-header {
background-color: var(--background-color);
display: flex;
align-items: center;
justify-content: center;
transition: all .3s ease-out;
position: relative;
width: 100%;
height: 100px;
}
.form-logo {
display: flex;
align-items: center;
cursor: pointer;
}
.image-logo-container {
box-sizing: border-box;
display: flex;
width: initial;
height: initial;
background: none;
opacity: 1;
border: 0;
margin: 0;
padding: 0;
max-width: 100%;
}
.image-logo-container img {
width: 250px;
height: 52px;
}
.nav-container {
display: flex;
align-items: center;
justify-content: space-between;
height: 100%;
}
.nav-menu {
display: flex;
font-size: 18px;
width: 380px;
align-items: center;
justify-content: space-between;
justify-content: center;
height: 100%;
margin: unset;
}
.nav-menu-item {
display: flex;
height: 100px;
align-items: center;
margin-left: 50px;
}
.nav-menu-link {
display: flex;
height: 100%;
align-items: center;
color: rgba(255, 255, 255, 0.5);
border-bottom: 2px solid transparent;
}
.nav-menu-link.active {
font-weight: bold;
color: var(--white);
}
.nav-menu-link:hover {
color: var(--white);
border-bottom: 2px solid var(--explorer);
transition: all .2s ease-in-out;
}
#media (min-width: 998px) {}
#media (min-width: 768px) {}
<header class="form-header">
<div class="nav-container">
<a class="form-logo" id="navbar-link-form-logo" href="/">
<div class="image-logo-container">
<img src="https://placekitten.com/250/52" alt="" />
</div>
</a>
<nav class="container">
<ul class="row nav-menu">
<li class="nav-menu-item">
<a class="nav-menu-link active" href="/">Home</a>
</li>
<li class="nav-menu-item">
<a class="nav-menu-link" href="/form">Form</a>
</li>
<li class="nav-menu-item">
<a class="nav-menu-link" href="/about">About</a>
</li>
</ul>
</nav>
<ul>
</ul>
</div>
</header>
I did two effects, one is when the link is active with the '.active' class, and another is when I hover over the link with the 'hover'.
In pure CSS, the correct way to do these two effects is as I wrote in the code above?
I am just practicing CSS/HTML and am trying to make a google clone. Everything else seems fine but now I am trying to make a footer and whenever I put a div inside the footer, they appear on top of the footer instead of inside the footer.
#import url('https://fonts.googleapis.com/css2?family=Roboto:wght#300;400;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
background-color: rgb(32, 33, 36);
color: white;
}
a {
text-decoration: none;
color: inherit;
}
.nav-bar a:nth-child(1):hover {
text-decoration: underline;
}
.nav-bar a:nth-child(2):hover {
text-decoration: underline;
}
.nav-bar {
height: 50px;
display: flex;
align-items: center;
justify-content: flex-end;
}
.nav-items {
list-style: none;
display: flex;
justify-content: flex-end;
align-items: center;
}
.nav-items li {
margin-left: 15px;
}
.menu-icon {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
width: 40px;
height: 40px;
padding: 10px;
border-radius: 50%;
}
.menu-icon:hover {
background-color: rgba(138, 133, 133, 0.26);
}
.menu-icon span {
background-color: #ffffff;
width: 20px;
height: 2px;
}
.profile-picture {
margin-right: 15px;
height: 32px;
width: 32px;
border-radius: 50%;
}
.profile-picture:hover {
box-shadow: 0px 0px 0px 5px #7068683b;
}
.profile-picture img {
border-radius: 50%;
width: 100%;
}
.main-section {
display: flex;
justify-content: center;
align-items: center;
margin-top: 80px;
}
.google-logo {
width: 375px;
height: 150px;
}
.google-logo img {
width: 100%;
}
.search-section {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.search-container {
display: flex;
justify-content: center;
align-items: center;
width: 580px;
border: solid;
border-color: #949090;
border-width: 1px;
border-radius: 300px;
padding: 9px;
height: 45px;
}
.search-container:hover {
box-shadow: 0px 0px 10px 2px #00000036;
}
.search-icon {
width: 25px;
height: 25px;
margin-right: 5px;
}
.search-icon img {
width: 100%;
}
.search-bar {
width: 550px;
height: 30px;
border: none;
outline: none;
}
.microphone {
width: 25px;
height: 25px;
}
.microphone img {
width: 100%;
}
.search-buttons {
margin-top: 25px;
}
.search-buttons button {
margin-left: 6px;
padding: 10px 16px 10px 16px;
background-color: #303134;
border: none;
border-radius: 4px;
color: #e8eaed;
font-size: 14px;
cursor: pointer;
border: solid 1px transparent;
}
.search-buttons button:hover {
border-color: #e8eaed;
}
.language-selector {
display: flex;
justify-content: center;
margin-top: 30px;
}
.language-selector p {
font-size: 13px;
color: #bdc1c6;
}
.language-selector a {
color: #8ab4f8;
}
.footer {
background-color: #446adb;
height: 100px;
margin-top: 92px;
}
<body>
<!-- start of the navigation bar-->
<nav class="nav-bar">
<ul class="nav-items">
<li>Gmail</li>
<li>სურათები</li>
<li>
<a href="#">
<div class="menu-icon">
<span>
</span>
<span>
</span>
<span>
</span>
</div>
</a>
</li>
<li>
<a href="#"><div class="profile-picture">
<img src="icons/unnamed.png">
</div></a>
</li>
</ul>
</nav>
<!-- end of the navigation bar -->
<!-- start of the main section (logo and search-bar)-->
<div class="main-section">
<a href="#"><div class="google-logo">
<img src="icons/google.png">
</div></a>
</div>
<div class="search-section">
<div class="search-container">
<div class="search-icon"><img src="icons/search.png"/></div>
<input type="text" class="search-bar">
<div class="microphone"><img src="icons/micro.png" alt=""></div>
</div>
<div class="search-buttons">
<button>
Google ძებნა
</button>
<button>
იღბალს მივენდობი
</button>
</div>
</div>
<div class="language-selector">
<p>Google ხელმისაწვდომია შემდეგ ენაზე: English</p>
</div>
<!-- end of the main section -->
<!-- start of the footer-->
<footer class="footer">
<div class="current-location">
this text should be inside the footer
</div>
</footer>
</body>
here is the picture of the problem I am having.
https://i.stack.imgur.com/AXMv6.png
It is inside the footer. Just this property:
background-color: rgb(32, 33, 36);
which you set for * gets inherited, and the bg color makes you think text it outside the footer. Comment it out for a while and you will see.
#draggable-container {
margin: 0 auto;
display: flex;
flex-wrap: nowrap;
align-items: center;
}
.draggable-game-content {
width: 100%;
height: 40rem;
}
.draggable-game {
position: relative;
border: 1px solid black;
border-radius: 25px;
margin-left: 1.5rem;
height: 38rem;
text-align: center;
}
#menu-container {
width: 4rem;
height: 30rem;
border: 1px solid #000;
border-radius: 15px;
position: relative;
}
.menu-list {
position: absolute;
left: 25%;
top: 50%;
transform: translate(-50%, -50%);
}
.menu-item {
display: block;
margin-bottom: 1.5rem;
border-radius: 50%;
border: 1px solid #000;
height: 2.5rem;
width: 2.5rem;
}
.menu-item:nth-child(2) {
margin-bottom: 7rem;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div id="draggable-container">
<div id="menu-container">
<ul class="menu-list">
<li class="menu-item"></li>
<li class="menu-item"></li>
<li class="menu-item">info</li>
<li class="menu-item">settings</li>
<li class="menu-item">achievements</li>
</ul>
</div>
<div class="draggable-game-content">
<div class="draggable-game">test</div>
</div>
</div>
</div>
I have this page generated by React and I don't understand why the div with "test" stays up while the left menu goes down.
I want to make them stay at the same level, like this:
I thought I will achieve this by setting align-items to center (so they will center vertically) and start at the same point, but actually it doesn't work.
Why is my approach not valid and how can I achieve the layout from the page?
Your's align-items should be flex-start
#draggable-container {
margin: 0 auto;
display: flex;
flex-wrap: nowrap;
align-items: flex-start;
}
#draggable-container {
margin: 0 auto;
display: flex;
flex-wrap: nowrap;
align-items: flex-start; // updated this line only
}
.draggable-game-content {
width: 100%;
height: 40rem;
}
.draggable-game {
position: relative;
border: 1px solid black;
border-radius: 25px;
margin-left: 1.5rem;
height: 38rem;
text-align: center;
}
#menu-container {
width: 4rem;
height: 30rem;
border: 1px solid #000;
border-radius: 15px;
position: relative;
}
.menu-list {
position: absolute;
left: 25%;
top: 50%;
transform: translate(-50%, -50%);
}
.menu-item {
display: block;
margin-bottom: 1.5rem;
border-radius: 50%;
border: 1px solid #000;
height: 2.5rem;
width: 2.5rem;
}
.menu-item:nth-child(2) {
margin-bottom: 7rem;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div id="draggable-container">
<div id="menu-container">
<ul class="menu-list">
<li class="menu-item"></li>
<li class="menu-item"></li>
<li class="menu-item">info</li>
<li class="menu-item">settings</li>
<li class="menu-item">achievements</li>
</ul>
</div>
<div class="draggable-game-content">
<div class="draggable-game">test</div>
</div>
</div>
</div>
In Flex to align your items, you must use the align-items property.
You can read more about Flex and its properties in this article.
#draggable-container {
margin: 0 auto;
display: flex;
flex-wrap: nowrap;
align-items: flex-start;
}
I have a menu (sidebar), when you hover over the corresponding menu item, a second column with a submenu is displayed. I need to make a triangle-pointer, as in the picture (in the question). I can’t understand how this can be done. Share your opinion, please. Thank!
https://i.stack.imgur.com/su151.png
.main {
font-family: PT Sans;
position: relative;
display: flex;
flex-direction: row;
min-height: 100%;
}
.main_menu {
display: flex;
flex-direction: column;
width: auto;
background-color: #38618C;
padding: 50px 0 0 0;
z-index: 1000;
}
.main_menu_content {
display: flex;
flex-direction: column;
position: sticky;
top: 50px;
width: 100%;
}
.main_menu_content_list {
display: flex;
flex-direction: column;
justify-content: space-between;
text-align: center;
height: 700px;
width: 250px;
}
.main_menu_content_list li {
list-style-type: none;
}
.main_menu_content_list a {
display: flex;
flex-direction: column;
align-items: center;
font-style: normal;
font-weight: normal;
font-size: 18px;
line-height: 23px;
color: #D7DFE8;
text-decoration: none;
}
.main_menu_content_list_sub_block {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 55px;
}
.main_menu_content_list_submenu {
justify-content: center;
position: absolute;
padding: 0;
margin: 0;
left: 100%;
height: 100vh;
background-color: #F0F6F8;
box-shadow: 5px 0px 20px rgba(0, 0, 0, 0.25);
top: -50px;
pointer-events: none;
opacity: 0;
transition: all linear 0.1s 0s;
width: 250px;
}
.main_menu_content_list li:hover .main_menu_content_list_submenu {
opacity: 1;
pointer-events: auto;
}
.main_menu_content_list_submenu_popup li:first-child {
margin: 50px 0 0 0;
}
.main_menu_content_list_submenu_popup li:not(:first-child) {
margin: 10px 0 0 0;
}
.main_menu_content_list li:hover > .main_menu_content_list_submenu {
display: flex;
}
.main_menu_content_list_submenu_popup a {
font-style: normal;
font-weight: normal;
font-size: 16px;
line-height: 21px;
color: #38618C;
}
.main_menu_content_list_submenu_popup a:hover {
color: #38618C;
text-decoration: underline;
}
.main_menu_content_list_submenu_popup a:active {
color: #FF5964;
}
.main_content {
display: flex;
align-items: center;
flex-direction: column;
width: 100%;
max-width: 100%;
height: 100%;
}
<div class="main">
<div class="main_menu">
<div class="main_menu_content">
<ul class="main_menu_content_list">
<li><a href="">
<div class="main_menu_content_list_int"></div>Интернет
</a>
<div class="main_menu_content_list_submenu">
<ul class="main_menu_content_list_submenu_popup">
<li>Подключение</li>
<li>Дополнительные услуги</li>
<li>Настройка соединения</li>
<li>Подключенные дома</li>
</ul>
</div>
</li>
<li><a href="">
<div class="main_menu_content_list_tv"></div>Телевидение
</a>
<div class="main_menu_content_list_submenu">
<ul class="main_menu_content_list_submenu_popup">
<li>Подключение</li>
<li>Новости</li>
<li>Акции</li>
<li>Аналоговое ТВ</li>
<li>Оборудование</li>
<li>Настройка каналов</li>
<li>Подключенные дома</li>
<li>Документы</li>
</ul>
</div>
</li>
<li><a href="">
<div class="main_menu_content_list_video"></div>Видеонаблюдение,<br>домофон
</a>
<div class="main_menu_content_list_submenu">
<ul class="main_menu_content_list_submenu_popup">
<li>Обслуживание</li>
<li>Установка</li>
<li>Заявка на ремонт</li>
<li>Подключение</li>
</ul>
</div>
</li>
<li><a href="">
<div class="main_menu_content_list_tvr"></div>ТВ Реклама
</a></li>
<li><a href="">
<div class="main_menu_content_list_intb"></div>Интернет для бизнеса
</a></li>
<div class="main_menu_content_list_sub_block">
<li>Оплата</li>
<li>О компании</li>
</div>
<li><a href="">
<div class="main_menu_content_list_sub_account"></div>Личный кабинет
</a></li>
</ul>
</div>
</div>
<div class="main_content">
</div>
</div>
Use this css
.main_menu_content_list > li.haveSubmenu > a:after{
content: '';
position: absolute;
border: solid 10px;
border-color: transparent #F0F6F8 transparent transparent;
right: 0;
opacity: 0;
}
.main_menu_content_list > li.haveSubmenu:hover > a:after{
opacity: 1;
}
.main {
font-family: PT Sans;
position: relative;
display: flex;
flex-direction: row;
min-height: 100%;
}
.main_menu {
display: flex;
flex-direction: column;
width: auto;
background-color: #38618C;
padding: 50px 0 0 0;
z-index: 1000;
}
.main_menu_content {
display: flex;
flex-direction: column;
position: sticky;
top: 50px;
width: 100%;
}
.main_menu_content_list {
display: flex;
flex-direction: column;
justify-content: space-between;
text-align: center;
height: 700px;
width: 250px;
}
.main_menu_content_list li {
list-style-type: none;
}
.main_menu_content_list > li.haveSubmenu > a:after{
content: '';
position: absolute;
border: solid 10px;
border-color: transparent #F0F6F8 transparent transparent;
right: 0;
opacity: 0;
}
.main_menu_content_list > li.haveSubmenu:hover > a:after{
opacity: 1;
}
.main_menu_content_list a {
display: flex;
flex-direction: column;
align-items: center;
font-style: normal;
font-weight: normal;
font-size: 18px;
line-height: 23px;
color: #D7DFE8;
text-decoration: none;
}
.main_menu_content_list_sub_block {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 55px;
}
.main_menu_content_list_submenu {
justify-content: center;
position: absolute;
padding: 0;
margin: 0;
left: 100%;
height: 100vh;
background-color: #F0F6F8;
box-shadow: 5px 0px 20px rgba(0, 0, 0, 0.25);
top: -50px;
pointer-events: none;
opacity: 0;
transition: all linear 0.1s 0s;
width: 250px;
}
.main_menu_content_list li:hover .main_menu_content_list_submenu {
opacity: 1;
pointer-events: auto;
}
.main_menu_content_list_submenu_popup li:first-child {
margin: 50px 0 0 0;
}
.main_menu_content_list_submenu_popup li:not(:first-child) {
margin: 10px 0 0 0;
}
.main_menu_content_list li:hover > .main_menu_content_list_submenu {
display: flex;
}
.main_menu_content_list_submenu_popup a {
font-style: normal;
font-weight: normal;
font-size: 16px;
line-height: 21px;
color: #38618C;
}
.main_menu_content_list_submenu_popup a:hover {
color: #38618C;
text-decoration: underline;
}
.main_menu_content_list_submenu_popup a:active {
color: #FF5964;
}
.main_content {
display: flex;
align-items: center;
flex-direction: column;
width: 100%;
max-width: 100%;
height: 100%;
}
<div class="main">
<div class="main_menu">
<div class="main_menu_content">
<ul class="main_menu_content_list">
<li class="haveSubmenu"><a href="">
<div class="main_menu_content_list_int"></div>Интернет
</a>
<div class="main_menu_content_list_submenu">
<ul class="main_menu_content_list_submenu_popup">
<li>Подключение</li>
<li>Дополнительные услуги</li>
<li>Настройка соединения</li>
<li>Подключенные дома</li>
</ul>
</div>
</li>
<li class="haveSubmenu"><a href="">
<div class="main_menu_content_list_tv"></div>Телевидение
</a>
<div class="main_menu_content_list_submenu">
<ul class="main_menu_content_list_submenu_popup">
<li>Подключение</li>
<li>Новости</li>
<li>Акции</li>
<li>Аналоговое ТВ</li>
<li>Оборудование</li>
<li>Настройка каналов</li>
<li>Подключенные дома</li>
<li>Документы</li>
</ul>
</div>
</li>
<li class="haveSubmenu"><a href="">
<div class="main_menu_content_list_video"></div>Видеонаблюдение,<br>домофон
</a>
<div class="main_menu_content_list_submenu">
<ul class="main_menu_content_list_submenu_popup">
<li>Обслуживание</li>
<li>Установка</li>
<li>Заявка на ремонт</li>
<li>Подключение</li>
</ul>
</div>
</li>
<li><a href="">
<div class="main_menu_content_list_tvr"></div>ТВ Реклама
</a></li>
<li><a href="">
<div class="main_menu_content_list_intb"></div>Интернет для бизнеса
</a></li>
<div class="main_menu_content_list_sub_block">
<li>Оплата</li>
<li>О компании</li>
</div>
<li><a href="">
<div class="main_menu_content_list_sub_account"></div>Личный кабинет
</a></li>
</ul>
</div>
</div>
<div class="main_content">
</div>
You can draw the arrow with border properties and add to the corresponding submenu popup ::before for styling. Then, adjust the position of the arrow with top property for each submenu.
/* Add the following CSS configuration */
li:first-child ul.main_menu_content_list_submenu_popup::before {
top: 4.5rem;
}
li:nth-child(2) ul.main_menu_content_list_submenu_popup::before {
top: 11rem;
}
li:nth-child(3) ul.main_menu_content_list_submenu_popup::before {
top: 18rem;
}
ul.main_menu_content_list_submenu_popup::before {
position: absolute;
content: "";
border-color: transparent;
border-style: solid;
left: -0.5rem;
border-width: .5rem .5rem .5rem 0;
border-right-color: #F0F6F8;
}
.main {
font-family: PT Sans;
position: relative;
display: flex;
flex-direction: row;
min-height: 100%;
}
.main_menu {
display: flex;
flex-direction: column;
width: auto;
background-color: #38618C;
padding: 50px 0 0 0;
z-index: 1000;
}
.main_menu_content {
display: flex;
flex-direction: column;
position: sticky;
top: 50px;
width: 100%;
}
.main_menu_content_list {
display: flex;
flex-direction: column;
justify-content: space-between;
text-align: center;
height: 700px;
width: 250px;
}
.main_menu_content_list li {
list-style-type: none;
}
.main_menu_content_list a {
display: flex;
flex-direction: column;
align-items: center;
font-style: normal;
font-weight: normal;
font-size: 18px;
line-height: 23px;
color: #D7DFE8;
text-decoration: none;
}
.main_menu_content_list_sub_block {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 55px;
}
.main_menu_content_list_submenu {
justify-content: center;
position: absolute;
padding: 0;
margin: 0;
left: 100%;
height: 100vh;
background-color: #F0F6F8;
box-shadow: 5px 0px 20px rgba(0, 0, 0, 0.25);
top: -50px;
pointer-events: none;
opacity: 0;
transition: all linear 0.1s 0s;
width: 250px;
}
.main_menu_content_list li:hover .main_menu_content_list_submenu {
opacity: 1;
pointer-events: auto;
}
.main_menu_content_list_submenu_popup li:first-child {
margin: 50px 0 0 0;
}
.main_menu_content_list_submenu_popup li:not(:first-child) {
margin: 10px 0 0 0;
}
.main_menu_content_list li:hover > .main_menu_content_list_submenu {
display: flex;
}
.main_menu_content_list_submenu_popup a {
font-style: normal;
font-weight: normal;
font-size: 16px;
line-height: 21px;
color: #38618C;
}
.main_menu_content_list_submenu_popup a:hover {
color: #38618C;
text-decoration: underline;
}
.main_menu_content_list_submenu_popup a:active {
color: #FF5964;
}
.main_content {
display: flex;
align-items: center;
flex-direction: column;
width: 100%;
max-width: 100%;
height: 100%;
}
/* Add the following CSS configuration */
li:first-child ul.main_menu_content_list_submenu_popup::before {
top: 4.5rem;
}
li:nth-child(2) ul.main_menu_content_list_submenu_popup::before {
top: 11rem;
}
li:nth-child(3) ul.main_menu_content_list_submenu_popup::before {
top: 18rem;
}
ul.main_menu_content_list_submenu_popup::before {
position: absolute;
content: "";
border-color: transparent;
border-style: solid;
left: -0.5rem;
border-width: .5rem .5rem .5rem 0;
border-right-color: #F0F6F8;
}
<div class="main">
<div class="main_menu">
<div class="main_menu_content">
<ul class="main_menu_content_list">
<li><a href="">
<div class="main_menu_content_list_int"></div>Интернет
</a>
<div class="main_menu_content_list_submenu">
<ul class="main_menu_content_list_submenu_popup">
<li>Подключение</li>
<li>Дополнительные услуги</li>
<li>Настройка соединения</li>
<li>Подключенные дома</li>
</ul>
</div>
</li>
<li><a href="">
<div class="main_menu_content_list_tv"></div>Телевидение
</a>
<div class="main_menu_content_list_submenu">
<ul class="main_menu_content_list_submenu_popup">
<li>Подключение</li>
<li>Новости</li>
<li>Акции</li>
<li>Аналоговое ТВ</li>
<li>Оборудование</li>
<li>Настройка каналов</li>
<li>Подключенные дома</li>
<li>Документы</li>
</ul>
</div>
</li>
<li><a href="">
<div class="main_menu_content_list_video"></div>Видеонаблюдение,<br>домофон
</a>
<div class="main_menu_content_list_submenu">
<ul class="main_menu_content_list_submenu_popup">
<li>Обслуживание</li>
<li>Установка</li>
<li>Заявка на ремонт</li>
<li>Подключение</li>
</ul>
</div>
</li>
<li><a href="">
<div class="main_menu_content_list_tvr"></div>ТВ Реклама
</a></li>
<li><a href="">
<div class="main_menu_content_list_intb"></div>Интернет для бизнеса
</a></li>
<div class="main_menu_content_list_sub_block">
<li>Оплата</li>
<li>О компании</li>
</div>
<li><a href="">
<div class="main_menu_content_list_sub_account"></div>Личный кабинет
</a></li>
</ul>
</div>
</div>
<div class="main_content">
</div>
</div>