Pagination items move on hover and adding border - css

This menu items are moving when hover.How can I make the items static and not moving when hovering.
Same thing happens when putting a specific width and height.
Here's the NEW JSFiddle link.
http://jsfiddle.net/tagaawang/zTCCf/3/
/CSS/
<style type="text/css">
.div{margin:0 auto;position:relative;margin-top:40px;}
.pagination{height: 42px;
clear: right;
top: -21px;
left: 0;
position: absolute;}
.pagination ul{width: 100%;max-height: 42px;}
.pagination li{font-family: 'Open Sans', sans-serif;
list-style: none;
cursor: pointer;
font-weight: 600;
line-height: 23px;
text-indent: 8px;
color: white;
background-color: #0083DE;
height: 26px;
font-size: 14px;display: inline-block;
width: 26px;margin-left:10px; }
.pagination li.selected{background-color: white;
border: 4px solid #F0F0F0;
padding: 5px;
position: relative;
font-weight: 600;
color: #0F7ABE;
font-family: 'Open Sans', sans-serif;}
.pagination li:hover{background-color: #0083DE;
border: 4px solid #F0F0F0;
padding: 5px;
position: relative;
font-weight: 600;
color: #ffffff;
font-family: 'Open Sans', sans-serif;}​
</style>
html
<div class="div">
<div class="pagination">
<ul>
<li>1</li>
<li class="selected">2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
</div>
​

based on your code, the hover and/or selected state goes along with a border of 4px:
border: 4px solid #F0F0F0;
This causes a shift of 4 pixel offcourse, solution:
Add a border with same color as the background of your site as placeholder, then when hovering, change border-color.
.pagination li{
border: 4px solid #fff;
}
.pagination li.selected, .pagination li:hover {
border-color: #F0F0F0;
}

Related

Is it possible to increase the padding of an element while not affecting its border?

I have a navigation bar that includes the usual links, and to improve the user experience I have a bottom border show on hover:
I achieve this with the following code:
body {
background-color: #E9EBEE;
color: #666666;
margin: 0px;
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
font-size: 16px;
}
.nav {
padding-top: 50px;
padding-bottom: 5px;
margin-top: 2em;
margin-bottom: 6em;
background-color: #F6F7F9;
color: #666666;
font-size: 1.5em;
line-height: 1.5;
text-align: center;
}
.nav > .links {
margin-top: -36px;
border-left: solid 1px #E9EBEE;
font-size: 0.8em;
}
.nav > .links > .link {
float: left;
position: inherit;
border-right: solid 1px #E9EBEE;
border-bottom-width: 2px;
width: 8em;
transition: border-color .2s;
}
.nav > .links > .link:hover {
border-bottom: solid;
border-bottom-color: #3B5998;
border-bottom-width: 2px;
color: #3B5998;
}
<body>
<div class="nav">
<div class="links">
<div class="link">
Servers
</div>
</div>
</div>
</body>
I'd like the border to be on the bottom of nav; to do this I added padding-bottom:11px; to .nav > .links > .link, which resulted in this:
The result is exactly what I wanted, however notice that the right and left borders of each navigation item has been extended; something that I should've realised would happen when adding the padding-bottom attribute to .nav > .links > .link.
To fix this I thought that I could use a border-bottom-height since there is a border-bottom-width but apparently no such thing exists, and I don't want to use an additional element if possible to provide the left & right borders. As seen in the first image, the left and right borders should be approximately the height of the text contained.
Is this possible without an additional 'wrapper' element?
Use a pseudo element instead, i.e. ::after (if to support IE8, use :after, works cross browser)
body {
background-color: #E9EBEE;
color: #666666;
margin: 0px;
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
font-size: 16px;
}
.nav {
padding-top: 50px;
padding-bottom: 5px;
margin-top: 2em;
margin-bottom: 6em;
background-color: #F6F7F9;
color: #666666;
font-size: 1.5em;
line-height: 1.5;
text-align: center;
}
.nav > .links {
margin-top: -36px;
border-left: solid 1px #E9EBEE;
font-size: 0.8em;
}
.nav > .links > .link {
float: left;
position: relative;
border-right: solid 1px #E9EBEE;
border-bottom-width: 2px;
width: 8em;
transition: border-color .2s;
}
.nav > .links > .link:hover::after {
content: '';
position: absolute;
top: calc(100% + 11px);
left: 0;
width: 100%;
height: 2px;
background: #3B5998;
}
<body>
<div class="nav">
<div class="links">
<div class="link">
Servers
</div>
</div>
</div>
</body>
There are many ways to do this. In most cases, the simplest and cleanest option would be to create a pseudo-element (as suggested by LGSon), but sometimes this isn't possible. For example, you may already have used both pseudo-elements for other effects, or you may not be able to position it properly (notice that the pseudo-element method requires you to set the .link element's position property to relative -- this may not always be possible for your layout).
Below is an alternative technique, using box-shadow. It has its own drawbacks, most notably that it only works when working with a solid-color background.
The idea is simple: draw two box-shadows (since they can stack!) on the hovered element. The bottom one is two pixels taller than the top one. The bottom one is blue, the top one is the same color as the nav bar.
body {
background-color: #E9EBEE;
color: #666666;
margin: 0px;
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
font-size: 16px;
}
.nav {
padding-top: 50px;
padding-bottom: 5px;
margin-top: 2em;
margin-bottom: 6em;
background-color: #F6F7F9;
color: #666666;
font-size: 1.5em;
line-height: 1.5;
text-align: center;
}
.nav > .links {
margin-top: -36px;
border-left: solid 1px #E9EBEE;
font-size: 0.8em;
}
.nav > .links > .link {
float: left;
position: inherit;
border-right: solid 1px #E9EBEE;
border-bottom-width: 2px;
width: 8em;
transition: border-color .2s;
}
.nav > .links > .link:hover {
color: #3B5998;
box-shadow:
0 11px 0 #F6F7F9,
0 13px 0 #3B5998;
}
<body>
<div class="nav">
<div class="links">
<div class="link">
Servers
</div>
</div>
</div>
</body>

Create space between left border of vertically aligned list items

I am trying to make a vertical navbar. I have used an unordered list, with a border-left propoerty, so that on hover, I can change the opacity/color of the border. The problem right now, is that this border appears as a continuous line across the list items. I want to include some space between the list items so that the borders are separated and one can make out which border belongs to which list item.
HTML:
<div class="leftNavbar">
<span class="navLine"></span>
<ul>
<li>Introduction</li>
<li>Whats new?</li>
<li>Gallery</li>
</ul>
</div>
CSS:
.leftNavbar{
position: absolute;
top: 100px;
z-index: 500;
left: 50px;
vertical-align: middle;
}
.leftNavbar ul{
list-style: none;
}
.leftNavbar ul li{
font-family: 'Sintony', sans-serif;
height: 100px;
text-transform: uppercase;
color: white;
font-weight: bold;
text-shadow: 0px 0px 2px #000;
vertical-align: middle;
line-height:100px;
border-left:4px solid blue;
}
JSFIDDLE: http://jsfiddle.net/ATQ4Q/
You could add a margin to the list items. Something like margin-bottom:5px;:
.leftNavbar ul li {
font-family:'Sintony', sans-serif;
height: 100px;
text-transform: uppercase;
color: white;
font-weight: bold;
text-shadow: 0px 0px 2px #000;
vertical-align: middle;
line-height:100px;
border-left:4px solid blue;
margin-bottom:5px;
}
jsFiddle example

MENU DISPLAY PROBLEMS

So I have a menu from ul and li, and it looks something like this at page load:
but when i click each menu and executed the code this happens:
what should i do? here's my CSS:
#menu-centered {
padding: 0px;
margin-bottom: 0px;
}
#menu-centered ul {
margin: 0;
padding: 0;
height: 99px;
width: 603px;
}
#menu-centered li {
display: inline;
list-style: none;
padding: 0px;
background: url(images/menu1.png) no-repeat right top;
}
#menu-centered a {
border-style: none;
border-color: inherit;
border-width: medium;
display: block;
margin-right: 0;
padding: 20px 30px 0px 30px;
text-decoration: none;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
font-weight: normal;
color: #FFFFFF;
height: 68px;
width: 130px;
text-align: center;
}
#menu-centered a:hover {
background: url(images/menu2.png) no-repeat right top;
}
and here's my html code for the menus:
<div id="menu-centered">
<ul>
<li> <a href="javascript:Clikbtn1()" >MENU1</a></li>
<li>MENU2</li>
<li>MENU3</li>
</ul>
</div>
Please help. Thanks
Your menus need some LoVe and HAte. In other words you need to create all four of the important link pseudoselectors to avoid letting browsers destroy your layout by applying the default active pseudoslector.
Define a:link, a:visited, a:hover and a:active for your menu, in that order exactly.

How to center text inside a li element inside an unordered list

This list is working great for me but the text within the <li> elements is not centering.
The <li>s must auto resize to their content.
#nav-menu {
font-family: Verdana, Arial, Helvetica, sans-serif;
height: 30px;
background-image: url(../img/menu_bg.png);
background-repeat: repeat-x;
border-bottom: dotted thin #666666;
border-top: dotted thin #666666;
text-align: center;
width: 800px;
}
#nav-menu ul {
list-style: none;
padding: 0;
margin: auto 0;
}
#nav-menu li {
float: left;
border-right: dotted thin #666666;
list-style: none;
padding: 0.5em 2em 0.5em 0.75em;
}
#nav-menu li a {
line-height: 1.5em;
color: #333333;
text-decoration: none;
font-size: 12px;
font-weight: bold;
display: block;
}
<div id="nav-menu">
<ul>
<li class="current_page_item">Home
<li class="current_page_item">Home
<li class="current_page_item">Home
<li class="current_page_item">zxczczxczHome
</ul>
</div>
While you're assigning unequal padding values to the left and right of the li (0.75em and 2em respectively) the text can't be centred since you're forcing it off-centre with the padding.
If you amend the padding to: padding: 0.5em 1em; (0.5em top and bottom, 1em left and right) then it can be centred.
#nav-menu {
font-family: Verdana, Arial, Helvetica, sans-serif;
height: 30px;
background-image: url(../img/menu_bg.png);
background-repeat: repeat-x;
border-bottom: dotted thin #666666;
border-top: dotted thin #666666;
text-align: center;
width: 800px;
}
#nav-menu ul {
list-style: none;
padding: 0;
margin: auto 0;
}
#nav-menu li {
float: left;
border-right: dotted thin #666666;
list-style: none;
padding: 0.5em 1em;
}
#nav-menu li a {
line-height: 1.5em;
color: #333333;
text-decoration: none;
font-size: 12px;
font-weight: bold;
display: block;
}
<div id="nav-menu">
<ul>
<li class="current_page_item">Home</li>
<li class="current_page_item">Home</li>
<li class="current_page_item">Home</li>
<li class="current_page_item">zxczczxczHome</li>
</ul>
</div>
JSFiddle demo of the above.
If you want various sizes, then change the right or left padding property to be the same as the other one:
padding: 0.5em 2em 0.5em 2em;
or
padding: 0.5em 0.75em 0.5em 0.75em;
I've fiddled around with it a little: http://jsfiddle.net/Q32hn/
Don't forget to always close your ListItems

How to make a css navigation menu "selected" option still clickable

So I have a fairly simple vertical CSS menu based off of UL.
<ul class="vertnav">
<li>Item1</li>
<li>Item2</li>
<li>Selected</li>
</ul>
I want three basic colors (say tan for default LI, orange for VERTNAVDOWN, and red for A:HOVER. However I can't seem to get the vertnavdown class to inherit right, and the .vertnav li a:visited overrides it every time. if I use !important to force it through I can't seem to also get the hover to work.
Any suggestions? I thought I understood inheritance in CSS but I guess I don't.
.vertnav{
list-style: none;
margin: 0px;
width: 172px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
text-align: left;
height: 45px;
}
.vertnav li{
margin: 0px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
border-bottom: 0px none;
border-right: 0px none;
border-top: 1px solid #fff;
border-left: 0px none;
text-align: left;
height: 45px;
width: 172px;
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
}
.vertnav li a{
display: block;
text-align: left;
color: #666666;
font-weight: bold;
background-color: #FFEEC1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
text-decoration: none;
padding-top: 10px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 15px;
height: 45px;
}
.vertnav li a:visited{
display: block;
text-align: left;
color: #666666;
background-color: #FFEEC1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
text-decoration: none;
padding-top: 10px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 15px;
height: 45px;
}
.vertnav li a:hover{
color: white;
background-color: #ffbf0c;
font-family: Verdana, Arial, Helvetica, sans-serif;
height: 45px;
text-decoration: none;
font-weight: bold;
}
.vertnavdown a
{
display:block;
color: #FFF;
background-color: #ff9000;
}
.vertnavdown a:hover
{
background-color: #ffbf0c;
}
^^^^^^^^^^^^^ Edited to add CSS. ^^^^^^
It would help if you could post the css as well.
What you normally need is something like this
<ul id="nav">
<li><a>one</a></li>
<li class="active"><a>two</a></li>
</ul>
the css would be:
#nav li{
color: red;
}
#nav li a:visited{
color: green;
}
#nav li.active a{
color: blue;
}
you need to be more specific with the active css naming.
.vertnav li a:visited is very specific, and in CSS, more specific overrides less specific, even if the less specific CSS comes later in the inheritance chain.
.vertnavdown on it's own will always be overridden by .vertnav li a:visited -- the best solution is to be more specific with your description of .vertnavdown.
Changing .vertnavdown a and .vertnavdown a:hover to
.vertnav ul li a.vertnavdown .vertnav ul li a.vertnavdown:hover will fix your problem.
EDIT:
Smacks head Apologies, I should have noted that you were trying to fix a problem with the :visited links ... Since you haven't specified a style for a.vertnavdown:visited it inherits the style of .vertnav a:visited.
The solution then is to add a.vertnavdown:visited to whatever style declaration you want it to inherit from. That should fix the problem.
Try with .vertnav li a:visited .vertnavdown

Resources