I would like to add line before li elements but not include after the last li. How could I do?
Here my CSS:
ul.timeline {
list-style-type: none;
position: relative
}
ul.timeline:before {
content: '';
background: #d4d9df;
display: inline-block;
position: absolute;
left: 29px;
width: 2px;
height: 100%;
z-index: 400
}
ul.timeline > li {
margin-bottom: 10px 0;
padding-left: 10px
}
ul.timeline > li:not(:last-child):after {
content: '';
background: white;
display: inline-block;
position: absolute;
border-radius: 50%;
border: 2px solid #22c0e8;
left: 20px;
width: 20px;
height: 20px;
z-index: 400
}
JSFiddle
With your current setup, you could set height of the :before line equal to 100% - li height . Or the last li height. This is not very responsive but without knowing what you really have in your project, this is the best ( imo ) solution.
Also you have margin-bottom: 10px 0 . That is not correct. I changed it to margin-bottom: 10px;
/* Timeline Changelogs */
ul.timeline {
list-style-type: none;
position: relative
}
ul.timeline:before {
content: '';
background: #d4d9df;
display: inline-block;
position: absolute;
left: 31px;
width: 2px;
height: calc(100% - 52px);
z-index: 400
}
ul.timeline > li {
margin-bottom: 10px;
padding-left: 10px
}
ul.timeline > li:not(:last-child):after {
content: '';
background: white;
display: inline-block;
position: absolute;
border-radius: 50%;
border: 2px solid #22c0e8;
left: 20px;
width: 20px;
height: 20px;
z-index: 400
}
<div class="col-12">
<ul class="timeline">
<li>
<p><b>20 Sept 2018</b></p>
<p>This is 20 Sept 2018</p>
</li>
<li>
<p><b>17 Sept 2018</b></p>
<p>This is 17 Sept 2018</p>
</li>
<li>
<p><b>11 Sept 2018</b></p>
<p>This is 11 Sept 2018</p>
</li>
<li>
<p><b>8 Sept 2018</b></p>
<p>This is 8 Sept 2018</p>
</li>
</ul>
</div>
OPTION 2. You could set the before line to the li elements except last-child, not to the ul. And set it a height 100% + 1em. Because in jsfiddle and snippet, p which is inside li has margin: 1em 0 by default. If you change that default margin you should consider that when setting the height.
Also, you need position:relative on li so the :before height is relative to the li not the ul. And so, you need to change the left values for the line and the circle. But it's easily adjustable.
/* Timeline Changelogs */
ul.timeline {
list-style-type: none;
position: relative
}
ul.timeline > li {
margin-bottom: 10px;
padding-left: 10px;
position:relative;
}
ul.timeline > li:not(:last-child):after {
content: '';
background: white;
display: inline-block;
position: absolute;
border-radius: 50%;
border: 2px solid #22c0e8;
left: -21px;
width: 20px;
height: 20px;
z-index: 401
}
ul.timeline > li:not(:last-child):before {
content: '';
background: red;
display: inline-block;
position: absolute;
left: -10px;
width: 2px;
height: calc(100% + 1em);
z-index: 400;
top:0;
}
<div class="col-12">
<ul class="timeline">
<li>
<p><b>20 Sept 2018</b></p>
<p>This is 20 Sept 2018</p>
</li>
<li>
<p><b>17 Sept 2018</b></p>
<p>This is 17 Sept 2018</p>
</li>
<li>
<p><b>11 Sept 2018</b></p>
<p>This is 11 Sept 2018</p>
</li>
<li>
<p><b>8 Sept 2018</b></p>
<p>This is 8 Sept 2018</p>
</li>
</ul>
</div>
Please make these changes to your css file:
/* Timeline Changelogs */
ul.timeline {
list-style-type: none;
position: relative
}
ul.timeline > li {
margin-bottom: 10px;
padding-left: 10px;
}
ul.timeline > li:not(:last-child)::after {
content: '';
background: white;
display: inline-block;
position: absolute;
border-radius: 50%;
border: 2px solid #22c0e8;
left: 20px;
width: 20px;
height: 20px;
z-index: 401
}
ul.timeline > li:not(:last-child)::before {
content: '';
background: red;
display: inline-block;
position: absolute;
left: 31px;
width: 2px;
height: 80px;
z-index: 400
}
There was some issue with height in your css and use ::before in li rather than in ul.
You can use this simple code:
ul {
margin-left: 10px;
padding: 0;
width: 100%;
border-left: 2px solid #999;
}
li {
list-style: none;
padding-left: 20px;
height: 100%;
margin: 0;
display: block;
position: relative;
}
li:last-child:before { /*With this you hide the last-child li line*/
content: '';
position: absolute;
left: -2px;
top: 0;
width: 2px;
height: 100%;
background-color: #fff;
}
li:after {
content: '';
position: absolute;
top: 0;
left: -12px; /*The half of the circle width minus the border width*/
border-radius: 50%;
border: 2px solid #22c0e8;
width: 20px;
height: 20px;
background: #fff;
}
<ul>
<li>
<p><b>Title</b></p>
<p>Subtitle</p>
</li>
<li>
<p><b>Title</b></p>
<p>Subtitle</p>
</li>
<li>
<p><b>Title</b></p>
<p>Subtitle</p>
</li>
<li>
<p><b>Title</b></p>
<p>Subtitle</p>
</li>
</ul>
For hide the li:last-child line I've used a before pseudoelement that goes over the line and hides it. To position the circles I used an after pseudoelement that is located right in the middle of the line. To do this we start from left: 0 minus half of the width of the circle (10) minus the width of the line (2). Both pseudoelements on the li tag.
Hope it helps you!
If you keep the current HTML structure you can do it like in the code bellow. Just moving your before element to each LI element instead of the UL, and changing the margins and paddings of the P elements inside so the left border stretches accordingly.
ul.timeline > li:before {
content: '';
background: #d4d9df;
display: inline-block;
position: absolute;
left: -9px;
width: 2px;
height: 100%;
z-index: 400
}
ul.timeline > li {
margin-bottom: 10px 0;
padding-left: 10px;
position: relative;
}
ul.timeline > li::after {
content: '';
background: white;
display: inline-block;
position: absolute;
border-radius: 50%;
border: 2px solid #22c0e8;
left: -20px;
top: 0px;
width: 20px;
height: 20px;
z-index: 400;
}
ul.timeline > li:last-child:before{
display:none;
}
ul.timeline > li > p{
margin-top: 0px;
padding-top: 0px;
}
ul.timeline > li > p + p{
margin-bottom: 0px;
margin-top: 0em;
padding-top: 0px;
padding-bottom: 1em;
}
http://jsfiddle.net/6tcgr9eq/
Remove the : before last-child and the :after and used
ul.timeline > li:not(:last-child):after {
border-bottom: none !important;
}
Related
This is a django + html, css and very minimal or no JS question of a Tree display using nested UL/LI
(so far) have found out already the work of displaying tree vertical/horizontal is done,
(current issue) aim is to display a dynamic tree or static tree using nested UL in multiple format or options for the end-users with different options (they may choose for easier visualization) like vertical tree, horizontal tree and goal on the left side or right side.
so far those are achieved
currently the issue in working on the following to display vertically aligned horizontal tree with flex, and unable to succeed with the display as the wrap of the one tree path is making some impact on the next connectors (still trying to figure out which css selector and associated property will help to clear the gap)
Please find the attached screen shot and also the code
enter image description here
Latest Results Screenshot
enter image description here
CSS code:
<style>
body {
padding-top: 10px;
}
.tree {
list-style: none;
}
.tree,
.tree * {
margin: 0;
}
.tree li {
display: flex;
flex-direction: row;
align-items: flex-start;
position: relative;
padding-left: 2vw;
}
.tree li::before {
content: '';
position: absolute;
align-items: center;
left: 0;
top: 10%;
border-top: 4px solid rgb(42, 165, 97);
width: 2vw;
}
/* ========================================================= */
.tree li::after {
content: '';
position: absolute;
align-items: flex-start;
left: 0;
top:10%;
margin-bottom: 2px;
}
.tree li:not(:only-child):after {
content: '';
position: absolute;
left: 0;
bottom: 10%;
margin-top: 0px;
margin-bottom: 2px;
border-left: 3px solid rgb(172, 206, 20);
}
/* ========================================================= */
.tree li:last-of-type::after {
height: 50%;
top: 0;
}
.tree li:first-of-type::after {
height: 50%;
bottom: 0;
}
.tree li:not(:first-of-type):not(:last-of-type)::after {
height: 100%;
}
.tree ul,
.tree ol {
padding-left: 2vw;
position: relative;
}
.tree ul:not(:empty)::before,
.tree ol:not(:empty)::before {
content: '';
position: absolute;
left: 0;
top: 8%;
border-top: 4px solid red;
width: 2vw;
}
.tree span {
border: 1px solid;
text-align: center;
padding: 0.33em 0.66em;
background-color: yellow;
color: blue;
}
.tree>li {
padding-left: 0;
}
.tree>li::before,
.tree>li::after {
display: none;
}
ol,
ul {
counter-reset: section;
}
li span::before {
counter-increment: section;
/* content: counters(section, ".") " "; */
font-family: monospace;
}
body {
/* display: flex; */
justify-content: center;
align-items: center;
height: 100%;
}
finally working to a basic draft version:
enter image description here
still has to test with different dynamic options and also create a smooth alignment between the lines.
Currently this is the working copy,
still some more - pending fixes - please find the code and screenshot
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
padding-top: 10px;
}
.tree {
list-style: none;
}
.tree,
.tree * {
margin: 0;
}
.tree li {
display: flex;
flex-direction: row;
align-items: flex-start;
position: relative;
padding-left: 2vw;
padding-bottom: 2vh;
}
.tree li::after {
content: '';
position: absolute;
left: 0;
top: 5%;
margin-top: 2px;
}
.tree li::before {
content: '';
position: absolute;
align-items: center;
left: 2px;
top: 1%;
margin-left: -2px;
margin-right: -20px;
border-top: 5px solid red;
width: 2vw;
}
.tree li:not(:last-of-type)::before {
content: '';
position: absolute;
align-items: center;
left: -2px;
margin-left: -3px;
top: 2%;
border-top: 2px solid BLUE;
width: 2vw;
}
/* ========================================================= */
.tree li:not(:only-child):not(:last-of-type)::before {
content: '';
position: absolute;
left: 0;
bottom: 0%;
margin-top: 1px;
margin-bottom: -4px;
border-left: 2px solid blue;
}
.tree li:not(:only-child):not(:first-of-type):not(:last-of-type)::before {
content: '';
position: absolute;
left: 0;
bottom: 0%;
margin-top: 1px;
margin-bottom: -4px;
border-left: 2px solid red;
}
.tree li:only-child::before {
content: '';
position: absolute;
left: 0;
bottom: 0%;
margin-top: 1px;
margin-bottom: -6px;
border-left: 0px solid grey;
}
.tree li:only-child::after {
content: '';
position: absolute;
left: 0;
bottom: 2%;
top: 14%;
margin-top: 10px;
margin-bottom: 2px;
border-left: 0px solid grey;
}
.tree li:only-last-child::after {
content: '';
position: absolute;
left: 0;
bottom: -5%;
top: -20%;
margin-top: 10px;
margin-bottom: -24px;
border-left: 10px solid yellow;
}
.tree li:only-last-child::before {
content: '';
position: absolute;
left: 0;
bottom: 0%;
top: 5%;
margin-top: -9px;
margin-bottom: 20px;
border-left: 2px solid white;
}
/* ========================================================= */
.tree li:last-of-type::after {
height: 50%;
top: 0;
}
.tree li:first-of-type::after {
height: 50%;
bottom: 0;
}
.tree li:not(:first-of-type):not(:last-of-type)::after {
height: 100%;
}
.tree ul,
.tree ol {
padding-left: 2vw;
position: relative;
}
.tree ul:not(:empty)::before,
.tree ol:not(:empty)::before {
content: '';
position: absolute;
left: 0;
top: 2%;
margin-bottom: -2px;
border-top: 2px solid blue;
width: 2vw;
}
.tree span {
border: 1px solid;
text-align: center;
padding: 0.33em 0.66em;
background-color: yellow;
color: blue;
}
.tree>li {
padding-left: 0;
}
.tree>li::before,
.tree>li::after {
display: none;
}
ol,
ul {
counter-reset: section;
}
li span::before {
counter-increment: section;
/* content: counters(section, ".") " "; */
font-family: monospace;
}
body {
/* display: flex; */
justify-content: center;
align-items: center;
height: 100%;
}
</style>
</head>
<body>
<ul class="tree">
<li><span>Main</span>
</li>
</ul>
<ul class="tree">
<li>
<span>BACKLOG</span>
<ul>
<li><span>Level1</span>
<ul>
<li><span>Level1.1</span>
<ul>
<li><span>Level1.2.1</span>
<ul>
<li><span>Level1.2.1.1</span></li>
<li><span>Level1.2.1.2</span></li>
</ul>
</li>
<li><span>Level1.2.2</span></li>
</ul>
</li>
<li><span>Level1.2</span>
<ul>
<li><span>Level1.2.1</span>
<ul>
<li><span>Level1.2.1.1</span></li>
<li><span>Level1.2.1.2</span>
<ul>
<li><span>Level1.2.1.2.1</span></li>
<li><span>Level1.2.1.2.2</span></li>
<li><span>Level1.2.1.2.3</span></li>
</ul>
</li>
<li><span>Level1.2.1.3</span></li>
</ul>
</li>
<li><span>Level1.2.2</span>
<ul>
<li><span>Level1.2.2.1</span></li>
<li><span>Level1.2.2.2</span></li>
<li><span>Level1.2.2.3</span></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</body>
</html>
Screenshot
I've got this timeline code, I am trying to remove the line on top of first child and from last child, how can I get this border, do I need to add another absolute element to cover it up or?
Image what I want removed
Same goes for the line after End button.
body {
margin: 0;
}
.tree {
position: relative;
}
.tree {
position: relative;
list-style: none;
}
li {
border-left: 1px solid #abaaed;
padding-bottom: 50px;
position: relative;
padding-left: 20px;
margin-left: 10px;
height: auto;
display: flex;
align-items: center;
}
li:last-child {
padding-bottom: 0;
}
li::before {
content: '';
width: 15px;
height: 15px;
background: white;
border: 1px solid #4e5ed3;
border-radius: 50%;
position: absolute;
left: -8px;
}
li::after {
content: '';
width: 10px;
height: 2px;
position: absolute;
left: 7px;
top: auto;
background: #4e5ed3;
}
button {
padding: 10px 20px;
}
<div>
<ul class="tree">
<li><Button>Start</Button></li>
<li>
Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups.
</li>
<li><Button>
End</Button></li>
</ul>
</div>
You can try using background instead of border.
:root {
--circle-size: 15px;
}
body {
margin: 0;
}
.tree {
position: relative;
}
.tree {
position: relative;
list-style: none;
}
li {
padding-bottom: 50px;
position: relative;
padding-left: 20px;
margin-left: 10px;
height: auto;
display: flex;
align-items: center;
--line-padding: 0px;
--y-position: 0;
background: linear-gradient(#abaaed, #abaaed) 0 var(--y-position) / 1px calc(100% - var(--line-padding)) no-repeat;
}
li:first-child,
li:last-child {
--line-padding: 15px;
}
li:first-child {
--y-position: 100%;
}
li:last-child {
padding-bottom: 0;
}
li::before {
content: '';
width: 15px;
height: 15px;
background: white;
border: 1px solid #4e5ed3;
border-radius: 50%;
position: absolute;
left: -8px;
}
li::after {
content: '';
width: 10px;
height: 2px;
position: absolute;
left: 7px;
top: auto;
background: #4e5ed3;
}
button {
padding: 10px 20px;
}
<div>
<ul class="tree">
<li>
<Button>Start</Button>
</li>
<li>
Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups.
</li>
<li>
<Button>
End</Button>
</li>
</ul>
</div>
I've worked around a tooltip that appears in the same line where the link is located and it seems working well, best sying halfway. This tooltip is being used in a list, so it's in the same li where the link appears. The problem occurs in the next li, where the line-height seems to have been lost.
If someone could help me with this, here is the page I'm working in:
https:www.fredericopeter.com.br/playground
The damage is easily visible at the sidebar on the right side of the page.
The html code:
<ul style="margin: 2px 0 10px 20px;">
<li>Portfolio</li>
<li>Blog</li>
<li>Música</li>
<li>Video</li>
<li class="actual sidebar-tooltip">Playground<span class="txt">◄ Você está aqui</span></li>
<li style="clear: right;">Startpage [ ? ]</li>
</ul>
The css code (tooltip):
a.sidebar-tooltip:hover {
text-decoration: none;
}
a.sidebar-tooltip span {
z-index: 10;
display: none;
padding: 0;
margin-top: 0;
margin-left: 0px;
width: 100%;
text-align: right;
color: #3cbfc7;
background: transparent;
}
a.sidebar-tooltip:hover span {
display: inline;
position: absolute;
border: 0;
background: transparent;
}
.sidebar-tooltip {
width: 109px;
height: 10px;
display: inline-block;
position: relative;
border: 0;
background: transparent;
}
.sidebar-tooltip:hover .txt {
display: inline-block;
}
.sidebar-tooltip .txt {
margin-left: 3px;
color: #0a0;
width: 100%;
padding: 0;
display: none;
position: absolute;
z-index: 1000;
background: transparent;
}
.sidebar-tooltip .txt:before {
width: 0;
padding: 0;
position: absolute;
content: '';
}
You can check .sidebar-tooltip class and remove the height. I saw height is set 10px.
<div class="message-unread-headline" id="message-unread-headline" style="display: none;">
<span>Unread Messages</span>
</div>
.message-unread-headline {
color: #e91e63;
display: none;
margin: 0 10px -10px;
position: relative;
text-align: center;
&:before {
background: #e91e63;
content: '';
height: 2px;
left: 0;
padding: 0 10px;
position: absolute;
top: 0;
width: 100%;
}
span {
background: transparent;
display: inline-block;
height: 30px;
padding: 0 10px;
position: relative;
top: -11px;
}
}
this is how it looks
I would like that pink line stops as soon as reaches the Unread Message Text
I tried with z-index, but it doesn't work. Don't know the way how to prevent that overlaying
That's how I achieved this:
.message-unread-headline {
margin:0;padding:0 10px;
background:#fff;
display:inline-block;
color: #e91e63;
}
h2{
text-align:right;
position:relative;
z-index:2;
}
h2:after{
content:"";
position:absolute;
top:50%;
left:0;
right:0;
border-top:solid 2px #e91e63;
z-index:-1;
}
<h2>
<span class="message-unread-headline">Unread Messages</span>
</h2>
Check if this could help you.
I have removed width: 100% and added right: 0 to :before
And give background: #fff; to span
.message-unread-headline {
color: #e91e63;
position: relative;
text-align: right;
}
.message-unread-headline:before {
background: #e91e63;
content: '';
height: 2px;
left: 0;
padding: 0 10px;
position: absolute;
top: 0;
right: 0;
}
.message-unread-headline span {
background: #fff;
padding: 0 10px;
position: relative;
top: -11px;
}
<div class="message-unread-headline" id="message-unread-headline" >
<span>Unread Messages</span>
</div>
If your purpose is just strike over a text you can go for strike tag in html
I have a ul inside a div. I want to center it. Here is the fiddle
HTML
<div id="menu-top">
<div id="menu-container">
<div id="menu-mask">
<ul id="menu">
<li>Home</li>
<li>Home</li>
<li>Home</li>
<li>Home</li>
<li>Home</li>
</ul>
</div>
</div>
</div>
CSS
body {
background-color: #000;
overflow: hidden;
}
#menu-top {
position: absolute;
display: block;
width: 100%;
height: 26px;
top: 0px;
z-index: 9;
}
#menu-container {
width: 840px;
margin: auto;
}
#menu-mask {
display: inline-block;
height: 26px;
margin: auto;
overflow: hidden;
position: relative;
top: 0;
width: 800px;
}
#menu {
position: absolute;
display: block;
left: 0px;
top: 0px;
height: 26px;
margin: auto;
padding: 0px;
width: 100%;
}
#menu li {
padding-right: 20px;
clear: none;
float: left;
display: inline;
}
#menu li a {
font-size: 12px;
line-height: 26px;
letter-spacing: 1.5px;
color: #fff;
text-decoration: none;
text-transform: uppercase;
}
Here you go... change your #menu to this:
#menu {
position: absolute;
display: block;
margin-left:25%;
margin-right:25%;
margin-top:auto;
margin-bottom:auto;
top: 0px;
height: 26px;
padding: 0px;
width: 100%;
}
The margin-left and margin-right settings will center your menu on the page. I gave this a quick test in your JSFiddle to make sure it works.
Oh, and here's the updated JSFiddle showing the changes...
http://jsfiddle.net/LyJz9/7/
You can probably use text-align:center for what you are trying to do.