Exclude the last divider off a loop of 5 items? - php

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

Related

Css :last-child using on Laravel #foreach

On Laravel blade I'm using this code to iterate through a list which is filled by an array:
<ul>
#foreach($prerequisites as $prerequisite)
<li class="pre-course"
style="border-bottom: 1px solid #eee;">
<p>
...
</p>
</li>
#endforeach
</ul>
on this my code each <li> have border-bottom: 1px solid #eee; and i'm trying to remove that on last child with Css by code:
ul li.pre-course:last-child {
border-bottom:none;
}
but it doesn't work and last child have border
I suppose that's due to the inline style overriding the stylesheet CSS. Try to move the "regular" rule from inline to the stylesheet, like this:
<ul>
#foreach($prerequisites as $prerequisite)
<li class="pre-course">
<p>
...
</p>
</li>
#endforeach
</ul>
and CSS:
ul li.pre-course {
border-bottom: 1px solid #eee;
}
ul li.pre-course:last-child {
border-bottom:none;
}
That way :last-child will overwrite the regular CSS rule
ul li:last-child {
border-bottom:none !important;
}
Priority of in-line css is higher
<li class="pre-course">
<p>
...
</p>
</li>
Try this css
ul li.pre-course:not(:last-child) {
border-bottom: 1px solid #eee;
}

Inserting design elements in my WordPress nav menu

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;
}

CSS Drop down menu - moving everything on the page when activated

I have a navigation bar that has been on a site for ages. It works great. Now, I'm trying to add a pull-down effect on one of the navigation items driven by CSS.
The idea is that when you mouse over the 'pull down menu' link below, you'll get a vertical list of additional menu options.
The problem is that when I mouse over the 'pull down menu' link below, the resulting pop down box throws off everything below it. The text line in the div container below it wraps, the banner ad gets shifted down and the page basically loses its form.
Is there a way to make it so that the drop down CSS box overlays over the existing page and doesn't shift all the elements below it?
My navigation row looks like this:
<ul id="navlist">
<li>Home</li>
<li>Products</li>
<li>Services</li>
<li style="float:right">Pull Down Menu
<ul>
<li>Option 1</li><br>
<li>Option 2</li><br>
<li>Option 3</li><br>
</ul>
</li>
</ul>
</div>
//below this I have some other stuff
<div align="center">Here is a line of text about 800 pixles wide</div>
<div align="center">A BANNNER AD GOES HERE</div>
<div align="center">THE BODY OF THE PAGE GOES HERE</div>
Then my CSS looks like this:
ul#navlist {
width: 980px; line-height: 2em;
list-style-type: none;
clear: both;}
ul#navlist li { display: inline; }
ul#navlist li a {float: center;}
ul#navlist li a:hover {color: #fff;}
ul#navlist ul {display: none;}
ul#navlist li:hover > ul {display: block;}
Although the CSS is fine, it is better to restructure it. It would have been better if you had provided a screenshot of the page with the issue. Okay, I have a solution with me. Check the below code, try restructuring the CSS and HTML this way, although the HTML is kind of same.
HTML
<ul class="nav">
<li>
Menu 1
<ul>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
</ul>
</li>
<li>
Menu 2
<ul>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
</ul>
</li>
<li>
Menu 3
<ul>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
</ul>
</li>
</ul>
CSS
* {font-family: "Segoe UI", Tahoma;}
ul.nav {border-bottom: 1px solid #999;}
ul.nav li a {display: block; text-decoration: none; color: #333; padding: 5px; border: 1px solid #fff;}
ul.nav > li:hover {border: 1px solid #666; border-bottom: 1px solid #fff;}
ul.nav li a:hover {background: #ccc; border: 1px solid #999;}
ul.nav > li {display: inline-block; position: relative; border: 1px solid #fff;}
ul.nav > li ul {display: none; position: absolute; left: -1px; width: 150px; border: 1px solid #666; border-top-color: #fff; margin-top: 1px;}
ul.nav > li:hover ul {display: block;}
ul.nav > li ul li {display: block;} /* Vertical Menu */
ul.nav > li ul li {display: inline-block;} /* Horizontal Menu */
Fiddle: http://jsfiddle.net/vMuxA/ (Vertical Menu) http://jsfiddle.net/vMuxA/1/ (Horizontal Menu)
If you wish for the page to not shift down when you add additional content, you need to use position: absolute. Since there isn't an exact example here I can't give an exact example to show you what I mean.
Instead, here are resources that explain CSS positioning:
http://css-tricks.com/absolute-positioning-inside-relative-positioning/
http://www.impressivewebs.com/absolute-position-css/
Just a quick disclaimer - absolute positioning can be your best friend and worst enemy. Make sure you cross-browser test and know what it is you're trying to accomplish.
As long as your items are absolute positioned and given a top and left value, they will not affect page flow.

Wordpress single page, categories and archives menu current item

I can't get my head around how to do the following.
On my website I have a menu:
Home | About | Skills | Portfolio | Contact
To call the above menu I have the following in my header.php file:
<nav>
<?php wp_nav_menu( $args ); ?>
</nav>
At the moment when the page is active the link's background color changes, here is the CSS and HTML generated:
header ul li a
{
border-radius: 4px;
background-color: transparent;
border: 1px solid transparent;
color: #939393;
margin: 0px;
border-image: initial;
padding-left: 5px;
padding-right: 5px;
padding-top: 3px;
padding-bottom: 3px;
font-size: 18px;
text-decoration: none;
}
header ul li.current-menu-item a,
header ul li a:hover
{
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-o-border-radius: 4px;
-ms-border-radius: 4px;
-khtml-border-radius: 4px;
border-radius: 4px;
background-color: rgba(0, 0, 0, 0.042);
border: 1px solid rgba(0, 0, 0, 0.15);
margin: 0;
border-image: initial;
padding-left: 5px;
padding-right: 5px;
padding-top: 3px;
padding-bottom: 3px;
color: #939393;
}
header ul li.selected {
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-o-border-radius: 4px;
-ms-border-radius: 4px;
-khtml-border-radius: 4px;
border-radius: 4px;
background-color: rgba(0, 0, 0, 0.042);
border: 1px solid rgba(0, 0, 0, 0.15);
margin-top: -3px;
border-image: initial;
padding-left: 0px;
padding-right: 0px;
padding-top: 3px;
padding-bottom: 3px;
color: #939393;
}
Heres the HTML generated:
<nav>
<div class="menu-main-navigation-container"><ul id="menu-main-navigation" class="menu"><li id="menu-item-42" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-42">Home</li>
<li id="menu-item-41" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-41">About</li>
<li id="menu-item-45" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-45">Skills</li>
<li id="menu-item-56" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-56">Portfolio</li>
<li id="menu-item-49" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-49">Contact</li>
<li id="menu-item-52" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-50 current_page_item menu-item-52">Blog</li>
</ul></div>
</nav>
The above works fine, but what I am trying to achieve is when the user clicks on a blog post or archive or selects a category I want the 'Blog' link to remain highlighted with the different colored background-image.
At the moment nothing shows. Is there a function I can use that states all single, and archive pages to highlight the 'blog' anchor?
Don't know if this post is still relavant but I solved a similar problem today in a fairly dynamic manner, without using JavaScript to target a specific ID.
On your body HTML tag, makes sure you use the body_class function, like so:
<body <?php body_class(); ?>>
This tells WordPress to provide some useful CSS-classes that reflects what page you are currently on. For example, if you are currently on an archive page, the body tag will now have an archive CSS class. If you are on a category page, the body tag will have a category class and if you are on a single post page, the body tag will have a single-post class and so on (inspect the element to see what additional classes are provided by WordPress).
Next, you want to give your target menu item a CSS-class on the "Menus" page in the WordPress admin interface (make sure that the "CSS Classes" option is ticked from the "Screen Options" pane). In case of your blog menu item you could probably give it something like menu-item-blog.
Now you can specifically target your "Blog" menu item with CSS when you are on a single post page like so:
body.single-post .menu-item-blog {
/* Your highlight style goes here */
}
Now, I know that this is not a perfect solution as you still have to set custom CSS-classes on individual menu items, but I like that it is possible to achieve from the admin interface and not the code.
I hope this helps!
Here is small php - jquery combination script.
PHP function's of wordpress check if the page is an archive, category or single post page.
Then with help of Jquery we add class "current-menu-item" to li with id "menu-item-52" which is "Blog" li.
Please add below script in header of the wordpress blog.
<?php
if(is_archive() || is_category() || is_single())
{
?>
<script type="text/javascript">
$(document).ready(function(){
$("li#menu-item-52").addClass("current-menu-item");
});
</script>
<?
}
?>

Using css "active tab" technique on single page

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;
}
...

Categories