Div+css realizes the Adaptive width button _ Experience Exchange

Source: Internet
Author: User

First look at a picture:

The principle is to use a label and span label to combine a full rounded rectangle with the left and right alignment of the background. And then through the hover label to slide the picture. And all you need is a picture:


OK, look at the code.
Css:
Copy Code code as follows:

*{margin:0; padding:0;}
body{padding:10px; font-size:12px;}
h1{margin:0 padding:10px 0; font-size:14px; font-weight:bold;}
A{background:url (1.gif) left 0; color: #fff; text-decoration:none; height:30px; float:left; cursor:hand; margin:0 5px 0 0;}
A:hover{background:url (1.gif) left-30px;height:30px;}
A span{background:url (1.gif) right 0; padding:7px 8px 7px 0; margin:0 0 0 8px; Float:left; height:16px;}
A:hover Span{background:url (1.gif) right-30px; color: #000; padding:7px 8px 7px 0; margin:0 0 0 8px; height:16px; }

Html:
Copy Code code as follows:

<body>
<a href= "#" ><span> home </span></a>
<a href= "#" ><span> not home </span></a>
<a href= "#" ><span> he may be home </span></a>
<a href= "#" ><span> but he must not be home </span></a>
<a href= "#" ><span> well, that's it. Don't pull that ~</span></a>.
</body>

Demonstrate:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title>css Adaptive Width button </title> <style> *{margin:0; padding:0;} body{padding:10px; font-size:12px;} h1{margin:0 padding:10px 0; font-size:14px; font-weight:bold;} A{background:url (/upload/20071122231110605.gif) left 0; Color: #fff; Text-decoration:none; height:30px; Float:left; Cursor:hand; margin:0 5px 0 0;} A:hover{background:url (/upload/20071122231110605.gif) left-30px;height:30px;} A span{background:url (/upload/20071122231110605.gif) right 0; PADDING:7PX 8px 7px 0; margin:0 0 0 8px; Float:left; height:16px;} A:hover Span{background:url (/upload/20071122231110605.gif) right-30px; color: #000; PADDING:7PX 8px 7px 0; margin:0 0 0 8px; height:16px; } </style> </pead> <body> <p><strong>css Adaptive Width Corner button </strong></p> <span> home </span> <span> not home </ Span> <span> He may be home </span> <span> but he must not be home </span> <span> Okay, just do it. Don't pull that off. ~</span> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.