I have a series of subtabs that I want to make look like , except with more space between the items.
I am using psuedo elements and have successfully created a triangle on the right side of the element, but now I want to create an inset triangle on the left side. I have tried to use :before and with right:100% but it doesn't accomplish anything.
I was thinking I could do something like this, but no matter how I try and place it I can't seem to "cut" out a triangle from the left side....
.tabs > ul > li:before {
position: absolute;
content: " ";
height: 0;
width: 0;
top: 0;
right: 100%;
border: 1.65em solid #fff;
}
When using the above it just cuts out a little chunk from the triangle on the right.
Full jsfiddle of the working bits. (make sure you expand the preview to large width to actually see it in action)
.tabs {
padding-top: 0.5em;
padding-bottom: 1em;
padding-right: 40px;
}
.tabs > ul {
display: flex;
justify-content: space-between;
}
.tabs > ul > li {
position: relative;
display: inline-block;
background: #eeeeee;
padding: 1em;
line-height: 1.25em;
color: #ffffff;
}
.tabs > ul > li > a {
color: #ffffff;
font-family: Lato-Regular;
font-size: 1.2em;
}
.tabs > ul > li:after {
position: absolute;
content: " ";
height: 0;
width: 0;
top: 0;
left: 100%;
border: 1.65em solid transparent;
}
Update
Per Aaron's suggestion below I tried playing with z-index to get the before element to work. It looks like it's a step in the right direction but not wholly working yet. jsfiddle
1) It's not all the way to the left
2) It's a rectangle instead of a triangle
I did use the #Aaron answer and changed
.tabs > ul {
display: flex;
justify-content: space-between;
}
for
.tabs > ul {
display: flex;
justify-content: flex-start;
white-space: nowrap;
}
it'll look better when the width changes
here's the fiddle
Change the z-index of the :after pseudo to show the angle, then use the before pseudo to create the white section below the main angle.
You may have to fiddle with the height and width of the :before to make it wok exactly as you need.
.tabs {
padding-top: 0.5em;
padding-bottom: 1em;
padding-right: 40px;
}
.tabs > ul {
display: flex;
justify-content: space-between;
}
.tabs > ul > li {
position: relative;
display: inline-block;
background: #eeeeee;
padding: 1em 1em 1em 2em;
line-height: 1.25em;
color: #ffffff;
}
.tabs > ul > li > a {
color: #ffffff;
font-family: Lato-Regular;
font-size: 1.2em;
}
.tabs > ul > li:after {
position: absolute;
content: " ";
height: 0;
width: 0;
top: 0;
left: 100%;
border: 1.65em solid transparent;
z-index: 2;
}
.tabs > ul > li:before {
position: absolute;
content: "";
height: 0;
width: 0;
top: -3px;
left: 0;
border-width: 1.85em 1.65em 1.85em 1.85em;
border-style: solid;
border-color: transparent transparent transparent #fff;
z-index: 1;
}
.tabs > ul > li:nth-child(1):after {
border-left-color: red; }
.tabs > ul > li:nth-child(1) {
background: red; }
.tabs > ul > li:nth-child(2):after {
border-left-color: orange; }
.tabs > ul > li:nth-child(2) {
background: orange; }
.tabs > ul > li:nth-child(3):after {
border-left-color: gray; }
.tabs > ul > li:nth-child(3) {
background: gray; }
.tabs > ul > li:nth-child(4):after {
border-left-color: deepskyblue; }
.tabs > ul > li:nth-child(4) {
background: deepskyblue; }
.tabs > ul > li:nth-child(5):after {
border-left-color: blue; }
.tabs > ul > li:nth-child(5) {
background: blue; }
.tabs > ul > li:nth-child(6):after {
border-left-color: purple; }
.tabs > ul > li:nth-child(6) {
background: purple; }
.tabs > ul > li:nth-child(7):after {
border-left-color: green; }
.tabs > ul > li:nth-child(7) {
background: green; }
<div class="tabs">
<ul>
<li>Qualification</li>
<li>Profile</li>
<li>Skills Assessment</li>
<li>Interview Prep</li>
<li>Debrief</li>
<li>Offer</li>
<li>Follow Up</li>
</ul>
</div>
Related
I have a multi-level dropdown but it opens to the right by default. I have tried to tweak it a lot but doesn't seem to work no matter what I try.
I'll provide the code here. The HTML might be a little messed up because I had to remove the rails code in there and only leave plain HTML.
The dropdowns open to the right and overflow the window. If anyone has a better way to do it, I am all ears.
.dropdown-wrapper {
ul {
list-style: none;
padding: 0;
margin: 0;
// background: #1bc2a2;
}
li>ul {
margin-right: 190px;
}
ul li {
font-size: 16px !important;
margin-top: 10px;
display: block;
position: relative;
color: goldenrod;
float: left;
min-width: 100px;
cursor: pointer;
// background: #1bc2a2;
}
ul li:not(:last-child) {
border-bottom: 1px solid goldenrod;
}
li ul {
display: none;
}
ul li a {
display: block;
padding: 10px;
text-decoration: none;
white-space: nowrap;
color: goldenrod;
border-radius: 0;
box-shadow: none;
}
ul li a:hover {
background: #FAF9F6;
border-radius: 0;
}
ul li:hover {
background: #FAF9F6;
}
li:hover>ul {
display: block;
position: absolute;
margin-left: 2px;
}
.main-navigation {
ul {
background: white;
}
}
li:hover li {
float: none;
}
// li:hover a { background: #1bc2a2; }
li:hover li a:hover {
background: #FAF9F6;
}
.main-navigation li ul li {
border-top: 0;
}
ul ul ul {
left: 100%;
top: 0;
}
ul:before,
ul:after {
content: " ";
/* 1 */
display: table;
/* 2 */
}
ul:after {
clear: both;
}
}
<ul class="main-navigation">
<li>Treatments Provided
<ul>
<li>1</li>
</li>
<li>2
<ul>
<li class="">
<a href=>a</a>
</li>
</ul>
</ul>
</li>
</ul>
How can I make this CSS progress tracker responsive?
I want the "steps" to stack on top of each other when viewed on a screen that is too small to fit them horizontally.
Code snippet included below, or jsfiddle here if you prefer:https://jsfiddle.net/yr6kwzcv/
/* Resets the ordered list styles and makes the list elements be displayed in a single line */
.track-progress {
margin: 0;
padding: 0;
overflow: hidden;
}
.track-progress li {
list-style-type: none;
display: inline-block;
position: relative;
margin: 0;
padding: 0;
text-align: center;
line-height: 30px;
height: 30px;
background-color: #f0f0f0;
}
/* Make it occupy all the available width */
.track-progress[data-steps="3"] li { width: 33%; }
.track-progress[data-steps="4"] li { width: 25%; }
.track-progress[data-steps="5"] li { width: 20%; }
/* Adds a "done" class to represent the progress */
.track-progress li > span {
display: block;
color: #999;
font-weight: bold;
text-transform: uppercase;
}
.track-progress li.done > span {
color: #666;
background-color: #ccc;
}
/* add the arrows */
.track-progress li > span:after,
.track-progress li > span:before {
content: "";
display: block;
width: 0px;
height: 0px;
position: absolute;
top: 0;
left: 0;
border: solid transparent;
border-left-color: #f0f0f0;
border-width: 15px;
}
.track-progress li > span:after {
top: -5px;
z-index: 1;
border-left-color: white;
border-width: 20px;
}
.track-progress li > span:before {
z-index: 2;
}
/* Make arrows match the color of the previous step and remove arrow from first element */
.track-progress li.done + li > span:before {
border-left-color: #ccc;
}
.track-progress li:first-child > span:after,
.track-progress li:first-child > span:before {
display: none;
}
/* Adds arrows appearance to the start and end */
.track-progress li:first-child i,
.track-progress li:last-child i {
display: block;
height: 0;
width: 0;
position: absolute;
top: 0;
left: 0;
border: solid transparent;
border-left-color: white;
border-width: 15px;
}
.track-progress li:last-child i {
left: auto;
right: -15px;
border-left-color: transparent;
border-top-color: white;
border-bottom-color: white;
}
<ol class="track-progress" data-steps="3">
<li class="done">
<span>Site Information</span>
<i></i>
</li><!--
--><li class="done">
<span>Data Source</span>
</li><!--
--><li>
<span>Final Details</span>
<i></i>
</li>
</ol>
Here is the source of the code snippet I recreated above: https://coderwall.com/p/-7trcg/simple-css-only-wizard-progress-tracker
http://jsfiddle.net/vxaAE/
I tried to integrate this menu in my project but it comes to me with two problems.
- sub menu going out of window when I have this scenario-
http://jsfiddle.net/vxaAE/
- I tried to give submenu's width to auto, because it would be according to sub menu's length.
How do I get this working?
CSS-
.mega-wrapper {
width: 100%;
margin: 0 auto;
}
.mega-nav {
position: relative;
width: auto;
height: 59px;
background: #252428;
}
.mega-nav ul .mega-ul {
display: block;
margin: 0;
padding: 0;
list-style: 0;
}
.mega-nav .mega-ul li {
position: relative;
display: inline-block;
}
.mega-nav .mega-ul li a {
display: block;
font-size: 1em;
color: #fff;
text-decoration: none;
padding: 0 15px;
}
.mega-nav .mega-ul li a:hover, .mega-nav .mega-ul li:hover > a {
background: #333;
}
.mega-nav .mega-ul li:hover > .mega-div {
display: block;
}
.mega-div {
position: absolute;
top: 100%;
left: 0;
width: 450px;
height: auto;
padding: 20px 30px;
background: #333;
display: none;
z-index:1000;
}
.mega-ul li ul {
float: left;
width: 23%;
margin: 0 2% 15px 0;
padding: 0;
list-style: none;
}
.mega-ul li ul li {
display: block;
}
.mega-ul li ul li a {
float: left;
display: block;
width: 100%;
height: auto;
line-height: 1.3em;
color: #888;
text-decoration: none;
padding: 1px 0;
}
.mega-ul li ul li:first-child a {
font-size: 1.2em;
color: #8dc63f;
}
.mega-ul li ul li a:hover {
color: #fff;
background: none;
}
.mega-ul ul li:first-child a:hover {
color: #fff;
}
/* clearfix */
.mega-nav .mega-ul:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.mega-nav .mega-ul {
display: inline-block;
}
.header-title {
line-height: 59px;
}
Any help would be greate appreciated.
Fiddle
You can do this:
.mega-nav .mega-ul li:nth-child(1n+6):hover .mega-div{
right:0;
left:auto;
}
This way, starting from the 6th .mega-nav .mega-ul li:nth-child(1n+6):hover .mega-div, it will align to right:0; going the other way.
This is thanks to nth-child(1n+6), which means starting from the 6th element, every one after has this property.
It's not the prettiest alternative, but you can mess around, making it left:-50%, or right:50%.
If you know how many you have and will always be that way and you know what one works where, you can just use :nth-child(n) and style that way. (n being the number in which that element appears).
Remove position relative from li tag
.mega-ul li {
display: inline-block;
position: relative; // remove it
}
http://jsfiddle.net/vxaAE/1/
i have this css code for my responsive css menu:
nav, ul, li, a {
margin: 0; padding: 0;
}
a {
text-decoration: none;
}
.container {
width: 100%;
margin: 10px auto;
}
.toggleMenu {
display: none;
background: #666;
padding: 10px 15px;
color: #fff;
}
.nav {
list-style: none;
*zoom: 1;
background:#f36f25;
}
.nav:before,.nav:after {
content: " ";
display: table;
}
.nav:after {
clear: both;
}
.nav ul {
list-style: none;
width: 9em;
}
.nav a {
padding: 10px 15px;
color:#fff;
}
.nav li {
position: relative;
}
.nav > li {
float: left;
border-top: 1px solid #104336;
}
.nav > li > .parent {
background-image: url("images/downArrow.png");
background-repeat: no-repeat;
background-position: right;
}
.nav > li > a {
display: block;
}
.nav li ul {
position: absolute;
left: -9999px;
}
.nav > li.hover > ul {
left: 0;
}
.nav li li.hover ul {
left: 100%;
top: 0;
}
.nav li li a {
display: block;
background: #1d7a62;
position: relative;
z-index:100;
border-top: 1px solid #175e4c;
}
.nav li li li a {
background:#249578;
z-index:200;
border-top: 1px solid #1d7a62;
}
#media screen and (max-width: 768px) {
.active {
display: block;
}
.nav > li {
float: none;
}
.nav > li > .parent {
background-position: 95% 50%;
}
.nav li li .parent {
background-image: url("images/downArrow.png");
background-repeat: no-repeat;
background-position: 95% 50%;
}
.nav ul {
display: block;
width: 100%;
}
.nav > li.hover > ul , .nav li li.hover ul {
position: static;
}
}
but i cannot get the menu items to align in the centre of the menu/page
here is a fiddle with the full code:
http://jsfiddle.net/5Z2QV/
Is THIS FIDDLE what you want?
If so, then you have to remove float from the lis and add display: inline-block to them. Then you have to add text-align: center to the .nav
.nav {
list-style: none;
background:#f36f25;
text-align: center;
border-top: 1px solid #104336;
}
.nav > li {
display: inline-block;
}
I also removed border-top from the li and put it in the .nav to remove the gaps between lis.
EDIT:
To keep sub-menu items aligned to the left, add this CSS:
.nav li {
text-align: left;
}
EDIT2:
You don't need this adjustMenu() javascript function. You can use media queries. Modify your #media section a bit. Add this style:
.nav {
border-top: none;
}
and replace style for .nav > li with this:
.nav > li {
display: block;
border-top: 1px solid #104336;
}
Also, I noticed that in the small range of resolution, one menu item breaks into new line. To prevent this, you can add this style to the .nav
white-space: nowrap;
overflow: hidden;
Here's the update fiddle: http://jsfiddle.net/5Z2QV/9/
I have menu, where I use :after element. I am hovering li in menu, but it is hovering with :after element.
HTML:
<ul class="main-menu">
<li class="active">Menu</li>
<li>Menu</li>
<li>Menu</li>
<li>Menu</li>
<li>Menu</li>
<li>Menu</li>
<li>Menu</li>
</ul>
CSS:
/* MAIN MENU */
.main-menu {
list-style-type: none;
padding: 0;
margin: 0;
background: url("../img/li.png") repeat-x; height: 56px;
}
.main-menu li {
display: inline-block;
color: #fff;
height: 56px;
background: url("../img/li.png") repeat-x; height: 56px;
line-height: 56px;
}
.main-menu li:after {
content: "|";
}
.main-menu li:last-child:after {
content: "";
}
.main-menu li:hover {
background: url("../img/li-hover.png") repeat-x; height: 56px;
}
.main-menu .active {
background: url("../img/li-hover.png") repeat-x; height: 56px;
}
.main-menu li a {
text-decoration: none;
color: #d2eff3;
padding: 10px;
}
.main-menu li a:hover {
}
JsFiddle:
JsFiddle example
Question:
How to exclude li:after element from hover efect?
(In menu hover effect is hovering under "|" separator. I want to disable hover under separator)
I tried:
.main-menu li:after:hover {
background: none;
}
but no luck.
Thank you for your answers.
I think that the hover effect should be on the link not on the whole li element http://jsfiddle.net/krasimir/fC8sb/6/
.main-menu {
list-style-type: none;
padding: 0;
margin: 0;
background: url("...") repeat-x; height: 56px;
}
.main-menu li {
padding: 0;
margin: 0;
display: inline-block;
color: #fff;
height: 56px;
background: url("../img/li.png") repeat-x;
}
.main-menu li:after {
padding: 14px 0 0 4px;
content: "|";
float: right;
display: block;
}
.main-menu li:last-child:after {
content: "";
}
.main-menu li:hover a {
background: url("...") repeat-x; height: 56px;
}
.main-menu .active {
background: url("../img/li-hover.png") repeat-x; height: 56px;
}
.main-menu li a {
text-decoration: none;
color: #d2eff3;
padding: 10px;
display: block;
float: left;
padding: 16px 10px 10px 10px;
}
Position the :after element outside of the li. I did this in the example by adding the following code:
li {
position:relative;
}
li:after {
position:absolute;
right:-3px;
}
See: http://jsfiddle.net/fC8sb/1/
Apply styles like this:
.main-menu li:hover::after {
background:red;
}
FIDDLE
Add a position: relative; and left: a to your li:after so that the :after element is moved away from the li box.
Next, add some margin-right: a*2 to your li so that li:after element won't just move to next menu-item.
Hope that helps.
Edit - Just to make sure: Replace a and a*2 with numbers, eh?