I am having issues with this bit of CSS and I can't seem to find it out.
I have a bit of PHP:
<ul>
<?php if($page=="home"){echo"<li class='active'>";}else{echo"<li>";}?>Home</li>
<?php if($page=="about"){echo"<li class='active'>";}else{echo"<li>";}?><li>About</li>
<?php if($page=="contact"){echo"<li class='active'>";}else{echo"<li>";}?><li>Contact</li>
<?php if($page=="projects"){echo"<li class='active'>";}else{echo"<li>";}?><li>Projects</li>
<?php if($page=="sites"){echo"<li class='active'>";}else{echo"<li>";}?><li>Sites</li>
<?php if($page=="demo"){echo"<li class='active'>";}else{echo"<li>";}?><li>Demo</li>
</ul>
Now, on each page it will define $page. The issue is when a page is active it displays a bar underneath the item. The bar is floating to the right side of the page and the home item is on the far right. If that one is active then it works just fine. When any of the other items are active then the line is to the left. Here is my CSS:
#header {
position:fixed;
background:#222;
color:#999;
width:100%;
margin:0px;
padding:0px;
top:0;
z-index:1;
height:5%;
}
#header ul li{
display: inline;
margin:0;
float:right;
display:block;
padding:5px 10px;
}
#header .active{
border-bottom: solid 3px orange;
}
Right
Wrong
I know it has something to do with the spacing but I just can't figure it out. I'm not a CSS guy.
I am guessing that you are outputting more than the needed <li> tags
<?php if($page=="demo"){echo"<li class='active'>";}else{echo"<li>";}?><li>Demo</li>
this will either output
<li class='active'>
<li>Demo</li>
or
<li>
<li>Demo</li>
So to see if this is the problem use this
<ul>
<?php if($page=="home"){echo"<li class='active'>";}else{echo"<li>";}?>Home</li>
<?php if($page=="about"){echo"<li class='active'>";}else{echo"<li>";}?>About</li>
<?php if($page=="contact"){echo"<li class='active'>";}else{echo"<li>";}?>Contact</li>
<?php if($page=="projects"){echo"<li class='active'>";}else{echo"<li>";}?>Projects</li>
<?php if($page=="sites"){echo"<li class='active'>";}else{echo"<li>";}?>Sites</li>
<?php if($page=="demo"){echo"<li class='active'>";}else{echo"<li>";}?>Demo</li>
</ul>
Related
Hello guys and girls,
I've been given my first WordPress build at work, with freedom on pretty much anything. I chose to use Altitude pro as a theme with Genesis as a framework.
I love the theme but, for a service page the theme is not exactly fantastic. To spice it up a bit, I'd like to create a custom header design for every service page on the site.
This would be a coloured background over the top 1000px of the page or so, that has a solid colour with some patterns on top.
Due to my inexperience though, I'm not really sure on how to do it and my PHP knowledge is not fantastic.
Could anyone please assist?
Thanks!
You can check here for normal headers or even fixed headers. They explain well. http://www.w3schools.com/css/css_navbar.asp
Here is a code that makes a fixed header with menus. If you don't want to make it fixed you can just delete "position: fixed;".
<!DOCTYPE html>
<html>
<head>
<style>
body {margin:0;}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
position: fixed;
top: 0;
width: 100%;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #4CAF50;
}
</style>
</head>
<body>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
<div style="padding:20px;margin-top:30px;background-color:#1abc9c;height:1500px;">
<h1>Fixed Top Navigation Bar</h1>
<h2>Scroll this page to see the effect</h2>
<h2>The navigation bar will stay at the top of the page while scrolling</h2>
</div>
</body>
</html>
The header is being displayed dynamically using php like <?php include 'header.php';
?> and it disappears during print. And also the social media icons change to URLs instead of images.
Couldn't find a possible solution. Please suggest some solutions.
The HTML and CSS for header:
<nav class="navbar navbar-inverse" role="navigation">
<div>
<ul class="nav navbar-nav" >
<li>Add</li>
<li>Edit</li>
<li>Search</li>
<li>List</li>
<li>Pdf</li>
</ul>
</div>
</nav>
<style>
.navbar{
font-family:"Myriad Pro";
background-color:#333;
color:white;
font-size:16px;
text-align: center ;
width:100% !important;
z-index: 10;
}
.navbar-nav{
width: auto !important;
}
.navbar-inverse .navbar-nav>li>a{
color:white;
}
.navbar-inverse .navbar-nav>li:hover{
background-color:#000;
color:black;
}
.nav > li {
display:inline-block !important
}
</style>
There is a high chance your CSS has print styles are too global; especially form your anchors. The CSS you posted does not contain the print CSS. Are you including any 3rd party CSS files? Look for #media print a's. You will see that they probably include the (href)
Hi to everyone and many thanks to all who put out the effort to help me.
Here is my problem, and please bear with me as I'm relatively new to all of this.
I'm trying create a custom WordPress theme for the blog on my site, so that the look and feel of my blog and my site are seamless.
Right now my problem is the nav menu. I have vertical lines separating the nav links and I have been unable to find any examples that show how to do this, or something like it in WordPress and if it's possible can it be done without jQuery.
Here is my site for the visual; http://is-images.com/
If it helps, here is the html code for the menu and the css
<div id="HeaderNav">
<ul>
<li class="link">about</li>
<li class="navsep"> </li>
<li class="link">web</li>
<li class="navsep"> </li>
<li class="link">photo</li>
<li class="navsep"> </li>
<li class="link">blog</li>
<li class="navsep"> </li>
<li class="link">contact</li>
</ul>
</div>
CSS
#HeaderNav
{
display:block;
width:300px;
height:24px;
float:right;
margin-top:70px;
margin-right:37px;
}
#HeaderNav ul
{
position:relative;
display:block;
float:right;
}
#HeaderNav ul li
{
padding:0 4px;
display:block;
height:100%;
float:left;
margin:0 auto;
text-align:center;
}
#HeaderNav ul li.navsep
{
width:1px;
height:24px;
margin:0 7px;
padding:0;
background-color:#ffffff;
}
If anyone can help, in any way, I would greatly appreciate it.
Again, many thanks to all who put out the effort.
If you want to add vertical lines to separate your nav menu options on your wordpress theme you can do it with a few CSS rules. jQuery is not needed.
Here you go:
li.menu-item a {
border-right: 1px solid #fff;
padding-right: 5px;
padding-left: 5px;
}
they have just create an empty element after each menu:
<li class="navsep"> </li>
Then design it with css
#HeaderNav ul li.navsep
{
width:1px;
height:24px;
margin:0 7px;
padding:0;
background-color:#ffffff;
}
My issue is that I have cart section of the website where it automatically picks 5 related products on the right side of the page. I added a bottom-border style so you can tell the difference between each product. The issue here is that there's 4 dividers, or border lines, whatever you wish to call it. However as you can see in the picture below, having the 4th divider is completely redundant since it's already the last item. My question is what code would be necessary to add to take off the last divider to this stylesheet. I only have 1 line of code for the add to cart bottom border since it repeats itself every time a new object is added, and the max is 5 items every time.
I was going to take a picture and upload it directly but apparently you need more points just to post a picture, so I uploaded a picture at imgur until I have enough points. Cheers.
Code:
HTML Page:
<div class="addToCart_bottomBorder"></div>
CSS Page:
.addToCart_bottomBorder {
border-bottom: #d9d9d9 1px solid;
margin-top:3px;
margin-bottom: 5px;
clear:both;
}
.addToCart_bottomBorder li:last-child {
border-bottom: none;
}
Reference pic:
Might have better results using border-top and removing it from the first child :)
IE8 and below, from memory, don't support last-child
.addToCart_bottomBorder li {
border-top: #d9d9d9 1px solid;
margin-top:3px;
margin-bottom: 5px;
clear:both;
}
.addToCart_bottomBorder li:first-child {
border-top: none;
border-bottom: none;
}
and here is the html
<ul class="addToCart_bottomBorder">
<li class="">content</li><br />
<li class="">content</li><br />
<li class="">content</li><br />
<li class="">content</li><br />
<li class="">content</li><br />
</ul>
and a jsFiddle for good measure
edit
Updated code and added a fiddle.
You could use the CSS adjacent sibling selector (+).
Assuming your HTML looks like this:
<div class="addToCart_bottomBorder">
<ul>
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Last</li>
</ul>
</div>
Then the CSS would be:
.addToCart_bottomBorder {
margin-top:3px;
margin-bottom: 5px;
clear:both;
}
.addToCart_bottomBorder li+li {
border-top: #d9d9d9 1px solid;
}
Fiddle: http://jsfiddle.net/M8kN2/
Lets break this down, .addToCart_bottomBorder li:last-child,
.addToCart_bottomBorder This is the parent
li and this is the child
With the following selector you are targeting the li of your parent, .addToCart_bottomBorder, and then removing the border from the last li but since those styles are on the parent you are removing nothing from them.
Without more of your html and css it is hard to tell how you have it structured but this is how it should be structured.
<ul class="pickFive">
<li class="addToCart_bottomBorder">
Some content in here
</li>
<li class="addToCart_bottomBorder">
Some content in here
</li>
<li class="addToCart_bottomBorder">
Some content in here
</li>
<li class="addToCart_bottomBorder">
Some content in here
</li>
<li class="addToCart_bottomBorder">
Some content in here
</li>
</ul>
With this css,
.addToCart_bottomBorder {
border-bottom: #d9d9d9 1px solid;
margin-top:3px;
margin-bottom: 5px;
clear:both;
}
.pickFive li:last-child {
border-bottom: none;
}
If you structure it like so the last child of the parent will have no border. Check this JSFIDDLE to see how it works.
Instead of this
.addToCart_bottomBorder li:last-child {
border-bottom: none;
}
Do This
.addToCart_bottomBorder li:last-child {
border-bottom: #FFFFFF 0px solid;
}
that's how i do it anyways, and it works fine
Weirdly, I've never come across this issue before, but I've just started making a site and the top navigation isn't playing nicely.
I want a small amount of white space between each menu item, but when I have new lines between my <li> elements and my <a> elements in my IDE (Netbeans), the white space disappears, yet it looks fine if I have <li><a></a></li> all on the same line. I was always under the impression html ignored white space in the code.
I've checked for any weird characters causing problems in other text editors and can't find anything.
Here's the code...
Like this the menu looks correct but code looks ugly (I know it looks fine when it's this simple, but I'm going be adding more complexity in which makes it look awful all on one line):
<ul id="menu">
<li>About</li>
<li class="active">Track List</li>
<li>Stats</li>
<li>Stats</li>
</ul>
Produces:
Like this the menu looks wrong but code looks fine:
<ul id="menu">
<li>
About
</li>
<li class="active">
Track List
</li>
<li>
Stats
</li>
<li>
Stats
</li>
</ul>
Produces:
wrong http://img708.imageshack.us/img708/6628/screenshot20100618at000.png
I'm sure it's something simple I'm doing wrong... but can someone shed some light on this for me?
Sorry for the lengthy post (my first on stackoverflow).
Edit - Full CSS and HTML:
body {
/* font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif; */
font-family: 'Trebuchet MS', Helvetica, sans-serif;
/* font-family: 'Copperplate', 'Copperplate Gothic Light', sans-serif; */
}
a {
color: #FFFFFF;
text-decoration: none;
}
#container{
margin: 0 auto;
width: 800px;
}
#content {
margin-top: 50px;
}
#header {
background-image: url("../images/absolute_radio_logo.png");
border-bottom: solid 1px #777777;
background-repeat: no-repeat;
width: 800px;
height: 86px;
padding-bottom: 15px;
}
#menu {
float: right;
}
#menu li {
display: inline;
padding: 5px;
background-color: #932996;
border-bottom: solid 1px #932996;
}
#menu li:hover {
border-bottom: solid 3px #FF0000;
}
#menu li.active {
background-color: #58065e;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Radio - Statistics</title>
<link rel="stylesheet" type="text/css" href="http://localhost/resources/css/style.css" />
</head>
<body>
<div id="container">
<div id="header">
<ul id="menu">
<li>
About
</li>
<li class="active">
Track List
</li>
<li>
Stats
</li>
<li>
Stats
</li>
</ul>
</div>
<div id="content">
<!-- content -->
Elapsed Time: 0.0033 - Memory Used: 0.4MB
</div>
</div>
</body>
</html>
It seems to be totally fine with the CSS you supplied, so I'm guessing there must be some other rule affecting your links. Could you please supply us with a live preview or the full stylesheet?
Edit:
Seems to be an issue with how "display: inline" collapses the elements contents, though I couldn't find any proof of that. Change
#menu li {
display: inline;
}
to
#menu li {
display: inline-block;
}
or add a margin to it:
#menu li {
display: inline;
margin-right: 5px;
}
To fix the alignment of the text, I'll go ahead and recommend you float the lis. Someone please correct me if this is a horrible idea. Add
#menu {
overflow: hidden;
}
#menu li {
float: left;
}
to your existing rules.
Just as a guess try setting the line-height for the li & a tags to 1em or even 0
#menu li, #menu a {
line-height: 1em;
}
Firstly, those two screenshots appear to be swapped around, the first has gaps between the links, caused by the white-space in the second code snippet.
This new white-space-collapse property may be able to help.
#menu li{white-space-collapse:discard}
via: http://safalra.com/web-design/html-and-css/white-space-property/
If that doesn't work, the next option is to set the <a> tags to block level elements and the <li> tags to inline.
#menu li{display:inline}
#menu li a{
display:inline-block
padding: 5px;
background-color: #932996;
border-bottom: solid 1px #932996;
}
#menu li a:hover{
border-bottom: solid 3px #FF0000;
}
#menu li.active a {
background-color: #58065e;
}
so it seems the targeted answer's have all been provided, so I'd just like to add that as a rule of thumb I always use normalize.css which is a css library that ensures normal
you can download it or use npm install normalize.css
You must set overflow: hidden on the parent box, then set position: relative on the <li>:
ul {
margin: 0;
display: flex;
flex-wrap: wrap;
padding: 25px;
margin: 5px 0;
overflow: hidden
}
ul li {
display: inline-block;
padding: 19px 10px;
text-align: center;
position: relative
}
ul li::before {
content: '';
position: absolute;
width: 400%;
height: 1px;
background: #f3f3f3;
bottom: 0;
right: -250px
}