How to spread elements with flex to take up the same width in a parent container - css

My codepen
What I want to achieve:
I want that the elements within the process-indicator parent take up the same width except the elements with class=step AND that the divs with steps name are directly under the step element.
The process-indicator stretch 100% and the connector classes should not use fixed pixel widths so I can add 5,6 or 10 steps and it scales graphically well.
What does not work:
1.) The first after-connector and last before-connector elements in yellow do not share the same size as the elements in green/black
2.) The step names in the divs should be positioned under the according step bubble and not inline with the steps and connectors.
Be aware that I do NOT want to use the before/after pseudo selectors for the step element! =>
I need to be able to later apply dynamically a complete/incomplete class with react thus I need full control about every connector.
HTML
<ul class="process-indicator">
<li class="completed">
<span class="step"></span>
<span class="after-connector"></span>
<div>step 1</div>
</li>
<li class="incompleted">
<span class="before-connector"></span>
<span class="step"></span>
<span class="after-connector"></span>
<div>step 2</div>
</li>
<li class="incompleted">
<span class="before-connector"></span>
<span class="step"></span>
<span class="after-connector"></span>
<div>step 3</div>
</li>
<li class="incompleted">
<span class="before-connector"></span>
<span class="step"></span>
<div>step 4</div>
</li>
</ul>
SCSS
$incomplete: gray;
$complete: blue;
$step-size: 40px;
$step-line-thickness: 2px;
$border-thickness: 1px;
$darken-amount: 30%;
#mixin step-style($color) {
background-color: $color;
color: $color;
border-color: darken($color, $darken-amount);
&:before,
&:after {
background-color: $color;
border-color: darken($color, $darken-amount);
}
}
.flex {
-ms-flex: 1;
-webkit-flex: 1;
-moz-flex: 1;
flex: 1;
}
.displayFlex {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.process-indicator {
background: orange;
#extend .displayFlex;
margin: 0;
padding: 0;
margin-bottom: 1em;
> li {
#extend .displayFlex;
#extend .flex;
list-style: none;
font-size: 1.2em;
position: relative;
text-overflow: ellipsis;
color: $incomplete;
}
> li .before-connector,
li .after-connector {
#extend .flex;
position: relative;
text-overflow: ellipsis;
color: $incomplete;
}
> li .step {
width: $step-size;
height: $step-size;
background-color: $incomplete;
border-radius: 40px;
}
// line connectors
> li .after-connector {
height: 3px;
top: $step-size / 2;
background-color: green;
}
> li .before-connector {
height: 3px;
top: $step-size / 2;
background-color: red;
}
> li:first-child span.after-connector,
> li:last-child span.before-connector {
background: yellow;
}
// completed state
> li.completed {
color: $complete;
.step {
#include step-style($complete);
}
}
> li.incompleted {
color: $incomplete;
.step {
#include step-style($incomplete);
}
}
}
UPDATE

I would go with a flex solution on the container and move the seperators outside so they can grow equally:
.container {
display: flex;
width: 100%;
background: orange;
}
.step {
height: 40px;
width: 40px;
border-radius: 50%;
overflow: visible;
position: relative;
background: grey;
}
.text {
font-weight:bold;
font-size:20px;
position: absolute;
top: 100%;
margin-top: 10px;
left: 0;
white-space: nowrap;
}
.step:last-child .text {
right:0;
left:auto;
}
.seperator {
flex-grow: 1;
position: relative;
}
.seperator:before {
content: '';
display: block;
height: 10px;
position: absolute;
left: 0;
right: 0;
top: 50%;
transform: translateY(-50%);
}
.yellow:before {
background: yellow;
}
.green:before {
background: green;
}
.red:before {
background: red;
}
<div class="container">
<div class="step">
<span class="text">Step 1</span>
</div>
<div class="seperator yellow"></div>
<div class="seperator red"></div>
<div class="step">
<span class="text">Step 2</span>
</div>
<div class="seperator green"></div>
<div class="seperator red"></div>
<div class="step">
<span class="text">Step 3</span>
</div>
<div class="seperator green"></div>
<div class="seperator yellow"></div>
<div class="step">
<span class="text">Step 4</span>
</div>
</div>
Please note you will need to add margin bottom to the container to prevent any content below being overlapped by the text

Related

How do I to create a bread crumbs navigation like this?

I'm trying to wrap my head around making a breadcrumbs navigation that will look sort of like this.
I want the circle to be centered beneath the text. I want the text to stay within the container where I place the breadscrumbs. E.g. I can't use position absolute to place them relatively to the circle, since they would potentially overflow the container I put them in.
This is where I'm currently at... https://jsfiddle.net/04pts9ey/2/
body {
background: gray;
}
.container {
max-width: 80%;
margin: auto;
background: #f6f6f6;
padding: 40px;
}
.page {
width: 100%;
height: 400px;
border: 1px solid black;
margin-top: 24px;
}
.wrapper {
display: flex;
justify-content: space-between;
}
.step {
display: flex;
flex-direction: column;
align-items: center;
}
.text {
margin-bottom: 8px;
}
.circle {
background: purple;
width: 18px;
height: 18px;
border-radius: 50%;
position: relative;
}
.step:not(:last-child) .circle:before {
content: "";
position: absolute;
left: 50%;
top: 50%;
height: 1px;
width: 100px;
right: 100px;
background: green;
}
<div class="container">
<div class="wrapper">
<span class="step">
<span class="text">Short</span>
<span class="circle"></span>
</span>
<span class="step">
<span class="text">Long title here</span>
<span class="circle"></span>
</span>
<span class="step">
<span class="text">Medium title</span>
<span class="circle"></span>
</span>
<span class="step">
<span class="text">Another title</span>
<span class="circle"></span>
</span>
</div>
<div class="page"></div>
</div>
My main issue seems to be that I can't align the circle and text together, since putting them in a div together, makes it hard for me to draw the lines between the circles.
Something like this ?
.wrapper {
display: flex;
border: 1px solid;
}
.step {
flex: 1 1 0;
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
.text {
margin-bottom: 8px;
}
.circle {
background: orange;
width: 20px;
height: 20px;
border-radius: 50%;
margin-top: auto;
}
.step:not(:last-child)>.circle:before {
content: "";
position: absolute;
height: 2px;
left: 0;
right: 0;
bottom: 10px;
transform: translate(50%, 50%);
background: orange;
}
/* Styles below are not needed, Used for illustration */
.wrapper {
resize: horizontal;
overflow: auto;
}
<h3>Bottom right corner to resize for responsiveness</h3>
<div class="wrapper">
<span class="step">
<span class="text">Short</span>
<span class="circle"></span>
</span>
<span class="step">
<span class="text">Long title here</span>
<span class="circle"></span>
</span>
<span class="step">
<span class="text">Medium title</span>
<span class="circle"></span>
</span>
<span class="step">
<span class="text">Another title</span>
<span class="circle"></span>
</span>
</div>
The code is self explanatory nevertheless if you have any question please leave a comment, The only significant changes i made are:
moved the lines from being relative to .circle to .step to have more control over the width.
margin-top:auto on the .circle to ensure it's always on be bottom in case text overflows.
Made .step equal width using flex: 1 1 0; So the lines between the circle have a unified offset.

Issue with z-index of css dropdown menu

I have broken my head on the following css.
JSFiddle:
<div id='new_task_wrap'>
<div class='box'>
<div class='first_row'>
<div class='description' contenteditable='true'>
</div>
<div class='calendar dropdown'>
<i class="fa fa-calendar" aria-hidden="true"></i>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
</div>
My dropdown menu is hidden behind the divs of contenteditable elment. Any ideas how to fix it?
Important: The div heights should not be changed to show the dropdown menu.
Remove overflow: auto on .first-row
$(document).on('click', '.dropdown', function() {
$(this).find('.dropdown-content').toggle();
});
#new_task_wrap {
position: relative;
display: flex;
}
#new_task_wrap > .box {
width: 100%;
border-style: solid;
border-color: #98afc8;
}
#new_task_wrap > .box > .first_row {
display: flex;
width: 100%;
/*overflow-y: auto;*/
}
#new_task_wrap > .box > .first_row > .description {
background-color: white;
display: inline-block;
font-weight: 400;
padding: 9px 9px 9px 9px;
cursor: text;
outline: 0;
flex-grow: 1;
overflow-y: auto;
}
#new_task_wrap > .box > .first_row > .calendar {
padding-top: 8px;
cursor: pointer;
}
.right-add-on {
position: relative;
}
.right-add-on >:not([contenteditable=true]) {
position: absolute;
right: 0;
color: #67829e;
cursor: pointer;
}
.dropdown {
position: relative;
vertical-align: middle;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
right: 0;
min-width: 160px;
background-color: yellow;
padding: 12px 16px;
z-index: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='new_task_wrap'>
<div class='box'>
<div class='first_row'>
<div class='description' contenteditable='true'>
</div>
<div class='calendar dropdown'>
<i class="fa fa-calendar" aria-hidden="true"></i>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
</div>
Updated jsFiddle
Just change overflow-y to visible
Refer this
The overflow-y property specifies what to do with the top/bottom edge of the content - if it overflows the element's content area.
#new_task_wrap > .box > .first_row {
display: flex;
overflow-y: visible; //Here is the change
width: 100%;
}
use position: absolute for .dropdown and position it accordingly
here is the updated Fiddle http://jsfiddle.net/z0kfdahu/2/

Is it possible to apply same style to element 1 and element 2, without calling out the style in element 1?

Is it possible to apply same style to element 1 and element 2, without calling out the style in element 1?
Element 1 is .notch
Element 2 is #fullbg
Element 1 must always come before Element 2. I would like to apply Element 2's bg-color to Element 1 and Element 2.
How do I make the first <div class="notch">have a yellow bg (#fullbg), without applying any specific style (class/id) to <div class="notch">?
I'm thinking this could be done with :nth-of-type() selector...? Eventually, I will have several "notches", with <div id="fullbg3">, <div id="fullbg4">, etc.
Check codepen example - I want first notch to be yellow (like fullbg), and second notch to be red (like fullbg2), without giving any notch their own special class.
Currently, the first notch is red. It should be yellow.
http://codepen.io/Goatsy/pen/GqJGxb
HTML
<p>stuff</p>
<div class="notch">this should be YELLOW</div>
<p>stuff</p>
<div id="fullbg">this should be YELLOW</div>
<p>stuff</p>
<div class="notch">this should be RED</div>
<p>stuff</p>
<div id="fullbg2">this should be RED</div>
CSS
.notch,
#fullbg {
background: yellow;
}
.notch,
#fullbg2 {
background: red;
}
Here is, more specifically what I'm trying to achieve: the bgcolor and small block color should match. codepen.io/Goatsy/pen/rLVrJo
The ~ (selects successors) partly solves the problem, though it can be not very flexible sometimes (i.e. you have to right that for every new "notch").
.notch,#fullbg{
background:yellow;
}
#fullbg~.notch,#fullbg2{
background:red;
}
#fullbg2~.notch,#fullbg3{
background:green;
}
<p>stuff</p>
<div class="notch">this should be YELLOW</div>
<p>stuff</p>
<div id="fullbg">this should be YELLOW</div>
<p>stuff</p>
<div class="notch">this should be RED</div>
<p>stuff</p>
<div id="fullbg2">this should be RED</div>
<p>stuff</p>
<div class="notch">this should be GREEN</div>
<p>stuff</p>
<div id="fullbg3">this should be GREEN</div>
Updated based on comment/codepen sample
Here is a start
/* notch nav styles */
.notch-nav {
overflow: hidden;
background: #fff;
margin: 0;
list-style: none
}
.notch-nav li {
float: right;
margin-top: 33px;
/* adjust this line to push entire notch nav down and away from minilinks */
margin-right: -15px;
}
.notch-nav a {
display: block;
/* padding:50px 0 20px 30px; */
margin-left: 30px;
color: #cca134;
text-decoration: none;
font-size: 18px;
padding-bottom: 25px;
}
.notch-nav a:hover {
text-decoration: none;
color: #295pms;
}
.notch-nav .current .dropdown:hover .dropbtn:before,
.notch-nav .current .dropdown:hover .dropbtn:after {
display: none
}
.notch-nav .current .dropdown-content a:before,
.notch-nav .current .dropdown-content a:after {
display: none
}
.notch-nav .current a {
position: relative;
text-decoration: none;
z-index: 5;
}
.notch-nav .current a:before,
.notch-nav .current a:after {
content: "";
display: block;
width: 26px;
height: 26px;
position: absolute;
bottom: 0;
left: 50%;
margin-left: -15px;
}
/* make fullwidth-header 100% */
.fullwidth-header {
display: none;
width: 100%;
height: 230px;
}
.fullwidth-header-block {
display: block;
background: #white;
padding: 30px;
margin-top: 53px;
font-size: 30px;
font-weight: 700;
text-align: center;
text-transform: uppercase;
letter-spacing: 2px;
}
.fullwidth-header-block p {
margin-top: 0;
font-size: 16px;
font-weight: 400;
text-align: center;
text-transform: none;
letter-spacing: 0;
}
/* current classes */
.curr1 li:nth-child(1),
.curr1 ~ div:nth-of-type(1) {
background:blue;
display: block;
}
.curr2 li:nth-child(2),
.curr2 ~ div:nth-of-type(2) {
background:black;
display: block;
}
.curr3 li:nth-child(3),
.curr3 ~ div:nth-of-type(3) {
background:pink;
display: block;
}
.curr4 li:nth-child(4),
.curr4 ~ div:nth-of-type(4) {
background:green;
display: block;
}
<ul class="nav notch-nav curr4">
<li>
<div class="dropdown">
<a class="dropbtn" href="/utilities/about-rpu">About</a>
</div>
</li>
<li>
<div class="dropdown">
<a class="dropbtn" href="/utilities/?q=contractors">Contractors</a>
</div>
</li>
<li>
<div class="dropdown">
<a class="dropbtn" href="/utilities/?q=businesses">Businesses</a>
</div>
</li>
<li>
<div class="dropdown">
<a class="dropbtn" href="/utilities/?q=residents">Residents</a>
</div>
</li>
</ul>
<div class="fullwidth-header">
About
</div>
<div class="fullwidth-header">
Contractors
</div>
<div class="fullwidth-header">
Businesses
</div>
<div class="fullwidth-header">
Residents
</div>

why only the first span is visible and others are hidden

I am new to CSS so please excuse if this s basic question ,
I am trying to develop a similar User Interface as show in this picture below
This is my code
<div class="container">
<div class="marquee-sibling">Indices </div>
<div class="marquee">
<ul class="marquee-content-items">
<li><span>NASDAQ</span><br>
<span>4655.92</span>
<span>17.93</span>
<span>0.39%</span>
</li>
<li><span>DJIA</span><br>
<span>16414.39</span>
<span>15.82</span>
<span>0.1%</span>
</li>
</ul>
</div>
</div>
But could you please tell me why only the first span is visible and others are hidden ??
http://jsfiddle.net/Wf43X/319/
I have tried something like this..
body {
margin: 0px;
padding: 0px;
background-color: #fff;
}
.marquee {
margin: 10px;
padding: 10px;
}
span {
display: inline-block;
margin:0px;
padding:0px;
}
.container{
display: flex;
justify-content: center;
list-style-type: none;
}
.ind-cont {
background-color: #000;
width: 200px;
height: 100px;
margin: 0px;
padding:0px;
}
.txtcolor {
color: #fff;
}
.txtcolorb {
color: #aaa;
}
.ind-name {
margin: 20px;
}
.capital {
float: right;
margin: 20px;
}
.floatright {
float: right;
margin: 10px;
margin-right: 20px;
}
.one-share {
margin: 10px;
margin-left: 20px;
}
<div class="container">
<div class="marquee-sibling"> </div>
<div class="marquee">
<span class="ind-cont">
<span class="ind-name txtcolor ">NASDAQ</span>
<span Class="capital txtcolor">4655.92</span>
<span class="one-share txtcolorb">17.93</span>
<span class="per txtcolorb floatright">0.39%</span>
</span>
<span class="ind-cont">
<span class="ind-name txtcolor ">DJIA</span>
<span Class="capital txtcolor">16414.39</span>
<span class="one-share txtcolorb">15.82</span>
<span class="per txtcolorb floatright">0.1%</span>
</span>
</div>
</div>
You can do this with Flexbox
ul {
display: flex;
justify-content: center;
list-style-type: none;
}
li {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-between;
background: black;
color: white;
border: 1px solid white;
paddgin: 10px;
}
li span {
flex: 50%;
padding: 5px;
box-sizing: border-box;
}
li > span:nth-child(4n+2),
li > span:nth-child(4n+4) {
text-align: right;
}
li > span:nth-child(4n+1),
li > span:nth-child(4n+2) {
font-size: 16px;
font-weight: bold;
}
li > span:nth-child(4n+3),
li > span:nth-child(4n+4) {
font-size: 14px;
color: #aaa;
}
<div class="container">
<div class="marquee-sibling">Indices </div>
<div class="marquee">
<ul class="marquee-content-items">
<li>
<span>NASDAQ</span>
<span>4655.92</span>
<span>17.93</span>
<span>0.39%</span>
</li>
<li>
<span>DJIA</span>
<span>16414.39</span>
<span>15.82</span>
<span>0.1%</span>
</li>
</ul>
</div>
</div>
You are breaking a line after the first span, and this code is hiding whatever is after the first line:
.container {
overflow: hidden;
height: 45px;
}
I also think that the flexbox ideas is the best but if you still want to stay with your code, I think you should try changing the size height of your .container in your css. you will be able to see the rest of your 'li' element. The text is in white color and you can't really see it when you run your code cause the background is white.

scrollable ul element without scrollbar

I'm trying to use angular to create list of elements. The page will be an app on mobile phone.
The list itself can have many elements so what I expect is that the ul element should be scrollable ("swipable"?). I tried to follow some example like http://jsfiddle.net/sirrocco/9z48t/ and http://jsfiddle.net/qcv5Q/1/..
This is the html code:
<div class="container">
<div id="spinner-icon" style="display:none">
<span class = "icon-spinner"></span>
</div>
<div class="col-xs-12 indentation push-down bg-white" ng-repeat="cei in completeElementInfo">
<div class="clearfix">
<div class="pull-left">
<h4>{{cei.description}}</h4>
<p>{{cei.name}}</p>
</div>
</div>
<div class="log-widget-list">
<ul class="list scroller clearfix" id="elements-list">
<li class="pull-left" ng-repeat="tinfo in cei.techInfo | orderBy: 'tinfo.sentTime'">
<h4 class="align-center">{{tinfo.elementShortCode}}</h4>
<div class="clearfix">
<span class="icon-clock pull-left"></span>
<span class="pull-right"> {{tinfo.sentTime}}min</span>
</div>
</li>
</ul>
</div>
</div>
</div>
and this is the css code:
.list {
margin: 0;
padding: 0;
}
.log-widget-list {
height:100px;
width: 720px;
overflow: hidden;
}
.log-widget-list .scroller{
overflow-x: scroll;
list-style-type: none;
width: 1500px; /* combined width of all LI's */
}
#elements-list li {
width: 100px;
list-style: none;
box-sizing: border-box;
border-top: none!important;
background-color: #0accf8;
padding: 4px;
}
#elements-list li:not(:last-of-type) {
border-right: 3px solid #ffffff;
}
#elements-list [class^="icon-"], #elements-list [class*=" icon-"] {
margin-top: 4px;
font-size: 12px;
}
Now the problem is that i don't want that the horizontal scrollbar appears, but it appears and i don't understand why... Any idea?
add overflow:hidden in #wrapper css.
CSS:
#wrapper {
background: transparent;
width: 550px;
color: white;
height:100%;
overflow:hidden;
}
Demo: http://jsfiddle.net/lotusgodkk/9z48t/5/
DEMO
http://jsfiddle.net/FTUrF/6/
Changed some CSS here:
.log-widget-list {
width: 200px;
height: 300px;
border: 1px solid #000;
overflow: hidden;
}
.log-widget-list .scroller {
width: 215px;
height: 300px;
overflow: scroll;
padding-bottom: 15px;
list-style-type: none;
}
Added height and padding-bottom in .scroller and border in .log-widget-list
and added some more of these:
<span class="pull-right"> {{tinfo.sentTime}}min</span>

Resources