大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> ASP专区 -> Creating CSS Buttons (一)

Creating CSS Buttons (一)

时间: 2021-07-31 作者:daque

introductionbeing 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 buttonsthe 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 buttonsin 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 hereyou 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!

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.