• 0

[CSS] How do I achieve this effect?


Question

11 answers to this question

Recommended Posts

  • 0
I have the this menu on my site: http://www.stunicholls.com/menu/pro_dropdown_2.html. I am wondering how they achieve the effect when you hover and the Background image will dynamically change width depending on the length of the text.

javascript :)

  • 0

I don't think he meant the menu and all the javascript involved. Just the background-changing during hover.

It goes somewhere along these lines.. (gross oversimplification from the original CSS on the site, but you should get the idea)

a { padding-left: 12px; }
a span { padding-right:12px; }
a:hover { background: url('bg.jpg') top left; }
a:hover span { background: url('bg.jpg') top right; }

<a href="something"><span>Hi There</span></a>

This image might help a bit:

post-69069-1227187599.png

  • 0
I don't think he meant the menu and all the javascript involved. Just the background-changing during hover.

It goes somewhere along these lines.. (gross oversimplification from the original CSS on the site, but you should get the idea)

a { padding-left: 12px; }
a span { padding-right:12px; }
a:hover { background: url('bg.jpg') top left; }
a:hover span { background: url('bg.jpg') top right; }

<a href="something"><span>Hi There</span></a>

This image might help a bit:

(Y) Great answer!

  • 0
There's a pretty good article about this (called the "sliding doors technique") at A List Apart:

http://www.alistapart.com/articles/slidingdoors/

Very similar, but not quite the same. That technique uses two images where the above mentioned one uses only one larger image. Same idea though :)

  • 0
I don't think he meant the menu and all the javascript involved. Just the background-changing during hover.

It goes somewhere along these lines.. (gross oversimplification from the original CSS on the site, but you should get the idea)

a { padding-left: 12px; }
a span { padding-right:12px; }
a:hover { background: url('bg.jpg') top left; }
a:hover span { background: url('bg.jpg') top right; }

<a href="something"><span>Hi There</span></a>

This image might help a bit:

Thanks! That is a very good explanation of the effect I am trying to achieve.

  • 0

I implemented the sliding door effect. It is working great except the hover don't work right yet. The right corner is rounded, but the left one isn't. Any ideas?

post-236909-1228921306.jpg

post-236909-1228921313.jpg

My html markup is:

<div id="headerTabs">
<ul>
<li><a href="#>Home</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Products</a></li>
</ul>
</div>

CSS

#headerTabs {
	background-image:url(bg_tabs.gif);
	Z-INDEX: 10;
	BORDER-BOTTOM: 0px;
	POSITION: relative;
	BORDER-LEFT: 0px;
	PADDING-BOTTOM: 0px;
	PADDING-LEFT: 20px;
	WIDTH: 967px;
	PADDING-RIGHT: 0px;
	HEIGHT: 22px;
	MARGIN-LEFT: auto;
	BORDER-TOP: 0px;
	TOP: -44px;
	MARGIN-RIGHT: auto;
	BORDER-RIGHT: 0px;
	PADDING-TOP: 0px
}
#headerTabs UL {
	BORDER-BOTTOM: 0px;
	BORDER-LEFT: 0px;
	PADDING-BOTTOM: 0px;
	MARGIN: 0px;
	PADDING-LEFT: 0px;
	WIDTH: 987px;
	PADDING-RIGHT: 0px;
	BORDER-TOP: 0px;
	BORDER-RIGHT: 0px;
	PADDING-TOP: 0px
}
#headerTabs LI {
	BORDER-BOTTOM: 0px;
	BORDER-LEFT: 0px;
	PADDING-BOTTOM: 0px;
	MARGIN: 0px 0px 0px 1px;
	PADDING-LEFT: 0px;
	/*WIDTH: 83px;*/
	PADDING-RIGHT: 0px;
	DISPLAY: block;
	BACKGROUND: url(tab_right.gif) #333 no-repeat right top;
	FLOAT: left;
	FONT-SIZE: 18px;
	BORDER-TOP: 0px;
	BORDER-RIGHT: 0px;
	PADDING-TOP: 0px
}

#headerTabs LI:hover {
	BORDER-BOTTOM: 0px;
	BORDER-LEFT: 0px;
	PADDING-BOTTOM: 0px;
	MARGIN: 0px 0px 0px 1px;
	PADDING-LEFT: 0px;
	/*WIDTH: 83px;*/
	PADDING-RIGHT: 0px;
	DISPLAY: block;
	BACKGROUND: url(tab_left_hov.gif) #333 no-repeat left top;
	FLOAT: left;
	FONT-SIZE: 18px;
	BORDER-TOP: 0px;
	BORDER-RIGHT: 0px;
	PADDING-TOP: 0px
}


#headerTabs LI.selected {
	BORDER-BOTTOM: 0px;
	BORDER-LEFT: 0px;
	PADDING-BOTTOM: 0px;
	MARGIN: 0px 0px 0px 1px;
	PADDING-LEFT: 0px;
	/*WIDTH: 83px;*/
	PADDING-RIGHT: 0px;
	DISPLAY: block;
	BACKGROUND: url(tab_right_sel.gif) #333 no-repeat right top;
	FLOAT: left;
	FONT-SIZE: 18px;
	BORDER-TOP: 0px;
	BORDER-RIGHT: 0px;
	PADDING-TOP: 0px
}

#headerTabs LI A {
	TEXT-ALIGN: center;
	PADDING-BOTTOM: 5px;
	PADDING-LEFT: 8px;
	PADDING-RIGHT: 8px;
	DISPLAY: block;
	COLOR: #333;
	FONT-SIZE: 11px;
	FONT-WEIGHT: normal;
	TEXT-DECORATION: none;
	PADDING-TOP: 3px;
	background:url(tab_left.gif) no-repeat left top;

}

#headerTabs LI A:hover {
	TEXT-ALIGN: center;
	PADDING-BOTTOM: 5px;
	PADDING-LEFT: 8px;
	PADDING-RIGHT: 8px;
	DISPLAY: block;
	COLOR: #333;
	FONT-SIZE: 11px;
	FONT-WEIGHT: normal;
	TEXT-DECORATION: none;
	PADDING-TOP: 3px;
	background:url(tab_right_hov.gif) no-repeat right top;

}


#headerTabs .selected A {
	TEXT-ALIGN: center;
	PADDING-BOTTOM: 5px;
	PADDING-LEFT: 8px;
	PADDING-RIGHT: 8px;
	DISPLAY: block;
	COLOR: #fff;
	FONT-SIZE: 11px;
	FONT-WEIGHT: normal;
	TEXT-DECORATION: none;
	PADDING-TOP: 3px;
	background:url(tab_left_sel.gif) no-repeat left top;

}

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • AB Download Manager 1.9.1 by Razvan Serea AB Download Manager is an open-source, feature-rich download manager designed to accelerate downloads, organize files efficiently, and provide seamless control over downloads. With support for multiple connections, resume capability, and an intuitive interface, it enhances the downloading experience for users seeking speed and reliability. The software integrates with various browsers, enabling quick link grabbing and batch downloading. It supports HTTP, HTTPS, and FTP protocols, ensuring broad compatibility with different file sources. Users can schedule downloads, set speed limits, and categorize files automatically for better organization. AB Download Manager is lightweight yet powerful, making it a great alternative to proprietary download managers. Its open-source nature allows developers to contribute, customize, and improve the software as needed. Whether you're downloading large files, managing multiple downloads at once, or seeking an ad-free experience, this tool offers a practical and efficient solution. Key features of AB Download Manager: Multi-Connection Support – Accelerates downloads by splitting files into multiple segments. Resume Capability – Allows paused or interrupted downloads to be resumed without starting over. Batch Downloading – Supports downloading multiple files at once for improved efficiency. Browser Integration – Captures download links directly from browsers for seamless operation. HTTP, HTTPS, and FTP Support – Ensures compatibility with a wide range of file sources. Download Scheduling – Enables users to automate downloads at specific times. Speed Limiting – Lets users control bandwidth usage for optimized performance. File Categorization – Automatically organizes downloaded files into designated folders. User-Friendly Interface – Simple and intuitive design for easy navigation. Cross-Platform Compatibility – Works on multiple operating systems. Ad-Free Experience – No intrusive ads or tracking for a clean user experience. AB Download Manager 1.9.1 changelog: Added An option to customize notification sounds (#1259) Fixed Ongoing notification was laggy on Samsung One UI devices (#1269) Improved Updated Translations Minor UI/UX improvements Download: AB Download Manager 1.9.1 | Portable | ~80.0 MB (Open Source) Download: ARM64 | Portable ARM64 | Android Links: AB Download Manager Website | Github Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • watching him because of the Mr Klinton cat
    • yup dude, ADS on this website are terrible
    • Samsung Galaxy Z Fold 8, Flip 8, Z Fold Wide: Everything you need to know The ONLY thing I need to know is the price, which I know will be way higher than I (and most people) are willing to pay for a phone... so basically nothing here I need to know. PS: Nice job getting that Apple reference to a non-existent and unrevealed product as "competition" in there. Cheque is in the mail.
  • Recent Achievements

    • Week One Done
      rolfus earned a badge
      Week One Done
    • One Month Later
      Leroy Jethro Gibbs earned a badge
      One Month Later
    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
    • One Month Later
      agatameier earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      505
    2. 2
      +Edouard
      196
    3. 3
      PsYcHoKiLLa
      140
    4. 4
      ATLien_0
      90
    5. 5
      Steven P.
      81
  • Tell a friend

    Love Neowin? Tell a friend!