CSS Image swap issue

This is a discussion on "CSS Image swap issue" within the Web Page Design section. This forum, and the thread "CSS Image swap issue are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 10th, 2006, 08:45
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
CSS Image swap issue

Hi chaps / chappettes

I'm hoping you guys can help me as im not entirley sure how to go about this.

For reference, the website in question is http://cbmgroup.co.uk

As you will probably notice i have a javascript based navigation system....... i dont like this for two reasons .... 1) its messy & 2) it takes ages to make any significant changes to.

I could f course put it into an external javascript file.... but..... i dont want to

I want to change the navigation bar so that it uses a css image swap instead of javascript.

Ive dont this before for navigation systems, but in this cas i need to swap a different immage for each link .... do u therefor need to cretae a whole set of css rules for each button.... ??

Also, i'd like to use text instead of "graphical text" on the links, and have the immages swap in the background ......... but, when i try this the immages get distorted and squished as though they cant fit in the space the text allows.......... any idea's?
Reply With Quote

  #2 (permalink)  
Old Oct 10th, 2006, 13:16
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,711
Blog Entries: 1
Thanks: 0
Thanked 16 Times in 16 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: CSS Image swap issue

Use a single image for both button states for each button. Use CSS background positioning.

For example say you have an image button 25px x 25px. You would make a single graphic that was 25px wide by 50px tall with both states in one image file.

#foobutton a {
width:25px;
height:25px;
display:block;
text-decoration:none;
background:#fff url("foo.jpg") 0px 0px no-repeat;
}

#foobutton a:hover {
background:#fff url("foo.jpg") 0px -50px no-repeat;
}
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)

Last edited by moojoo; Oct 10th, 2006 at 14:24.
Reply With Quote
  #3 (permalink)  
Old Oct 10th, 2006, 14:00
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS Image swap issue

Im not sure i understand what your saying?

Is there anyway you could explain this more clearly please?



Thanks
Reply With Quote
  #4 (permalink)  
Old Oct 10th, 2006, 14:02
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,711
Blog Entries: 1
Thanks: 0
Thanked 16 Times in 16 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: CSS Image swap issue

Every button would be a single graphic with both normal and hover states. You obtain the desired effect by positining the graphic based on normal link state and link hover state. So in effect you get the same result as two images but with a single image load. Cuts the amount of files in half, increases load times, elimintaes IE flicker bug.
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #5 (permalink)  
Old Oct 10th, 2006, 14:02
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS Image swap issue

Hang on !! ........ your talking about a film strip effect

All the css does is tells the immage to reposition itself upwards by 25 pixels right??

Isnt there a problem with the rest of the immage showing where you dont want it to??
Reply With Quote
  #6 (permalink)  
Old Oct 10th, 2006, 14:05
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,711
Blog Entries: 1
Thanks: 0
Thanked 16 Times in 16 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: CSS Image swap issue

No, you define the width and height of the image box to hide the overflow. You could also use overflow:hidden; I will whip up an example for you. But yes sort of like a film strip using CSS to switch between frames.
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #7 (permalink)  
Old Oct 10th, 2006, 14:14
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS Image swap issue

ok sounds good to me.......... id also like to find a way to get rid of this silly table that im using to controll the layout of the navbar .......
is there a way of acheiving the same using css? ...

Do i need a seperate div for each image to do what your suggesting?
Reply With Quote
  #8 (permalink)  
Old Oct 10th, 2006, 14:19
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,711
Blog Entries: 1
Thanks: 0
Thanked 16 Times in 16 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: CSS Image swap issue

Here is an example.

http://www.newbeginningsdesign.com/s...ton/index.html
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #9 (permalink)  
Old Oct 10th, 2006, 14:20
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,711
Blog Entries: 1
Thanks: 0
Thanked 16 Times in 16 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: CSS Image swap issue

By defining the width of the navigation area you could use an unordered list. By setting the li a's to the correct dimensions, margins etc they will wrap throughout the nav div 2 per row. That is how I would do it.

Quote:
Originally Posted by Accurax View Post
ok sounds good to me.......... id also like to find a way to get rid of this silly table that im using to controll the layout of the navbar .......
is there a way of acheiving the same using css? ...

Do i need a seperate div for each image to do what your suggesting?
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #10 (permalink)  
Old Oct 10th, 2006, 14:59
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS Image swap issue

Just a little tid-bit. If you're using multiple rollovers with different sizes, you can access them all with one class instead of defining different pixel heights:

Code: Select all
a.flip:hover {
    background-position: 0 100%;
}
Reply With Quote
  #11 (permalink)  
Old Oct 10th, 2006, 15:45
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS Image swap issue

Thanks for that,

However, im having a slightly annoying problem that i could do with another brain to suggest a reason fo if u dont mind.

I've removed those rollover immages from the navbar for the moment, and, i have added a <ul>....</ul> ... the problem is that no matter what i try, poke, fiddle or mess with i cant get the items in the list to line up with the left hand edge of the <div> ....... probably something silly.... but id appreciate you thoughts as allways.
Reply With Quote
  #12 (permalink)  
Old Oct 10th, 2006, 15:49
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,711
Blog Entries: 1
Thanks: 0
Thanked 16 Times in 16 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: CSS Image swap issue

Would help if we could see what you are doing but...

#foo { padding:0; margin:0;}

#foo ul { padding:0; margin:0;}

#foo li { list-style-type:none; }

#foo li a {}

#foo li a:hover {}

<ul id="foo">
<li>Links here</li>
</ul>
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #13 (permalink)  
Old Oct 10th, 2006, 15:55
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS Image swap issue

Thats what i have

heres the code for the acual list :

Code: Select all
  <div id="divLeft">
    <ul id="ulmainnav">
      <li>Accounting Services & Hosted Software</li>
      <li>Payroll Services</li>
      <li>Credit Controll</li>
      <li>Archiving Solutions</li>
      <li>Cost Down Programs</li>
      <li>Quality Systems</li>
      <li>Business Planning</li>
      <li>Search & Selection</li>
      <li>Marketing Solutions</li>
      <li>VOIP Solutions</li>
      </ul>
  </div>
heres the CSS for the Li items in the list, i havnt even started turning them into links yet you see:

Code: Select all
#ulmainnav li {
    list-style-type: none;
    text-align: left;
    padding:0;
    margin:0;
    width: 120px;
}
And heres the CSS for the Div its all contained in:

Code: Select all
#divLeft {
    float: left;
    width: 120px;
    background-color: #C4D0E7;
    line-height: normal;
    clear: right;
}
Thanks again
Reply With Quote
  #14 (permalink)  
Old Oct 10th, 2006, 15:57
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,711
Blog Entries: 1
Thanks: 0
Thanked 16 Times in 16 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: CSS Image swap issue

try adding

#ulmainnav ul {
padding:0;
margin:0;
}
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #15 (permalink)  
Old Oct 10th, 2006, 16:14
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS Image swap issue

nope

This is starting to gte to me, i'm looking at the site, and i have to admit that compared to how it was this morning, its infinatly better..... i jsut wish everything would click into place now.

Anything else that could be causeing this?
Reply With Quote
  #16 (permalink)  
Old Oct 10th, 2006, 22:24
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: CSS Image swap issue

I've been having a good look at you code. Could you clarify for me just exactly what you want to line-up where?
Reply With Quote
  #17 (permalink)  
Old Oct 11th, 2006, 07:43
Reputable Member
Join Date: May 2006
Location: Northampton, UK
Posts: 399
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS Image swap issue

I'll try geoff

on the left hand side of my page i have a <div> which is 120px wide and #C4D0E7 , the left hand edge of this <div> (as marked by the edge of the colour) is nicly in line with the left hand edge of my footer, and the left hand edge of my header.

However, when i add a <ul> inside the <div> the individual <li> items do not justify themselves along the left hand edge...... instead the "left justify in the middle"

I'm not sure if there are rules against posting screenshots here, so heres a direct link to an image of the problem... not sure if it will help, but at least u will understand what im prattleing on about.

[img=http://img100.imageshack.us/img100/7515/divproblemqp3.th.jpg]

The above image is just of the <div> that has the problem


thx

Last edited by Accurax; Oct 11th, 2006 at 07:45.
Reply With Quote
  #18 (permalink)  
Old Oct 11th, 2006, 21:48
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: CSS Image swap issue

Put the page somewhere I can see it so I can see the code in action and play with it.
Reply With Quote
  #19 (permalink)  
Old Oct 15th, 2006, 01:39
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS Image swap issue

Here's a different method using just one image for all the links:

http://superfluousbanter.org/archive...trix-reloaded/
Reply With Quote
Reply

Tags
ulmainnav

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] HELP!!! - Image Issue winnard2007 Web Page Design 5 Oct 20th, 2007 19:03
image swap Lelouch JavaScript Forum 4 Sep 18th, 2007 15:54
Text/image swap LorEye Website Planning 2 May 19th, 2007 17:43
swap more than 1 image on hover apos JavaScript Forum 2 May 9th, 2007 17:12
Swap Background Image on Hover Andy K Web Page Design 1 Feb 8th, 2006 15:11


All times are GMT. The time now is 01:19.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43