I want to remove the first line from the CSS timeline I created, I just want the timeline circle to show up first not to have a line before it. I also want to style each dot different color, how can I do both these?
I have tried to add a class to one of the timeline containers called .not_complete but it doesnt change the color of the circle of the timeline.
/* The actual timeline (the vertical ruler) */
.timelinex {
position: relative;
max-width: 1200px;
margin: 0 auto;
padding-bottom: 5em;
}
/* The actual timeline (the vertical ruler) */
.timelinex:before {
content: '';
position: absolute;
width: 0px;
background-color: #fff;
top: auto;
bottom: 0;
left: 50%;
margin-left: -3px;
}
.timelinex::after {
content: '';
position: absolute;
width: 4px;
background-color: #e3e3e3;
top: 0;
bottom: 0;
left: 50%;
margin-left: -3px;
}
/* Container around content */
.containerx {
padding: 10px 40px;
position: relative;
background-color: inherit;
width: 50%;
}
/* The circles on the timeline */
.containerx::after {
content: '';
position: absolute;
width: 12px;
height: 12px;
right: -5px;
background-color: #e3e3e3;
top: 15px;
border-radius: 50%;
z-index: 1;
}
.containerx::after .not_complete {
background-color: #e3e3e3 !important;
}
/* Place the container to the left */
.leftx {
left: 0;
}
/* Place the container to the right */
.rightx {
left: 50%;
}
/* Fix the circle for containers on the right side */
.rightx::after {
left: -7px;
}
/* The actual content */
.contentx {
padding: 2px 3px;
position: relative;
border-radius: 6px;
}
<div class="timelinex">
<div class="containerx leftx not_complete">
<div class="contentx">
<p>
<img src="assets/img/therapist1.jpg" style="border-radius: 0.5em;border-top-left-radius: 120px; border-bottom-right-radius: 120px">
</p>
<h5 style="color:#999;font-style: 0.5em"> DAY 1 </h5>
<div> Test Timeline Step 1</div>
</div>
</div>
</div>
The selector here is invalid:
.containerx::after .not_complete {
It would select the child of the ::after pseudo element. You need to use:
.containerx.not_complete::after {
The above selector selects any element's ::after pseudo element, with the classes containerx and not_complete. So kindly replace your code with:
.containerx.not_complete::after {
background-color: #e3e3e3 !important;
}
Hope this solves your issue.
Complete Snippet
/* The actual timeline (the vertical ruler) */
.timelinex {
position: relative;
max-width: 1200px;
margin: 0 auto;
padding-bottom: 5em;
}
/* The actual timeline (the vertical ruler) */
.timelinex:before {
content: '';
position: absolute;
width: 0px;
background-color: #fff;
top: auto;
bottom: 0;
left: 50%;
margin-left: -3px;
}
.timelinex::after {
content: '';
position: absolute;
width: 4px;
background-color: #e3e3e3;
top: 0;
bottom: 0;
left: 50%;
margin-left: -3px;
}
/* Container around content */
.containerx {
padding: 10px 40px;
position: relative;
background-color: inherit;
width: 50%;
}
/* The circles on the timeline */
.containerx::after {
content: '';
position: absolute;
width: 12px;
height: 12px;
right: -5px;
background-color: #e3e3e3;
top: 15px;
border-radius: 50%;
z-index: 1;
}
.containerx.not_complete::after {
background-color: #e3e3e3 !important;
}
/* Place the container to the left */
.leftx {
left: 0;
}
/* Place the container to the right */
.rightx {
left: 50%;
}
/* Fix the circle for containers on the right side */
.rightx::after {
left: -7px;
}
/* The actual content */
.contentx {
padding: 2px 3px;
position: relative;
border-radius: 6px;
}
<div class="timelinex" >
<div class="containerx leftx not_complete">
<div class="contentx">
<p><img src="assets/img/therapist1.jpg" style="border-radius: 0.5em;border-top-left-radius: 120px; border-bottom-right-radius: 120px"></p>
<h5 style="color:#999;font-style: 0.5em"> DAY 1 </h5>
<div> Test Timeline Step 1</div>
</div>
</div>
</div>
Update: For Even / Odd Styling and First Child.
To create odd and even styling, you need to use :nth-child() selector. An example of having it blue and red is here:
li {
display: block;
width: 200px;
padding: 10px;
color: #fff;
}
li:nth-child(odd) {
background: #00f;
}
li:nth-child(even) {
background: #f00;
}
li:first-child {
background: #000;
font-weight: bold;
}
<ul>
<li>First Child</li>
<li>Even</li>
<li>Odd</li>
<li>Even</li>
<li>Odd</li>
</ul>
Related
How to place a vertical line between two div elements?
.flex-container {
display: -webkit-flex;
margin: 0 auto;
text-align: center;
}
.flex-container .column {
width: 320px;
text-align: center;
}
.vr {
border-left: 2px dotted black;
width: 2px;
margin: 0px 5px 0px 5px;
height: 200px;
}
<div>
<div class="flex-container mt-3 d-flex justify-content-center align-items-center">
<div class="column">Karvat group was established in Mumbai.</div>
<div class="vr "></div>
<div class="column2 bg-alt box arrow-left ml-15 "> 1952</div>
</div>
</div>
Rough way of getting this done.
HTML
<div class="timeline">
<div class="container left">
<div class="content">
<h2>2017</h2>
<p>Lorem ipsum..</p>
</div>
</div>
<div class="container right">
<div class="content">
<h2>2016</h2>
<p>Lorem ipsum..</p>
</div>
</div>
</div>
CSS
* {
box-sizing: border-box;
}
/* Set a background color */
body {
background-color: #474e5d;
font-family: Helvetica, sans-serif;
}
/* The actual timeline (the vertical ruler) */
.timeline {
position: relative;
max-width: 1200px;
margin: 0 auto;
}
/* The actual timeline (the vertical ruler) */
.timeline::after {
content: '';
position: absolute;
width: 6px;
background-color: white;
top: 0;
bottom: 0;
left: 50%;
margin-left: -3px;
}
/* Container around content */
.container {
padding: 10px 40px;
position: relative;
background-color: inherit;
width: 50%;
}
/* The circles on the timeline */
.container::after {
content: '';
position: absolute;
width: 25px;
height: 25px;
right: -17px;
background-color: white;
border: 4px solid #FF9F55;
top: 15px;
border-radius: 50%;
z-index: 1;
}
/* Place the container to the left */
.left {
left: 0;
}
/* Place the container to the right */
.right {
left: 50%;
}
/* Add arrows to the left container (pointing right) */
.left::before {
content: " ";
height: 0;
position: absolute;
top: 22px;
width: 0;
z-index: 1;
right: 30px;
border: medium solid white;
border-width: 10px 0 10px 10px;
border-color: transparent transparent transparent white;
}
/* Add arrows to the right container (pointing left) */
.right::before {
content: " ";
height: 0;
position: absolute;
top: 22px;
width: 0;
z-index: 1;
left: 30px;
border: medium solid white;
border-width: 10px 10px 10px 0;
border-color: transparent white transparent transparent;
}
/* Fix the circle for containers on the right side */
.right::after {
left: -16px;
}
/* The actual content */
.content {
padding: 20px 30px;
background-color: white;
position: relative;
border-radius: 6px;
}
/* Media queries - Responsive timeline on screens less than 600px wide */
#media screen and (max-width: 600px) {
/* Place the timelime to the left */
.timeline::after {
left: 31px;
}
/* Full-width containers */
.container {
width: 100%;
padding-left: 70px;
padding-right: 25px;
}
/* Make sure that all arrows are pointing leftwards */
.container::before {
left: 60px;
border: medium solid white;
border-width: 10px 10px 10px 0;
border-color: transparent white transparent transparent;
}
/* Make sure all circles are at the same spot */
.left::after, .right::after {
left: 15px;
}
/* Make all right containers behave like the left ones */
.right {
left: 0%;
}
}
Output:
Here is the sample code for it, You can also take some help from online codepen's https://codepen.io/havardob/pen/dyKoOjX
.stepper{
height: 400px;
width: 1px;
border-right: 2px dashed black;
position: relative;
}
.stepper:before,
.stepper:after
{
content: "";
position: absolute;
width: 10px;
height: 10px;
right: -7px;
border-radius: 50%;
border: 1px solid black;
background: #fff;
}
.stepper:after{
top: 50px;
}
<div class="stepper">
</div>
I am not sure why the position for the circle and container for the left side can't fix like the right side. When I resize the screen, the circle of the right container can still remind in the middle of the line but the left side cant. Does anyone know what is the error?
.timeline {
position: relative;
max-width: 100%;
margin: 0 auto;
}
.timeline::after {
content: '';
position: absolute;
width: 0.375em;
background-color: #D5D5D5;
top: 0;
bottom: 0;
left: 50%;
margin-left: -0.1875em;
}
.container2 {
padding: 0.625em 2.5em;
position: relative;
background-color: inherit;
width: 40%;
}
.container2::after {
content: '';
position: absolute;
width: 1.5625em;
height: 1.5625em;
right: -1.0625em;
background-color: white;
border: 0.25em solid #86B5D0;
top: 0.9375em;
border-radius: 50%;
z-index: 1;
}
.left {
left: 2.2%;
}
.right {
left: 50%;
}
.right::after {
left: -1em;
}
.left::before {
content: " ";
height: 0;
position: absolute;
top: 1.375em;
width: 0;
z-index: 1;
right: 1.875em;
border: medium solid #2D336A;
border-width: 0.625em 0 0.625em 0.625em;
border-color: transparent transparent transparent #2D336A;
}
.right::before {
content: " ";
height: 0;
position: absolute;
top: 1.375em;
width: 0;
z-index: 1;
left: 1.875em;
border: medium solid #2D336A;
border-width: 0.625em 0.625em 0.625em 0;
border-color: transparent #2D336A transparent transparent;
}
.content {
padding: 1.25em 1.875em;
background-color: #2D336A;
position: relative;
border-radius: 0.375em;
}
#media screen and (max-width: 40%) {
/* Place the timelime to the left */
.timeline::after {
left: 1.9375em;
}
/* Full-width containers */
.container2 {
width: 100%;
padding-left: 4.375em;
padding-right: 1.5625em;
}
/* Make sure that all arrows are pointing leftwards */
.container2::before {
left: 3.75em;
border: medium solid white;
border-width: 0.625em 0.625em 0.625em 0;
border-color: transparent white transparent transparent;
}
/* Make sure all circles are at the same spot */
.left::after,
.right::after {
left: 0.9375em;
}
/* Make all right containers behave like the left ones */
.right {
left: 0%;
}
}
<div class="timeline">
<div class="container2 left">
<div class="content">
<font class="titleText1">1</font><br><br> ABC
</div>
</div>
<div class="container2 right">
<div class="content">
<font class="titleText">2</font><br><br> ABC
</div>
</div>
</div>
Your .container2 elements are positioned with relative so that they remain in a vertical flow. When you position the .right one with left: 50%, it shifts it exactly over the timeline: great!
Now you'd like to do the opposite for the .left one, which would be right: 50%. But that won't work as it's not positioned in absolute, so it will shift from its natural position within the page flow.
Fix this by setting it float: right so it starts from the far right and ends up spot-on the timeline. But it breaks the flow again.
So add clear: both to .container2 to restore vertical flow and you're finally there.
One of the very rare instances where float can actually help!
.timeline {
position: relative;
max-width: 100%;
margin: 0 auto;
}
.timeline::after {
content: '';
position: absolute;
width: 0.375em;
background-color: #D5D5D5;
top: 0;
bottom: 0;
left: 50%;
margin-left: -0.1875em;
}
.container2 {
clear: both; /* Add this */
padding: 0.625em 2.5em;
position: relative;
background-color: inherit;
width: 40%;
}
.container2::after {
content: '';
position: absolute;
width: 1.5625em;
height: 1.5625em;
right: -1.0625em;
background-color: white;
border: 0.25em solid #86B5D0;
top: 0.9375em;
border-radius: 50%;
z-index: 1;
}
.left {
float: right; /* Add this */
right: 50%; /* Change this */
}
.right {
left: 50%;
}
.right::after {
left: -1em;
}
.left::before {
content: " ";
height: 0;
position: absolute;
top: 1.375em;
width: 0;
z-index: 1;
right: 1.875em;
border: medium solid #2D336A;
border-width: 0.625em 0 0.625em 0.625em;
border-color: transparent transparent transparent #2D336A;
}
.right::before {
content: " ";
height: 0;
position: absolute;
top: 1.375em;
width: 0;
z-index: 1;
left: 1.875em;
border: medium solid #2D336A;
border-width: 0.625em 0.625em 0.625em 0;
border-color: transparent #2D336A transparent transparent;
}
.content {
padding: 1.25em 1.875em;
background-color: #2D336A;
position: relative;
border-radius: 0.375em;
}
#media screen and (max-width: 40%) {
/* Place the timelime to the left */
.timeline::after {
left: 1.9375em;
}
/* Full-width containers */
.container2 {
width: 100%;
padding-left: 4.375em;
padding-right: 1.5625em;
}
/* Make sure that all arrows are pointing leftwards */
.container2::before {
left: 3.75em;
border: medium solid white;
border-width: 0.625em 0.625em 0.625em 0;
border-color: transparent white transparent transparent;
}
/* Make sure all circles are at the same spot */
.left::after,
.right::after {
left: 0.9375em;
}
/* Make all right containers behave like the left ones */
.right {
left: 0%;
}
}
<div class="timeline">
<div class="container2 left">
<div class="content">
<font class="titleText1">1</font><br><br> ABC
</div>
</div>
<div class="container2 right">
<div class="content">
<font class="titleText">2</font><br><br> ABC
</div>
</div>
</div>
How would I go about making this in CSS3/HTML5?
The Red background is the background of the div. The inner white is another div that will contain some text.
Since you already have 2 containers, you can use two pairs of pseudo elements for the corners, like this:
.outer {
width: 120px;
background: #a08;
position: relative;
padding: 30px;
}
.inner {
height: 118px;
background: #fff;
border: 1px dashed #a08;
flex: 1;
}
.outer::before, .outer::after, .inner::before, .inner::after {
content: '';
width: 20px;
height: 20px;
background: #a08;
background-clip: padding-box;
border: 1px dashed #a08;
border-radius: 50%;
position: absolute;
z-index: 1;
}
.outer::before {
top: 20px;
left: 20px;
}
.outer::after {
top: 20px;
right: 20px;
}
.inner::before {
bottom: 20px;
left: 20px;
}
.inner::after {
bottom: 20px;
right: 20px;
}
<div class="outer">
<div class="inner"></div>
</div>
I'd like some help to integrate a design made on sketch 2 years ago ! The goal is to do a beautiful orderer list but I have difficulties to integrate the content.
This is what i've done so far :
HTML :
<div class="stepbar_block">
<ol class="stepbar_list">
<li class="stepbar_list_elem_active"> 50% </li>
<li class="stepbar_list_item">60% </li>
<li class="stepbar_list_item">70%</li>
<li class="stepbar_list_elem_current">80%</li>
<li class="stepbar_list_item">90%</li>
</ol>
</div>
CSS :
.stepbar_block {
margin: 0;
padding: 0;
counter-reset: step;
position: relative;
margin-top: 40px;
}
.stepbar_block:before {
width: 1px;
height :10px;
background-color : rgba(87,87,86,0.3);
content : '';
position : absolute;
left : 30px;
top : -4px;
}
.stepbar_block:after {
width: 1px;
height :10px;
background-color : rgba(87,87,86,0.3);
content : '';
position : absolute;
right : 30px;
top : -4px;
}
.stepbar_list li {
list-style-type: none;
float: left;
width: 20%;
height : 5px;
position: relative;
font-family: Roboto;
font-size: 10px;
line-height: 11px;
text-align: center;
color: rgba(87,87,86,0.5);
}
.stepbar_list:after {
content: '';
position: absolute;
height: 1px;
background-color: rgba(87,87,86,0.3);
left: 30px;
right: 30px;
z-index: 3;
}
.stepbar_list li:before {
content : '';
counter-increment: step;
width: 5px;
height: 5px;
border: 1px solid black;
display: block;
background-color : black;
border-radius: 40px;
text-align: center;
margin: -2px auto 10px auto;
}
.stepbar_list_item:after {
content: counter(step);
position: absolute;
top: -25px;
background-color: white;
left: 0;
right: 0;
color: rgba(87,87,86,0.5);
font-size: 10px;
line-height: 11px; text-align: center;
}
.stepbar_list_elem_active:after {
content: counter(step);
position: absolute;
top: -25px;
background-color: red;
left: 0;
right: 0;
}
.stepbar_list_elem_current:after {
content: counter(step);
position: absolute;
top: -25px;
background-color: blue;
left: 0;
right: 0;
}
https://jsfiddle.net/zawt9hL6/
However I'm able to colorise the items but not the circles, so I'd like to know what is missing because when I play with :before and :after it seems to colorize the whole list item and not a specific content
That is the result i'd like to have
It is possible to have a render like this ? Moreover it's a gradiant background on the circles..
THank you for advices
Use something like this for all.
.stepbar_list_elem_active:before {
width: 10px;
height: 10px;
background-color: #fff;
content: '';
position: absolute;
left: 0;
top: -6px;
border: 2px solid red;
border-radius: 50%;
right: 0;
margin: 0 auto;
}
You can use :before and :after pseudo elements to create that circle with gradient. First you can create just regular circle with gradient and then add one more white circle with other pseudo-element on top of the frist one.
10* {
box-sizing: border-box;
}
ul {
display: inline-flex;
list-style: none;
position: relative;
padding: 0;
margin: 0 50px;
}
ul:after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 2px;
background: gray;
}
li {
padding: 25px;
position: relative;
}
li:after,
li.color:before {
position: absolute;
content: '';
bottom: 0;
left: 50%;
height: 10px;
width: 10px;
background: gray;
border-radius: 50%;
transform: translate(-50%, 40%);
z-index: 1;
}
li.color:after {
width: 20px;
height: 20px;
transform: translate(-50%, 9px);
}
li.color:before {
background: white;
z-index: 2;
width: 10px;
height: 10px;
}
li.yellow:after {
background: linear-gradient(to right, rgba(240,184,88,1) 0%, rgba(230,139,60,1) 38%, rgba(240,47,23,1) 71%, rgba(231,56,39,1) 100%);
}
li.blue:after {
background: linear-gradient(to right, rgba(52,163,247,1) 0%, rgba(52,163,247,1) 32%, rgba(19,100,158,1) 71%, rgba(19,100,158,1) 100%);
}
.yellow {
color: #ED4620;
}
.blue {
color: #64A3D1;
}
<ul>
<li>1</li>
<li class="color yellow">2</li>
<li class="color blue">3</li>
<li>4</li>
</ul>
I want to show three horizontal dots (I've made a demo on jsfiddle)
span {
position: relative;
background-color: blue;
border-radius: 5px;
font-size: 0;
margin-left: 20px;
padding: 5px;
}
span:before {
position: absolute;
left: -10px;
content: '';
background-color: green;
border-radius: 5px;
font-size: 0;
margin-left: 35px;
padding: 5px;
}
span:after {
position: absolute;
right: 0;
content: '';
background-color: grey;
border-radius: 5px;
font-size: 0;
margin-left: 35px;
padding: 5px;
}
I don't know if this is the best way to achieve this. Also, I want them to line-up horizontally. And I don't understand why they aren't. Any suggestion how to fix this ?
Since you are using absolute positioning, you could use top property to position the pseudo generated contents vertically, and play with left property for horizontal alignment
Example Here
span:before {
position: absolute;
left: -20px; /* <-- align the circle horizontally */
top: 0; /* <-- Added declaration */
content: '';
background-color: green;
border-radius: 5px;
font-size: 0;
padding: 5px;
}
span:after {
position: absolute;
left: 20px; /* <-- align the circle horizontally */
top: 0; /* <-- Added declaration */
content: '';
background-color: grey;
border-radius: 5px;
font-size: 0;
padding: 5px;
}
In this case there's no need to use margin of the pseudo-elements.
Additionally, you could avoid negative values for left property to make the circles appear in the right. (Example Here).
//using left instead of right in after
span {
position: relative;
background-color: blue;
border-radius: 5px;
font-size: 0;
margin-left: 20px;
padding: 5px;
}
span:before {
position: absolute;
left: -10px;
content: '';
top: 0;
background-color: green;
border-radius: 5px;
font-size: 0;
margin-left: 35px;
padding: 5px;
}
span:after {
position: absolute;
left: 10px; //using left instead of right
content: '';
background-color: grey;
border-radius: 5px;
font-size: 0;
margin-left: 35px;
top: 0;
padding: 5px;
}
Check this jsFiddle
HTML
<span></span>
CSS
span {
position: relative;
background-color: blue;
border-radius: 5px;
font-size: 0;
margin-left: 20px;
padding: 5px;
}
span:before {
position: absolute;
left: -20px;
top: 0;
content: '';
background-color: green;
border-radius: 5px;
font-size: 0;
padding: 5px;
}
span:after {
position: absolute;
left: 20px;
top: 0;
content: '';
background-color: grey;
border-radius: 5px;
font-size: 0;
padding: 5px;
}