#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;
}
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 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.
This page is a grid container with some images as posts-list, header, and left menu:
JSFiddle1
When I hover over images two links: "comments" and "view posts" would appear. I want to use the CSS and when I click on either of these two it leads me to something like this:
JSFiddle
I wanted to use display: none; but I don't know where should I put it.
if I understand your question correctly, this is a possible solution to your problem.
function changeContainer(){
if($('.grid-container-before').css('visibility') === 'visible') {
$('.grid-container-before').css('visibility','hidden');
$('.grid-container-before').css('display','none');
$('.grid-container-after').css('visibility','visible');
$('.grid-container-after').css('display','grid');
}
}
body {
padding-top: 73px;
overflow-y: hidden;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
/* ------------ PAGE SCROLLBAR ------------ */
*::-webkit-scrollbar {
width: 2px;
}
*::-webkit-scrollbar-track {
background: white;
}
*::-webkit-scrollbar-thumb {
background-color: grey;
border-radius: 20px;
height: 2px;
}
/* ------------ navbar ------------ */
.header {
display: flex;
position: fixed;
background-color: white;
width: 100%;
justify-content: space-between;
z-index: 7;
font-family: Libre Franklin;
top: 0;
left: 0;
}
.header-flex-list {
display: flex;
margin-top: 10px;
justify-content: flex-end;
flex: 50%;
}
.header-list {
list-style: none;
display: flex;
}
.header-list a {
text-decoration: none;
color: #000;
font-size: 12px;
padding: 0px 20px 0px 20px;
}
.top-icon-container {
display: flex;
padding: 10px 50px;
flex-wrap: wrap;
}
.icon-column {
width: 10%;
border-radius: 50px;
}
.p-column {
width: 28%;
padding-left: 10px;
}
#top-bar-icon {
display: block;
max-width: 100%;
height: auto;
object-fit: cover;
border-radius: 50px;
border: 2px solid #73AD21;
}
/* ------------ LEFT MENU ------------ */
.container {
display: flex;
justify-content: space-between;
height: 100vh;
}
.left-menu {
width: 18%;
order: 1;
height: 100vh;
/* overflow-y: scroll; */
padding: 0px 0px 10px 45px;
}
.menu-list {
list-style: none;
line-height: 2.5rem;
/* display: flex;
flex-direction: column; */
margin-left: -25px;
}
.menu-list a {
text-decoration: none;
}
/* ------------ MAIN POSTS ------------ */
.main-posts {
width: 100%;
order: 2;
padding: 0px 20px 0px 20px;
overflow-y: auto;
text-align: center;
scrollbar-width: thin;
scrollbar-color: grey white;
}
/* ------------ MAIN POSTS LISTS ------------ */
.grid-container-before {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(480px, 1fr));
grid-gap: 1rem;
width: 100%;
margin: 0 auto;
margin-bottom: 6rem;
visibility: visible;
}
.grid-container-after {
display: grid;
grid-template-columns: 80% 1fr;
grid-gap: 10px;
height: 300px;
visibility: hidden;
display:none;
}
.box {
background-color: #20262e;
color: #fff;
border-radius: 3px;
padding: 20px;
font-size: 14px;
}
.posts {
display: flex;
}
.img__wrap {
position: relative;
}
.posts-image {
height: 350px;
width: 100%;
object-fit: cover;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: white;
color: #000;
visibility: hidden;
opacity: 0;
/* transition effect. not necessary */
transition: opacity 0.2s, visibility 0.2s;
}
.text {
color: white;
font-size: 15px;
position: absolute;
top: 50%;
left: 50%;
width: 100%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
.text a {
color: #000;
text-decoration: none;
padding-right: 20px;
}
[data-title]::after {
content: attr(data-title);
background-color: #000;
color: #fff;
font-size: 13px;
;
position: absolute;
padding: 10px;
bottom: -3.6em;
left: 50%;
white-space: nowrap;
box-shadow: 1px 1px 3px #222222;
opacity: 0;
border: 1px solid #111111;
z-index: 99999;
visibility: hidden;
}
[data-title]:hover::after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title] {
position: relative;
}
.img__wrap:hover .overlay {
visibility: visible;
opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<head>
<link href="//fonts.googleapis.com/css?family=Karla|Syne|Libre+Franklin|Bai+Jamjuree|Chakra+Petch|Gotu" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<!------------ TOP MENU ------------>
<header id="header" class="header">
<div id="top-container" class="top-icon-container">
<div class="icon-column">
<img id="top-bar-icon" src="https://s4.uupload.ir/files/top-bar-icon_ensh.png" alt="my logo:)">
</div>
<div class="p-column">
<p>Name it what u want!</p>
</div>
</div>
<div class="header-flex-list">
<ul class="header-list">
<li>TERMS OF USE</li>
<li>HAVE A QUESTION</li>
<li>ABOUT ME</li>
</ul>
</div>
</header>
<body>
<div class="container">
<!------------ LEFT MENU ------------>
<nav id="menu" class="left-menu">
<p style="text-decoration: none; color: black;">Filter by:</p>
<ul class="menu-list">
<li><a>Popular pages</a></li>
<li><a>About pages</a></li>
<li><a>Character pages</a></li>
<li><a>Music pages</a></li>
</ul>
</nav>
<!------------ MAIN POSTS ------------>
<section id="main-content" class="main-posts">
<div class="grid-container-before">
<div class="img__wrap">
<img class="posts-image" src="https://www.webdevelopersnotes.com/wp-content/uploads/random-image-display-using-javascript-2.png" alt="project" />
<div class="overlay">
<div class="text">
<button href="#" data-title="comments" onclick="changeContainer()">
<i class="fa fa-comments fa-fw"></i>comment</button>
<button href="#" data-title="view post" onclick="changeContainer()">
<i class="fa fa-external-link fa-fw"></i></button>
</div>
</div>
</div>
</div>
<div class="grid-container-after">
<div class="box a">A</div>
<div class="box b">B</div>
</div>
</section>
</div>
</body>
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>
I have created the following list within a div that is centered by flex.
As you can see in the snippet, the list is not centered (as I would expect with using flex on the list-div2 and the translate rule in the parents middle-text div.
Can someone help me? Why does it not get centered properly?
body {
margin: 0;
}
.container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
height: 100vh;
background-color: white;
}
.container>div {
min-height: 100vh;
border: 1px solid black;
box-sizing: border-box;
background-color: inherit;
}
.container>div .content {
height: 100vh;
width: 100vw;
background-color: inherit;
}
.full-width {
width: 100%;
}
.half-width {
width: 50%;
}
.full-width>.content>.third-parent {
height: 100%;
display: flex;
flex-direction: row;
}
.full-width>.content>.third-parent>.third {
position: relative;
flex: 1 1 0px;
border: 1px solid black;
width: 100%;
}
.full-width>.content>.third-parent>.third>img {
position: absolute;
width: 100%;
height: auto;
left: 50%;
top: 50%;
visibility: visible;
text-align: center;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.middle-text {
position: absolute;
width: 100%;
left: 50%;
top: 50%;
visibility: visible;
text-align: center;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.full-width>.content>.third-parent>.third>.middle-text>.list-div2 {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
.full-width>.content>.third-parent>.third>.middle-text>.list-div2 li {
position: relative;
display: block;
border: 1px solid red;
margin-bottom: 5px;
padding: 10px;
text-align: center;
text-transform: uppercase;
visibility: visible;
list-style-type: bullet;
}
<div class="container">
<div class="full-width">
<div class="content">
<div class="third-parent">
<div class="third" id="one">
<img src="https://fakeimg.pl/350x200/?text=left">
</div>
<div class="third" id="two">
<div class="middle-text">
<h1>Headline</h1>
<div class="list-div2">
<ul class="items-list2" id="list">
<li>Entry A</li>
<li>Entry B</li>
<li>Entry C</li>
<li>Entry D</li>
</ul>
</div>
</div>
</div>
<div class="third" id="three">
<img src="https://fakeimg.pl/350x200/?text=right">
</div>
</div>
</div>
</div>
</div>
That's because of the padding/margin that browsers add to the ul tag by default.
Example:
body {
margin: 0;
}
.container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
height: 100vh;
background-color: white;
}
.container>div {
min-height: 100vh;
border: 1px solid black;
box-sizing: border-box;
background-color: inherit;
}
.container>div .content {
height: 100vh;
width: 100vw;
background-color: inherit;
}
.full-width {
width: 100%;
}
.half-width {
width: 50%;
}
.full-width>.content>.third-parent {
height: 100%;
display: flex;
flex-direction: row;
}
.full-width>.content>.third-parent>.third {
position: relative;
flex: 1 1 0px;
border: 1px solid black;
width: 100%;
}
.full-width>.content>.third-parent>.third>img {
position: absolute;
width: 100%;
height: auto;
left: 50%;
top: 50%;
visibility: visible;
text-align: center;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.middle-text {
position: absolute;
width: 100%;
left: 50%;
top: 50%;
visibility: visible;
text-align: center;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.full-width>.content>.third-parent>.third>.middle-text>.list-div2 {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
.full-width>.content>.third-parent>.third>.middle-text>.list-div2 li {
position: relative;
display: block;
border: 1px solid red;
margin-bottom: 5px;
padding: 10px;
text-align: center;
text-transform: uppercase;
visibility: visible;
list-style-type: bullet;
}
.items-list2 {
margin: 0;
padding: 0;
}
<div class="container">
<div class="full-width">
<div class="content">
<div class="third-parent">
<div class="third" id="one">
<img src="https://fakeimg.pl/350x200/?text=left">
</div>
<div class="third" id="two">
<div class="middle-text">
<h1>Headline</h1>
<div class="list-div2">
<ul class="items-list2" id="list">
<li>Entry A</li>
<li>Entry B</li>
<li>Entry C</li>
<li>Entry D</li>
</ul>
</div>
</div>
</div>
<div class="third" id="three">
<img src="https://fakeimg.pl/350x200/?text=right">
</div>
</div>
</div>
</div>
</div>
Actually user agent stylesheet have padding left. So you need to overwrite that style by ul{padding-left: 0}
ul, menu, dir {
display: block;
list-style-type: disc;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 40px;
}
You should give padding: 0; to your ul
ul.items-list2 {
padding: 0;
}
The W3C spec says ul has as default margin of 40px, but different browsers over ride this. So its always good to normalize margins and paddings.
body {
margin: 0;
}
ul.items-list2 {
padding: 0;
}
.container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
height: 100vh;
background-color: white;
}
.container>div {
min-height: 100vh;
border: 1px solid black;
box-sizing: border-box;
background-color: inherit;
}
.container>div .content {
height: 100vh;
width: 100vw;
background-color: inherit;
}
.full-width {
width: 100%;
}
.half-width {
width: 50%;
}
.full-width>.content>.third-parent {
height: 100%;
display: flex;
flex-direction: row;
}
.full-width>.content>.third-parent>.third {
position: relative;
flex: 1 1 0px;
border: 1px solid black;
width: 100%;
}
.full-width>.content>.third-parent>.third>img {
position: absolute;
width: 100%;
height: auto;
left: 50%;
top: 50%;
visibility: visible;
text-align: center;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.middle-text {
position: absolute;
width: 100%;
left: 50%;
top: 50%;
visibility: visible;
text-align: center;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.full-width>.content>.third-parent>.third>.middle-text>.list-div2 {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
.full-width>.content>.third-parent>.third>.middle-text>.list-div2 li {
position: relative;
display: block;
border: 1px solid red;
margin-bottom: 5px;
padding: 10px;
text-align: center;
text-transform: uppercase;
visibility: visible;
list-style-type: bullet;
}
<div class="container">
<div class="full-width">
<div class="content">
<div class="third-parent">
<div class="third" id="one">
<img src="https://fakeimg.pl/350x200/?text=left">
</div>
<div class="third" id="two">
<div class="middle-text">
<h1>Headline</h1>
<div class="list-div2">
<ul class="items-list2" id="list">
<li>Entry A</li>
<li>Entry B</li>
<li>Entry C</li>
<li>Entry D</li>
</ul>
</div>
</div>
</div>
<div class="third" id="three">
<img src="https://fakeimg.pl/350x200/?text=right">
</div>
</div>
</div>
</div>
</div>