Using css "active tab" technique on single page - php

I'm building a navigation system using jquery scrollto. I have my navigation menu in a separate file (( navigation.php )). It is included in 5 locations on the first page (( 5 different sections w/ text following each )). I'm trying to figure out a way to have the current "tab" highlight'd. I could hard code the navigation in each location to ensure it shows up the correct way, but I'd rather use the phpinclude() method. The other issue is that each "tab" has it's own unique color (( cmykd )). Here is the alpha version of what I'm doing (( when you click && the page slides, the "active tab" still stays grey -- I'd like it to be the corresponding color )).
Hope this all makes sense && thanks in advance !!

Few things first.
You have the same <ul> in multiple places, each with the same id. Same with the multiple <li> elements sharing IDs. This is not only invalid HTML but just a bad practice in general.
Secondly, your document outline is backwards. Your text is in <h2> elements whereas your navigation/headers are in <h3> elements. This is also invalid and a bad practice.
Next, let's talk about rest of the HTML for your navigation bars (which are doubling as section headers) and their content sections. Let's look at new HTML for two of them (Creativity and Minimalism)
<div id="a1" class="section creativity">
<ul class="nav">
<li class="creativity">Creativity</li>
<li class="minimalism">Minimalism</li>
<li class="youthfulness">Youthfulness</li>
<li class="kuler">Kuler</li>
<li class="design">Design</li>
</ul>
<p>Lorem ispum...</p>
</div>
<div id="a2" class="section minimalism">
<ul class="nav">
<li class="creativity">Creativity</li>
<li class="minimalism">Minimalism</li>
<li class="youthfulness">Youthfulness</li>
<li class="kuler">Kuler</li>
<li class="design">Design</li>
</ul>
<p>Lorem ispum...</p>
</div>
The key takeaways here are
Semantic use of elements
Semantic use of class names
No behavior
Next, the CSS changes
div.section ul.nav {
font: 35px 'ChunkFiveRegular', Arial, sans-serif;
letter-spacing: 0;
padding: 0px;
margin: 0px;
border-top: 1px solid black;
border-bottom: 1px solid black;
width:100%;
list-style-type: none;
}
div.section ul.nav li {
display:inline;
padding: 0px;
margin: 0px;
}
div.section p {
font: 36px 'ChunkFiveRegular', Arial, sans-serif;
letter-spacing: 0;
}
div.section.active ul.nav li a {
color: #ddd;
}
a:link {color:#999; text-decoration: none;}
a:visited {color:#999; text-decoration: none;}
a:hover {color:#000; text-decoration: none;}
li.creativity a:hover, div.creativity.active li.creativity a {color:#00ffff !important;}
li.minimalism a:hover, div.minimalism.active li.minimalism a {color:#ff00ff !important;}
li.youthfulness a:hover, div.youthfulness.active li.youthfulness a {color:#ffff00 !important;}
li.kuler a:hover, div.kuler.active li.kuler a {color:#000000 !important;}
li.design a:hover, div.design.active li.design a {color:#666666 !important;}
Key takeaways here are
Semantic use of class names
Inheritance based coloring
And finally, the modification to your jQuery
jQuery.noConflict();
jQuery(function($)
{
$("ul.nav li a").click(function( event )
{
event.preventDefault();
var target = $(this).attr( 'href' );
$.scrollTo(
target.replace( '#', '' )
, { duration: 800
, axis: "y"
, onAfter: function()
{
$( 'div.section.active' ).removeClass( 'active' );
$( target ).addClass( 'active' );
}
}
);
});
$(".return-top").click(function()
{
$.scrollTo("body", {duration: 800, axis:"y"});
});
});
Key takeaways here are
Behavior removed from links is added here
Now relies on CSS classes, not IDs

Once you change your multiple ids to classes (since ids must be unique), you could do something like this:
.a1 .q1 a
{
color: cyan;
}
.a2 .q2 a
{
color: magenta;
}
...

Related

WordPress Custom Menu (3rd Level Nesting Issue)

I've ran into a problem using a custom WordPress menu that I can't seem to solve, so after doing a lot of searching the web & failing to fix this over the past few days, I've decided to see if anybody here on StackOverflow can help.
Please note: I would use a Walker function for this but I'm too far gone with the code right now and the way the design works I'm having to build the menu this way.
My snippet for my dropdown: http://pastebin.com/8Stfs90c (would post but it would crucify the screen).
I’m having trouble with the 3rd level of my dropdown menu. In this image: http://s13.postimg.org/lxhslt0lz/image.png you can see that there’s a <li></li> that I’ve highlighted (Pages, About Me, About Us). The structure is as follows
Pages (Parent)
About Me (Parent: Pages)
About Us (Parent: About Me)
And these are fine, BUT when it goes to the third dropdown, it cuts of the <li> and leaves the rest of the Pages children and puts them into a separate container and not the <li> for Pages.
So it should work like so:
Pages (Parent)
About Me (Parent: Pages)
About Us (Parent: About Me)
Right Sidebar (Parent: Pages)
Left Sidebar (Parent: Pages)
Our Process (Parent: Pages)
And all though it may look like this on the dropdown (visually), as you can see in the code it isn’t represented by this. I think the problem I’m having is the checks I’m doing for closing the </li> is wrong. I’ve had this problem for a few days and I just can't seem to fix it. I was going to post this on the WordPress based forum but it's more of a PHP error than anything else.
Here’s a quick screenshot of me hovering over the elements that should be in Pages: http://s23.postimg.org/ef4ame6m3/image.png - as you see they’re separated from the <li>.
To replicate this what I've done is just created a menu structure in WordPress and used the code that's in the snippet (basically I just pasted it into the index.php file) to show how it's being represented.
I really hope somebody can help with this as it has been driving me mad and put a holt on my project for the past few days.
Apologies for the links above, I would post them directly in (screenshots & code) but I didn't want to take away from the actual problem.
If somebody does manage to provide me with the solution I'd be more than happy to buy you a virtual coffee or two!
Out of curiosity, I could be missing the point, is there a reason why would not want to use wp_nav_menu() to handle all of this?
Ex below would output the correct structure for you to theme as your screenshot if applied in your context?
wp_nav_menu( array( 'container' => 'nav', 'container_class' => 'your-class', 'fallback_cb' => 'wp_page_menu', 'theme_location' => 'primary-menu' ) );
Thanks.
Had a quick look at the code, I suppose line 100-130 are dealing with the third dropdown. Actually whats happening is you already have an ol on line 105, then its again being called through the loop on line 122.
echo "<ol><li><a href='" . $link . "'>" . $t->title . "</a></li></ol>";
I think the problem is on line 128 you have to remove ol from the end and create a new condition just for this.
Sorry if i am not being of any help but its really hard to picture the whole code in mind without seeing it. If you are really stuck send the ftp details in chat and i can have a look.
Hi There try this css code to create multiple Nested menu create.
WP code for menu in header.php
<nav class="photoshoot-menu">
<?php wp_nav_menu(array('theme_location' => 'primary','container' => ' ')); ?>
</nav>
CSS Code Add in your style.
.photoshoot-menu {
float: right;
width: auto;
padding-left: 0px;
padding-right: 0px;
}
.photoshoot-menu ul {
padding-left: 0px;
margin: 0px;
}
.photoshoot-menu > ul li {
display: inline-block;
position: relative;
text-transform: uppercase;
margin: 3px 2px;
position: relative;
}
.photoshoot-menu > ul > li > a {
color: #212121;
display: inline-block;
padding: 8px 20px;
border: 1px solid #4f4f4f;
border-radius: 4px;
}
.photoshoot-menu > ul > li > a:hover,
.photoshoot-menu > ul > li > a:focus,
.photoshoot-menu > ul > li.current_page_item > a {
background-color: #343434;
color: #f45c06;
}
.photoshoot-menu ul ul {
border-radius: 4px;
border: 1px solid #4f4f4f;
background-color: rgba(38, 38, 38, 0.95);
opacity: 0;
position: absolute;
top: 42px;
width: 100%;
min-width: 170px;
z-index: 1;
visibility: hidden;
transition: all 0.5s ease-in-out;
-webkit-transition: all 0.5s ease-in-out;
}
.photoshoot-menu ul li:hover > ul {
opacity: 1;
visibility: visible;
}
.photoshoot-menu ul ul li {
width: 100%;
}
.photoshoot-menu ul ul li a {
display: inline-block;
line-height: 16px;
padding: 5px;
color: #FFF;
width: 100%;
}
.photoshoot-menu ul ul li a:hover,
.photoshoot-menu ul ul li a:focus {
color: #f45c06;
}
.photoshoot-menu ul ul ul {
left: 99%;
top: 0px;
}
<nav class="photoshoot-menu">
<ul class="menu" id="menu-all-pages">
<li>Home
</li>
<li>Level 1
<ul>
<li>Level 2
<ul>
<li>Level 3
<ul>
<li>Lorem Ipsum
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>Sample Page
</li>
</ul>
</nav>

CSS id is passing to the rest of the website

I´m trying to do a navigation menu on a website and for some reason what i defined in the id topnav_ubid is getting applied to the rest of the site, especially on a:link and a:visited. I just wanted the style to be applied to the menu. I tried wraping inside a div but still no luck. What's wrong with my code? Can someone help?
I defined this on my style.css
#topnav_ubid ul li {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
#topnav_ubid li {
float: left;
}
#topnav_ubid a:link, a:visited {
display: block;
width: 85px;
height: 20px;
font-weight: bold;
color: #FFFFFF;
background-color: orange;
text-align: center;
padding: 4px;
text-decoration: none;
text-transform: uppercase;
}
#topnav_ubid a:hover, a:active {
background-color: #7A991A;
And had this in HTML:
<div id="topnav_ubid">
<ul>
<li><? print $MSG_501; ?></li>
<?php
if($_SESSION["BPLowbidAuction_LOGGED_IN"]) {
/* user is logged in, give link to edit data or log out */
?>
<li class="<?=$user_menu_style;?>"><? print $MSG_622; ?></li>
<li><? print $MSG_245; ?></li>
<?php
} else {
/* user not logged in, give link to register or login */
?>
<li class="<?=$user_login_style;?>"><? print $MSG_259; ?></li>
<?php
}
?>
<li><? echo $MSG_5085 ;?></li>
<li><? echo $MSG_31_0048; ?></li>
<li> <? print $MSG_164; ?></li>
</ul>
</div>
#topnav_ubid a:link, a:visited { actually are two selectors: #topnav_ubid a:link and a:visited. The second one applies to every visited link, regardless of its parent.
I think you meant this to be #topnav_ubid a:link, #topnav_ubid a:visited {. The same mistake is made in the next selector: #topnav_ubid a:hover, a:active.
I usually add a break after a comma in a list of selectors, so it would be written as:
#topnav_ubid a:link,
#topnav_ubid a:visited {
That way, it's much easier to instantly see all the selectors and you are less likely to make this mistake.
Also note, that in your developer tools (F12) in your browser, you can inspect which styles are applied and which selector caused that. That should help you find any invalid selectors pretty easily.

MPDF57 CSS3 list-style:none not being applied (or isn't supported) for <UL> items inside <TD> element

I would like to clear list-style-type:circle; from the generated PDF (using MPDF57). I've read the CSS3 Docs (and according to the documentation, list-style:none; is supported), but during the Output() stage of creating a PDF file, the circle can seen.
HTML OUTPUT
(source: iforce.co.nz)
Border is to only emphasize, which elements are being targeted.
PDF OUTPUT
(source: iforce.co.nz)
CSS (HTML available via PasteBin).
.schedule_logo_con img {
width: 300px;
height: auto;
}
.daily_schedule { font-family: helvetica, sans serif }
.schedule {
font-family: helvetica, sans serif;
margin: 0px !important;
padding-bottom: 10px;
}
.schedule_list { margin: 10px 0 0 0 }
ul {
margin: 0;
padding: 0;
}
.weekday {
width: 65px;
text-align: center;
border-left: solid #ddd 1px;
color: red;
}
.weekday ul li {
border: 1px solid red;
}
ul, .weekday ul, .weekday ul li {
list-style-type: none;
}
I've also tried list-style-type:none; (In addition too checking MPDF56 to see whether it is something with MPDF57), but regardless this style is not being applied.
For now, it seems to be a rendition problem, from the library itself
<UL> with no parents
But, the above CSS does work, if the UL element is being generated on its own, and not as a child of a another element.
<ul>
<li>Test A</li>
<li>Test B</li>
</ul>
PDF OUTPUT
(source: iforce.co.nz)
Solution
Therefore, the designer and I have a found a work around, using divs and replicating a list with display:block;, although if someone is able to figure out a solution for <UL>, without high server load (That would be great too).
CSS
div.weekday_time {
display:block;
}
HTML
<div class='weekday_time'>
10:30 PM
</div>

Exclude the last divider off a loop of 5 items?

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

New line (in the code) after <li> element breaking layout

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
}

Categories