I have a anchor containing a span element containing my text. The span element has these attributes
border-bottom: 5px solid #59DFB8;
padding-bottom: 2px;
Now I want to create a shadow behind the border, but not the whole text. How would I do that without giving up on responsiveness?
.selected {
border-bottom: 5px solid #59DFB8;
padding-bottom: 2px;
box-shadow: 10px 10px 10px #59DFB8;
}
<div class="nav">
<ul>
<li><span class="selected">Home</span><span class="shadow"></span></li>
<li>Projects</li>
<li>About</li>
</ul>
</div>
Example:
The box-shadow property always uses its containing element's bounding box. You can't apply it to just part of an element, so you'll need to create an element specifically for the part that you want to have a shadow.
One solution would be to use pseudo-elements to create a child of the .selected element, and make that child look like an underline / bottom border. Then you can apply box-shadow to that.
Make your .selected element inline-block, so that its width is sized to its content. Then use the ::after pseudo-selector to create a block element inside of that, sized to the parent's width with a height of 5px and a solid background.
.selected {
/* so that its bounding box is only as wide as its contents */
display: inline-block;
}
.selected::after {
/* pseudo-elements must have content in order to render; give it a blank string */
content: '';
/* so it fills the parent horizontally */
display: block;
/* adjust to how tall you want the "bottom border" to be */
height: 5px;
/* color for the "bottom border" */
background: #59DFB8;
/* here's the shadow effect, adjust offsets and color as desired */
box-shadow: 10px 10px 10px #59DFB8;
}
Here is a full example, with simplified markup and some extra styles to make it look more like your example image.
ul {
list-style: none;
display: block;
background: #003447;
padding: 20px;
}
ul li {
display: inline-block;
padding-left: 20px;
padding-right: 20px;
}
ul li a {
font-family: Arial, sans-serif;
font-size: 20px;
color: #59DFB8;
text-decoration: none;
text-transform: uppercase;
}
ul li a::after {
content: '';
display: block;
margin-top: 5px;
height: 2px;
background: #59DFB8;
}
ul li a.selected::after {
box-shadow: 0px 0px 10px 1px #59DFB8;
}
ul li a:active::after,
ul li a:hover::after {
visibility: hidden;
}
ul li a.selected:active::after,
ul li a.selected:hover::after {
visibility: visible;
}
<ul>
<li>Home</li>
<li>Projects</li>
<li>About</li>
</ul>
You could do so with an :after or :before psudo-element.
.selected {
display: block;
float: left;
position: absolute;
width: 100%;
border-bottom: 5px solid #59DFB8;
padding-bottom: 2px;
box-shadow: 10px 10px 10px #59DFB8;
}
<div class="nav">
<ul>
<li><span class="selected">Home</span><span class="shadow"></span></li>
<li>Projects</li>
<li>About</li>
</ul>
</div>
I was going to expound but I see Woodrow beat me by a minute. ;p
Without seeing an example of how you want it to look I'm having to guess. The approach may depend on how subtle an effect you're going for. Here i've added a box shadow with a negative spread and semi-transparent fill:
a{text-decoration:none; color:#555;}
a:hover, a.active {
color:#000;
border-bottom: 5px solid #59DFB8;
padding-bottom: 2px;
box-shadow: 0 8px 10px -8px hsl(0, 0%, 40%);
}
.nav ul {margin:0; padding:0; display:flex;}
.nav li {margin:15px; list-style-type:none;}
<div class="nav">
<ul>
<li>Home</li>
<li>Projects</li>
<li>About</li>
<li>A Long One</li>
</ul>
</div>
Related
I'd like to do something like this image:
ul menu li tags
Should I use a double tag for every element?
For example:
<ul class="menu">
<div class="outside"><li class="inside">Firefox</li></div>
<div class="outside"><li class="inside">Chrome</li></div>
<div class="outside"><li class="inside">Opera</li></div>
</ul>
Or maybe a double li tag?
I have tried in CSS the linear-gradient property, but with just one tag, and as I want to get the same result like in the image, it seems to me that there has to be two different tags with different background colors and the one with the black color just has to have a higher z-index property.
I'm quite new and a bit bad at design and styling, so I just can thank you so much in advance for your help!
You can use the pseudo element ::before to create the left colored side
Note, the div's you used is invalid as a direct child of an ul, so I removed them
ul.menu {
display: flex;
list-style: none;
padding: 0;
}
ul.menu li {
margin: 0 5px;
}
ul.menu a {
position: relative;
display: inline-block;
width: 120px;
background: black;
color: white;
padding: 4px 0 4px 10px;
text-decoration: none;
text-align: center;
}
ul.menu a::before {
content: '';
position: absolute;
top: 0; left: 0; bottom: 0;
background: gray;
width: 10px;
}
<ul class="menu">
<li>Firefox</li>
<li>Chrome</li>
<li>Opera</li>
</ul>
Or a left border
ul.menu {
display: flex;
list-style: none;
padding: 0;
}
ul.menu li {
margin: 0 5px;
}
ul.menu a {
position: relative;
display: inline-block;
width: 120px;
background: black;
color: white;
padding: 4px 0;
text-decoration: none;
text-align: center;
border-left: 10px solid gray;
}
<ul class="menu">
<li>Firefox</li>
<li>Chrome</li>
<li>Opera</li>
</ul>
You can use linear-gradient, just place both values of the gradient to be at the same point (ex: gray 10%, black 10%) so they split the background at that point.
Side Note: You should also remove the outter divs around your li tags, because they are not valid inside ul element.
ul.menu {
list-style: none;
display: flex;
}
ul.menu li.inside {
background: linear-gradient(to right, gray 10%, black 10%);
margin-left: 5px;
padding: 5px 5px 5px 20px;
width: 120px;
display: block;
box-sizing: border-box;
}
li a {
color: white;
}
<ul class="menu">
<li class="inside">Firefox</li>
<li class="inside">Chrome</li>
<li class="inside">Opera</li>
</ul>
When I put in a margin it adds 5px to the right as I expect it too, but it creates problems with my box-shadow. I want the box-shadow to be able to cover that space (white space) created by the margins. Is there a work around for that? Obviously if you don't have any margins the box-shadow looks fantastic.
Here is my CSS
#horizontalNav{
margin: 0;
padding: 0;
}
#horizontalNav ul{
margin: 0;
padding: 0;
box-shadow: 5px 5px 10px #888888;
}
#horizontalNav ul li{
margin-right: 5px; /* Make this margin a 0 to see what it looks like without margin added */
padding: 0;
list-style: none;
position: relative;
float: left;
background: linear-gradient(to bottom right, rgba(181,147,38,0.1), rgba(181,125,22,1));
}
#horizontalNav ul li a{
text-align: center;
width: 150px;
height: 30px;
display: block;
color: white;
border: 1px solid black;
text-decoration: none;
text-shadow: 1px 1px 1px black;
}
#horizontalNav ul ul{
position: absolute;
visibility: hidden;
top: 32px;
}
#horizontalNav ul li:hover ul{
visibility: visible;
}
#horizontalNav ul li:hover{
background: linear-gradient(to bottom right, rgba(167,120,38,0.1), rgba(167,136,42,1));
}
#horizontalNav ul li:hover ul li a:hover{
background: linear-gradient(to bottom right, rgba(180,105,45,0.1), rgba(180,135,15,1));
}
#horizontalNav ul li a:hover{
color: black;
}
#horizontalNav ul li ul li a:hover{
color: #120801;
}
Here is my HTML
<div id="wrapper">
<div id="horizontalNav">
<ul>
<li>Home
<ul>
<li>Home Sub 1</li>
<li>Home Sub 1</li>
<li>Home Sub 1</li>
<li>Home Sub 1</li>
<li>Home Sub 1</li>
</ul>
</li>
</ul>
</div>
</div>
If you don't want the box shadow on the ul, then try putting the box-shadow on another element. The actual link seems to achieve what you want, but then grabs the top level link, so you might need to target even more specifically.
#horizontalNav ul ul a {
box-shadow: 5px 5px 10px #888888;
}
Actually... that's not the best element to add it too. Here is a stripped down fiddle with a complete answer. I also urge you to see how giving the right elements classes, (the fist ul) it makes things much more readable.
jsFiddle
why you are adding margin-right to 5px it seems worthless. For space you should add padding-right to 5px;
I'm working on a navigation, and I can't seem to figure out how to make the bottom border increase in size upwards, instead of expanding downwards (which in turn extends my header a few pixels), I could fix the extending header with setting a height, but the the border will still extend downwards instead of upwards.
The CSS:
header {
margin: 0;
padding: 0;
left: 0;
top: 0;
width: 100%;
position: absolute;
background: #000000;
}
ul {
list-style-type: none;
display: block;
margin: 0 0 0 20px;
padding: 0;
}
ul li {
display: inline-block;
padding: 0;
}
ul li a{
display: block;
border-bottom: 1px solid #fff;
font-size: 19px;
}
ul li a:hover{
border-bottom: 2px solid #fff;
background: #333;
font-size: 19px;
}
The HTML:
<header>
<ul id="nav">
<li>link 1</li>
<li>link 2</li>
<li>link 3</li>
</ul>
</header>
The JSFiddle:
http://jsfiddle.net/Artsen/EZWvF/
So you want to increase the border-bottom to the top, right?
I've actually had to do this for a website recently. There is no other way than to set specific padding, and border properties.
I edited your jsfiddle here: http://jsfiddle.net/EZWvF/2/ (changed some properties to make the test case more visible)
The principle is: Swap the pixel values from padding-bottom and border-bottom on hover.
These are the key lines to your solution:
ul li a {
border-bottom: 1px solid white;
padding-bottom: 5px;
}
ul li a:hover {
border-bottom: 5px solid white;
padding-bottom: 1px;
}
Note: This only works if you don't add a css-transition. If you unquote the css-transition I put in the fiddle, you'll see that the div still expands to the bottom. If you want a ss-transition you'll need to add a separate div to the li's to mimic a border.
As Tyblitz suggested using extra padding value on :hover works great when you don't need a transition.
If you need transition and don't want to introduce an extra div you can do it using the line-height/height approach for controlling the vertical height.
so instead of doing this:
.nav-element a {
color: gray;
padding: 25px 15px;
transition: all ease-in-out 0.2s;
display: block;
text-decoration: none;
}
do this:
.nav-element a {
color: gray;
padding: 0 15px;
line-height: 70px;
height: 70px;
transition: all ease-in-out 0.2s;
display: block;
text-decoration: none;
}
See example where it doesn't work here
and does work (using the line-height/height) here
I have made a navigation bar using <ul> and <li>
I would like to customize each tab with border, gradient etc.
Where should it be applied?
My CSS styling tend to affect only the letters, not anything else.
CSS
#nav {
width: 100%;
margin: 20px 0px 20px 0px;
}
#nav ul {
padding: 12px 0px 12px 0px;
border-top: solid black 1px;
border-bottom: solid black 1px;
}
#nav ul li {
display: inline;
margin-left: 50px;
font-weight: bold;
background-color: grey;
}
HTML
<div id="nav">
<ul>
<li>Home</li>
<li>Files</li>
<li>Info</li>
<li>About</li>
</ul>
</div>
'a' tags inside of a styled tag (such as an 'li' tag) will not pick up any of the styles you set. They want their own styles. You will need to move all the 'li' styles to the 'a' tag and then put a display:block; on the 'a' tag.
#nav {
width: 100%;
margin: 20px 0px 20px 0px;
}
#nav ul {
padding: 12px 0px 12px 0px;
border-top: 1px solid black;
border-bottom: 1px solid black;
}
#nav ul li {
display: inline;
margin-left: 10px;
width:50px;
height:20px;
line-height:20px;
font-weight: bold;
background-color: grey;
}
a {
display: block;
// then whatever other rules you want to apply: width, height, border, pink flowers, etc
}
I have a problem with z-index in a CSS-Menu. I built the menu with nested ul Tags.
Clearly, the first ul is the first level in the menu-hierarchy. As a background-property of this first ul, I set a gradient and a box-shadow, all with CSS of course.
The second ul (the nested one) is the second level in the menu-hierarchy. I gave it a gray background-color.
Unfortunately, the second ul overlays the first ul. I tried to play around with z-index, but I can't get it to work. I'd like to get the shadow of the first ul over the nested ul.
Here is the code so that you may reproduce it:
CSS:
ul.menu {
/* Gradient: */
background: #444;
background: -webkit-gradient(linear, left top, left bottom, from(#999), to(#777));
background: -moz-linear-gradient(top, #999, #777);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#999', endColorstr='#777');
height: 25px;
/* Box-Shadow: */
-moz-box-shadow: 1px 3px 3px #888;
-webkit-box-shadow: 1px 3px 3px #888;
box-shadow: 1px 2px 3px #888;
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')";
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
position: relative;
z-index: 20;
}
ul.menu, ul.menu ul {
list-style: none;
margin: 0;
padding: 0;
}
ul.menu a {
display: block;
text-decoration: none;
color: #000;
line-height: 22px;
padding-right: 15px;
padding-left: 15px;
}
ul.menu li {
padding:0;
margin:0;
float:left;
}
ul.menu ul {
margin-left: 15px;
padding: 0;
position: absolute;
display: none;
background-color: #CCC;
z-index: 10;
}
ul.menu li:hover ul {
display: block;
}
ul.menu ul li {
float: none;
}
Here is the HTML:
<ul class="menu">
<li>ONE
<ul>
<li>SUB_ONE</li>
<li>SUB_TWO</li>
<li>SUB_THREE</li>
</ul>
</li>
<li>TWO</li>
<li>THREE</li>
</ul>
Is there any way that the first ul overlays the second ul or is it just not possible?
I have a work-around. By inserting a DIV above the nested UL that has its own shadow, you can get it on top of the sub-menu.
See: http://jsfiddle.net/SLkrN/6/
Short answer after some testing appears to be: even setting all elements to float, the containment of the sub menus in the parent .menu ul is causing them to not respond to z-index changes except relatively, never decreasing below the parent UL. I'll continue experimenting. May I suggest, however, putting the submenus lower so they at least are inline with the bottom of the parent ul?
ul.menu ul {
margin-left: 15px;
margin-top: 5px;
padding: 0;
position: absolute;
display: none;
background-color: #CCC;
z-index: 10;
}