- 热门文章:
- · Creating CSS Buttons (二)
- · 用javascript实现浮点数的截取小数位数,并四舍五入
- · three trim function(javascript)
- · 用ASP将javascript代码写入客户端执行的一种简易方法。。。
- · Trim Function in javascript
- · java分页源码
- · 过滤表格中的链接(用javascript提取表格中的数据)
- · 来看看哟.一个天气预报的小偷.可以偷到每天更新的全国24小时城市天气预报.
- · 一个把WORD转换成HTML的程序
- · 饮水思源,我从这里学到的知识投入应用,现在再奉献回给大家(可编辑页面的部分属性)
- · 用 WSH 想ASP 一样 查询数据库!(WSH 学习心得2)
- · 一段窗口自动关闭的源代码,不受js打开的限制,与大家共享!
上一篇:台湾的两篇文章,看看也好:唯讀的表單文字輸入項 >>
Creating CSS Buttons (一)
Being able to successfully navigate a Web site is an important metric in measuring a site@#s usability. To assist with navigation, many Web sites use graphical buttons (usually GIF files). While these buttons are not terribly difficult to create with a decent image editor, they can be a bit burdensome when all you have at your disposal is Microsoft Paint. Furthermore, while graphical buttons do not add that much size to the page, the bandwidth requirements do add up, resulting in slower loading pages for your users.
One solution is to use cascading style sheets (CSS) to create buttons. Using CSS, you can create buttons with just a few lines of plain text HTML and CSS tags! (To learn more about CSS, be sure to check out these links.) The downside of using CSS to generate buttons is that the buttons look less professional (in my opinion) and that they can only be rendered on CSS-compliant browsers. For the examples we@#ll be looking at in this article, they are functional in both IE 5.0+ and Netscape 6.1+. Certain "extra" features, which we@#ll be sure to note, only work in IE.
Creating CSS Buttons
The idea for creating CSS buttons was shamelessly borrowed from the book: Web Design: The Complete Reference. This book presented some code that could be used to generate a button using style sheets. The below code shows a simple example:
<% @# Define the stylesheet %>
<STYLE TYPE="text/css">
<!--
#mybutton {border-style: inset;
border-color: #ff6633;
background-color: #CC3300;
text-decoration: none;
width: 80px;
text-align: center;}
A.buttontext {color: white;
text-decoration: none;
font: bold 12pt Verdana;
cursor: hand;}
-->
</STYLE>
<% @# Create the button %>
<A HREF="http://www.yahoo.com/" CLASS="buttontext">
<DIV ID="mybutton">
Yahoo!
</DIV></A>
Here you can see the above code in action. Go ahead and click the button, if you like, you@#ll be instantly wisked away to Yahoo!:
Yahoo
Creating Responsive Buttons
In the above example we used two style sheet items: a mybutton ID and a buttontext class for use in the A tag. Let@#s create a new class, buttonover, that can be used to highlight the color of the button when the mouse is over it. (Note that this feature will only work in Internet Explorer.)
To accomplish this, first create another class in the style tag:
<% @# Define the stylesheet %>
<STYLE TYPE="text/css">
<!--
#mybutton {border-style: inset;
border-color: #ff6633;
background-color: #CC3300;
text-decoration: none;
width: 80px;
text-align: center;}
A.buttontext {color: white;
text-decoration: none;
font: bold 12pt Verdana;
cursor: hand;}
.buttonover {color: yellow;
text-decoration: none;
font: bold 12pt Verdana;
cursor: hand;}
-->
</STYLE>
We want our button to use this new class when the mouse is moved over the button, and to use the buttontext class when the mouse leaves the button. Therefore, we@#ll use the onMouseOver and onMouseOut events for the A tag:
<A HREF="http://www.yahoo.com/" CLASS="buttontext"
onMouseOver="this.className=@#buttonover@#;"
onMouseOut="this.className=@#buttontext@#;">
<DIV ID="mybutton">
Yahoo
</DIV></A>
Below you can see a live demo of this. If you are using IE, go ahead and move your mouse over the button. Neat, eh?
Yahoo
Where to Go from Here
You may be wondering why in the world there@#s a CSS article here on 4Guys, and how this relates to ASP. Well, obviously it doesn@#t... yet. I decided to write this article for two reasons: one, I think it is neat, espcially since I don@#t have any fancy-shmancy image editors to create professional looking buttons; second, I will tie this into ASP in a future article. If you@#re at all like me, then you love ASP and server-side programming, but client-side programming and HTML really ain@#t your thang. So, to compensate for this, I@#ve created a VBScript class that generates all of the needed style sheets and HTML for generating buttons. Using the class is simple: specify the name of the button, its UI elements (background color, font information, width, etc.), the text of the button, and the URL the button should lead to when clicked, and the class automagically generates all the needed CSS and HTML markup. For more information on this class, be sure to read: A CSS Button Creation Class.
Happy Programming!
下一篇:Creating CSS Buttons (二) >>
相关文章:
- · 带进度条的关闭窗口,绝对有用!并可根据需要改写。
- · 一组javascript绘图函数
- · 限制只能中文输入的方法。(详细讲解,对象初学者)
- · 一般的页面滚动条是在右边的,想让他在左边吗:)
- · 确认是否关闭浏览器或转到其它页面(javascript)(做聊天室或在线人数的时候可以用上)
- · <body onkeypress=alert(event.keyCode)>请按任意键,你将得到该键的键值!(转)
- · 利用cookie收藏网站
- · 转贴一个扫雷游戏脚本
- · 动态按钮生成器(上)
- · 用Cookie实现仅弹出一次窗口(javascript)(转)
- · 动态按钮生成器(下)
- · 一全很经典的堆积演示程序(javascript)(转)
- · 一个很酷的程序javascript做的MID歌曲搜索播放器[IE](JS)_(转)
- · 一个查看ASP的javascript程序,方便大家学习ASP程序(JS)_转
- · 长串连续英文字符自动回行的方法(转)
- · 如何修复被修改的IE(1)
- · 如何修复被修改的IE(2)
- · 鼠标右键绝对禁止法
- · 改变浏览器的标题和加入收藏夹的js文件!
- · 零点的网页真黑!!
- · 超级Mailto功能
- · javascript的history对象
- · 又一个给浏览器的滚动条加上颜色的方法(转)
- · 动态计算还能够输入多少字节的表单(纯script,请吧昨天的精华替换成这个吧,那个中文也算1字节
- · 动态计算还能够输入多少字节的表单代码^O^(申请入精华)
- · Vbscript教程一
- · vbscript教程三
- · vbscript教程四-常量
- · vbscript教程五-使用条件语句
- · vbscript教程六-循环语句
- · VBScript教程七-过程
- · VBScript教程九-页面
- · VBScript教程八-编码
- · VBScript 与窗体(十)
- · VBScript 中使用对象(十一)
- · VBScript错误信息列表
- · javascript[对象.属性]集锦(建议加入精华区)
- · 介绍一个判断plug-ins/ActiveX 是否存在的例子
