Add divider | between menus - css

I'm trying to add a separator between my navigation menu(header).
So basically make it A|B|C
I tried to add this code:
This is an edit:
So my snip, from where the title and url are retrieved looks like this:
<li class="dropdown{% if link.active %} selected{% endif %}{% if submenu_type == 'menu_two_columns' %} tt-megamenu-col-02{% elsif submenu_type == 'megamenu' %} megamenu{% else %} tt-megamenu-col-01{% endif %}" {{ block.shopify_attributes }}>
{{ link.title }}
And I added this code in my theme.css
.link {
position: relative;
display: inline-block;
height: 40px;
line-height: 40px;
padding: 0 20px;
color: #333;
text-decoration: none;
background-color: #ddd;
transition: all 0.2s ease;
}
.link:before {
content: '|';
position: absolute;
left: -1px;
line-height: 40px;
}
.link:first-child:before {
content: '';
}
.link:hover {
background-color: #aaa;
color: #000;
}
However, I am not getting the |

you set width:1px to link class so content of that class is not appears, just replace your css code
.link{
height: 40px;
width: 1px;
margin: 0 5px;
overflow: hidden;
background-color: #DDD;
border-right: 2px solid #FFF;
}
with
.link{
height: 40px;
width: auto;
margin: 0 5px;
overflow: hidden;
background-color: #DDD;
border-right: 2px solid #FFF;
}

Try this.
ul{
overflow:hidden;
}
li{
list-style:none;
position:relative;
float:left;
padding:0 15px;
}
li:first-child{
padding-left:0;
}
li:last-child{
padding-right:0;
}
li:not(:last-child):after{
position:absolute;
border:1px solid #000;
height:100%;
content:"";
right:0;
}
li a{
text-decoration:none;
}
<div>
<ul>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
</ul>
</div>

Add your border on the left of each link:
.link {
border-left: 2px solid #fff;
}
Then add a CSS rule that cancels that border on the first link using the first-child selector:
.link:first-child {
border-left: none;
}
It's important your links are behaving like links, taking up enough space, etc. I used my own approach here, feel free to take what you like.
.menu {
background: red;
display: flex;
}
.link {
position: relative;
display: inline-block;
height: 40px;
line-height: 40px;
padding: 0 20px;
color: #333;
text-decoration: none;
background-color: #ddd;
transition: all 0.2s ease;
}
.link:before {
content: '|';
position: absolute;
left: -1px;
line-height: 40px;
}
.link:first-child:before {
content: '';
}
.link:hover {
background-color: #aaa;
color: #000;
}
<nav class="menu">
Home
About
Contact
Blog
</nav>

Use a Horizontal rule between tags
.menu {
background: #ddd;
display: flex;
}
.link {
display: inline-block;
height: 40px;
line-height: 40px;
padding: 0 30px;
color: #333;
text-decoration: none;
background-color: #ddd;
transition: all 0.2s ease;
}
hr{
margin:0px;
color:blue;
}
.link:first-child {
border-left: none;
}
.link:hover {
background-color: #aaa;
color: #000;
}
<nav class="menu">
Home<hr>
About<hr>
Contact<hr>
Blog<hr>
</nav>
Whats the catcher just place a hr tag between each link and you get the line. hr means horizontal line but since the display is set to inline block and the height is set it can be used as a vertical line

Edit
I've taken your exact updated CSS and placed a few .link anchors inside a nav container. You can see the generated content (separator bar) working as you've styled. The only thing I've changed, which doesn't affect the render, is replacing content: '' with content: none.
.link {
position: relative;
display: inline-block;
height: 40px;
line-height: 40px;
padding: 0 20px;
color: #333;
text-decoration: none;
background-color: #ddd;
transition: all 0.2s ease;
}
.link:before {
content: '|';
position: absolute;
left: -1px;
line-height: 40px;
}
.link:first-child:before {
content: none;
}
.link:hover {
background-color: #aaa;
color: #000;
}
<nav>
A
B
C
</nav>
jsFiddle
Here's an example for you using a pseudo class to create the bar separator (|) in CSS content. This is the preferred way to handle details like this because you have more control over the content styling and positioning. I'm also using CSS negation to not add the separator after the last child. To vertically center the generated content, I've used top: 50% and a transform: translateY(-50%) to account for half the height of the actual separator.
.link{
margin: 0 5px;
background-color: #DDD;
position: relative;
}
.link:not(:last-child)::after {
content: '';
position: absolute;
display: block;
right: -10px;
top: 50%;
transform: translateY(-50%);
border-right: 2px solid #000;
height: 100%;
}
<nav>
A
B
C
</nav>
jsFiddle

Related

Can a child absolute element go under parent inline element

I want to make a tab style so the bottom of the tab doesn't have an underline. To do this I thought I could set bottom border color of tab and then make child menu go underneath.
I am not sure if that is possible though.
This excerpt is taken from site, it is done like this as the child menu is usually shown on hover.
body {
background-color: #000;
}
.desktop-menu {
color: #fff;
list-style: none;
}
.desktop-menu a {
color: #fff;
text-decoration: none;
}
.desktop-menu > li {
background-color: blue;
width: 60px;
margin-left: 25px;
border: 1px solid #fff;
border-bottom-color: blue;
padding: 10px;
position: relative;
z-index: 20;
}
.desktop-menu ul {
background-color: blue;
z-index: 10;
width: 200px;
display: flex;
position: absolute;
top: 100%;
left: -1px;
flex-direction: column;
list-style: none;
margin: 0;
padding: 10px 20px;
padding-top: 15px;
border: 1px solid #fff;
background-color: darkblue li;
padding-bottom: 15px;
}
.desktop-menu .has-sub:hover {
border: 1px solid #fff;
}
.desktop-menu .has-sub:hover ul {
display: flex;
}
<ul class="desktop-menu">
<li class="has-sub">Products
<ul>
<li>Product name 1</li>
<li>Prod name 2</li>
</ul>
</li>
</ul>
I am trying to remove this white line:
What is best method to achieve this?
Just a hack but it works.
.desktop-menu > li {
position: relative;
// ...
}
.desktop-menu > li::after {
content: "";
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 1px;
width: 100%;
background-color: blue;
}
.desktop-menu ul {
display: none;
transform: translateY(-1px);
// ...
}
.desktop-menu .has-sub:hover ul {
display: flex;
}
See result in codesandbox.
Note: not suitable if you are working with transparent backgrounds.
Edit: updated the sandbox to proof it works with the hover effect.

How to make elements stay in place when using transitions on hover

How do I make li elements not move around when applying transitions using :hover? The circles are made applying height and border-radius to the li elements. I've tried making the ul container bigger, but that didn't seem to work. Thanks for your help.
Code:
body {}
main {
display: flex;
background: #eeeeee;
min-height: 100vh;
padding: 1em;
}
h1 {
font-family: arial;
font-size: 1.4em;
padding-left: 1em;
}
ul {
padding-top:50px;
min-height: 600px;
position:relative;
}
li {
position:relative;
background-color: purple;
border-radius: 50%;
width: 50px;
height: 50px;
padding: 1em;
text-align: center;
list-style: none;
display: inline-block;
line-height: 50px;
border: 5px solid red;
margin-right: -1em;
z-index: 0;
transition: width 0.5s, height 0.5s, background-color 1s, line-height 0.5s;
}
li:hover {
display: inline-block;
position:relative;
width: 90px;
height: 90px;
z-index: 10;
background-color: green;
line-height: 90px;
}
<body>
<main>
<h1>
My animated Menu
</h1>
<div class="menu">
<ul>
<li>X</li>
<li>Y</li>
<li>Z</li>
</ul>
</div>
</main>
</body>
Use CSS3 transforms, this way the element can freely move or scale into the DOM without affecting the layout size.
A nice bonus: the animation will be more efficient in terms of fps as the layout won't be re-computed on each frame (an the GPU will be used)
ul {
padding-top: 50px;
}
li {
background-color: purple;
border-radius: 50%;
width: 50px;
height: 50px;
padding: 1em;
text-align: center;
list-style: none;
display: inline-block;
line-height: 50px;
border: 5px solid red;
margin-right: -1em;
z-index: 0;
transition: transform 0.5s, background-color 1s;
}
li:hover {
display: inline-block;
position: relative;
transform: scale(1.5);
z-index: 10;
background-color: green;
}
<div class="menu">
<ul>
<li>X</li>
<li>Y</li>
<li>Z</li>
</ul>
</div>

Pagination with extra space

I have some pagination in a div and am seeing some extra space. I'm not sure where it is coming from. The extra space is green (I added a background to the container).
The URL is: http://joshrodg.com/test/inductees/page/2/
Basically, at the bottom of the page, you'll see the pagination. The code is generated, so I can't change that. I'm pretty sure it's something with the css adding the extra space.
I can put a height on the wrap and the extra space goes away, but that's cheating.
The HTML looks like:
<div id="pagi">
<div class="wrap">
<a class="prev page-numbers" href="http://joshrodg.com/test/inductees/"><span class="left"></span><span class="ion-android-arrow-dropleft"></span> Prev</a>
<a class="page-numbers" href="http://joshrodg.com/test/inductees/">1</a>
<span aria-current="page" class="page-numbers current">2</span>
<a class="page-numbers" href="http://joshrodg.com/test/inductees/page/3/">3</a>
<a class="page-numbers" href="http://joshrodg.com/test/inductees/page/4/">4</a>
<span class="page-numbers dots">…</span>
<a class="page-numbers" href="http://joshrodg.com/test/inductees/page/15/">15</a>
<a class="next page-numbers" href="http://joshrodg.com/test/inductees/page/3/">Next <span class="ion-android-arrow-dropright"></span><span class="right"></span></a>
</div>
</div>
The CSS looks like:
#pagi {
text-align: center;
}
#pagi .wrap {
background: #00ff00;
display: inline-block;
font-size: 0;
overflow: hidden;
position: relative;
}
#pagi .page-numbers {
background: #CD1F31;
display: inline-block;
color: #fff;
font-family: 'Lato', sans-serif;
font-size: 18px;
line-height: 40px;
padding: 0 10px;
position: relative;
text-decoration: none;
top: -2px;
}
#pagi .current {
background: #fff;
color: #CD1F31;
}
#pagi .next,
#pagi .prev {
background: #054872;
color: #fff;
font-family: 'Oswald', sans-serif;
font-size: 20px;
line-height: 40px;
position: relative;
text-transform: uppercase;
top: 0;
}
#pagi .next {
padding: 0 35px 0 16px;
}
#pagi .prev {
padding: 0 16px 0 35px;
}
#pagi .left,
#pagi .right {
background: #333;
border-bottom: 21px solid transparent;
border-top: 21px solid transparent;
height: 0;
position: absolute;
top: 0;
width: 0;
}
#pagi .left {
border-right: 12px solid #054872;
left: 0;
}
#pagi .right {
border-left: 12px solid #054872;
right: 0;
}
#pagi .ion-android-arrow-dropleft,
#pagi .ion-android-arrow-dropright {
display: inline-block;
font-size: 30px;
position: absolute;
top: 6px;
}
pagi .ion-android-arrow-dropleft {
left: 18px;
}
#pagi .ion-android-arrow-dropright {
right: 18px;
}
#pagi a:hover .ion-android-arrow-dropleft,
#pagi a:hover .ion-android-arrow-dropright {
color: #fff;
}
#pagi a:hover {
color: #ddd;
}
I know this is probably something simple that I'm over-looking. If someone could point me in the right direction I'd appreciate it!
The one thing I forgot to mention is everything works just fine when the fonts are the same - my guess is the size differences are causing some of the issues.
Thanks,
Josh
So, after investigating this issue further, my problem was being creating by the different Google Web Fonts I was using.
The page numbers use a font called Lato and the Previous and Next links use a font called Oswald.
Somehow the line heights and padding that both fonts had were conflicting and I couldn't get them to play nicely with each other.
Both the Previous and Next links and the page numbers have the same pagenumbers class assigned. Because this is generated code, that's something I can't change.
So, I removed the Oswald font, which fixed the issue...unfortunately, I wanted the font to be different, so I was thinking about other options available visually.
I also had some arrows next to the Previous and Next links. Those arrows were absolutely positioned, so none of the line height issues apply.
After thinking it over I decided to go with arrows-only!
Now, the alignment is fixed and I understand what happened.
The HTML remains unchanged:
<div id="pagi">
<div class="wrap">
<a class="prev page-numbers" href="http://joshrodg.com/test/inductees/"><span class="left"></span><span class="ion-android-arrow-dropleft"></span> Prev</a>
<a class="page-numbers" href="http://joshrodg.com/test/inductees/">1</a>
<span aria-current="page" class="page-numbers current">2</span>
<a class="page-numbers" href="http://joshrodg.com/test/inductees/page/3/">3</a>
<a class="page-numbers" href="http://joshrodg.com/test/inductees/page/4/">4</a>
<span class="page-numbers dots">…</span>
<a class="page-numbers" href="http://joshrodg.com/test/inductees/page/15/">15</a>
<a class="next page-numbers" href="http://joshrodg.com/test/inductees/page/3/">Next <span class="ion-android-arrow-dropright"></span><span class="right"></span></a>
</div>
</div>
The CSS looks like:
#pagi {
margin: 5px 20px 25px;
text-align: center;
}
#pagi .wrap {
background: #054872;
display: inline-block;
font-size: 0;
overflow: hidden;
position: relative;
}
#pagi .page-numbers {
background: #CD1F31;
display: inline-block;
color: #fff;
font-family: 'Lato', sans-serif;
font-size: 18px;
line-height: 40px;
padding: 0 10px;
text-decoration: none;
}
#pagi .current {
background: #fff;
color: #CD1F31;
}
#pagi .next,
#pagi .prev {
color: #fff;
text-transform: uppercase;
}
#pagi .next {
padding: 0 25px 0 16px;
}
#pagi .prev {
padding: 0 16px 0 25px;
}
#pagi .left,
#pagi .right {
background: #333;
border-bottom: 21px solid transparent;
border-top: 21px solid transparent;
height: 0;
position: absolute;
top: 0;
width: 0;
}
#pagi .left {
border-right: 12px solid #054872;
left: 0;
}
#pagi .right {
border-left: 12px solid #054872;
right: 0;
}
#pagi .ion-android-arrow-dropleft,
#pagi .ion-android-arrow-dropright {
display: inline-block;
font-size: 30px;
position: absolute;
top: 6px;
}
#pagi .ion-android-arrow-dropleft {
left: 18px;
}
#pagi .ion-android-arrow-dropright {
right: 18px;
}
#pagi a:hover .ion-android-arrow-dropleft,
#pagi a:hover .ion-android-arrow-dropright {
color: #fff;
}
#pagi a:hover {
color: #ddd;
}
There are other ways I could've fixed this. I could've specified a width and absolutely positioned my Previous and Next links, which would also fix this issue because of the absolute positioning.
But, I like this solution and think it is better to just not have the inferred Previous and Next links and just show the icons (pointing in their respective directions).
Thanks,
Josh

Border-top Extending too far

I've got an interesting one: I was testing methods to get the list-item elements of a nav bar to spread evenly across the length of a nav. I used the display:table and display: table cell method to get the most even spread and that seemed to work fine.
When I went to add an ::after element so I could add a top-bar and have a smoother on-hover effect, I found that the bar extended past where I wanted it to -- I was trying to have it just to the end of the words "Communication Design". So I thought I'd just resize the nav container holding my list-elements but because it's a table/table-cell, when the nav resizes, the list-items shink along with it and I can never shore up the last element in the list.
Is there a way to either affect the size of the last table cell or only show a percentage of the ::after element?
Code:
HTML:
<h3>Test & Co.</h3>
<p id="title2">Communications Design</p>
<div id="navContainer">
<ul>
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Contact</li>
</ul>
</div>
CSS:
*
{
padding: 0;
margin: 0;
}
h3
{
padding-left: 140px;
display: inline-block;
padding-top: 10px;
padding-bottom: 25px;
}
#title2
{
display: inline-block;
float: right;
font-size: 16px;
margin-right: 252.5px;
padding-top: 14px;
padding-bottom: 25px;
}
#navContainer
{
//border: 1px solid black;
width: 643px;
margin-left: 140px;
height: 30px;
background: white;
}
#navContainer ul
{
list-style:none;
display: table;
width: 100%;
}
#navContainer ul li
{
display: table-cell;
height: 30px;
line-height: 30px;
font-family:arial;
font-size: 12px;
text-align: left;
//border: 1px solid black;
transition: color .2s ease-in-out;
position: relative;
}
#navContainer ul li::after
{
content: "";
display: block;
float: right;
position: absolute;
margin: auto;
height: 1px;
top: 0;
width: 100%;
background: #ccc;
transition: background-color .2s ease;
}
#navContainer ul li:hover::after
{
background: #8c8c8c;
}
#navContainer ul li:hover
{
color: #A6CFEB;
}

Decreasing inner box shadow with CSS3

I would like to know if (and maybe how) some text-shadow like shown in following image is possible:
The shadow is decreasing over several list-elements. I was thinking to give each element different hover-classes depending on what element is being hovered on, but I am not even sure how to get such decreasing shadows with CSS. Would be really cool if someone would be able to teach me how to do that. If you want you can use my jsfiddle code.
You could try something like this
demo
(click a tab to select it and see the shadows)
and get the effect using box-shadow on pseudo-elements of the selected tab.
Should look like this
HTML:
<ul class='tabs'>
<li><a href='#' tabindex='1'>1st tab</a></li>
<!-- as many tabs as you would like -->
<li><a href='#' tabindex='1'>aaand another tab</a></li>
</ul>
Relevant CSS:
.tabs { overflow: hidden; margin-top: 7em; list-style: none; }
.tabs li { float: left; border-right: 1px dotted #222; }
.tabs a {
display: block;
position: relative;
padding: 1em .66em;
font: .66em/1.1 sans-serif;
text-transform: uppercase;
text-decoration: none;
}
.tabs a:focus {
z-index: 3;
outline: none;
box-shadow: 0 -.5em 1.5em black;
background: lemonchiffon;
}
.tabs a:focus:before, .tabs a:focus:after {
position: absolute;
bottom: -1px;
width: 30em; height: 1px;
box-shadow: 0 0 20px 1px black;
content: '';
}
.tabs a:before {
left: -30.5em;
transform: rotate(-3deg);
transform-origin: 100% 100%;
}
.tabs a:after {
right: -30.5em;
transform: rotate(3deg);
transform-origin: 0 100%;
}
You could augment an <li> to sit within the whole width of the <ul>, rotate it and give it a shadow..
HTML:
...
</li>
<li class="shadow">1</li>
</ul>
CSS:
ul
{
overflow: hidden;
height: 50px;
}
li.shadow
{
width: 100%;
height: 100%;
position: relative;
top: 15px;
box-shadow: 0px 0px 45px #000;
-webkit-transform:rotate(-1deg);
}
​
http://jsfiddle.net/Kyle_Sevenoaks/4Luet/1/

Resources