Creating CSS Buttons (一)

2016-02-19 18:32 6 1 收藏

想要天天向上,就要懂得享受学习。图老师为大家推荐Creating CSS Buttons (一),精彩的内容需要你们用心的阅读。还在等什么快点来看看吧!

【 tulaoshi.com - Web开发 】

  Introduction
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.

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)

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!:

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)

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-d

CSS教程是:Creating CSS Buttons (一)。ecoration: 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!

来源:http://www.tulaoshi.com/n/20160219/1618087.html

延伸阅读
        通过在CSS中设置属性,我们可以准确的定义一个页面的样式,如颜色、字体、边框等。现在我们要讲的CSS定位主要是在页面的布局和控制上进行定义,使您的页面从这两个方面都展现的非常完美,更加富有动感。 另外,在讲解之前,我们首先介绍两个定义:相对定位和绝对定位。相对定位就是允许在文档的原始位置上进...
标签: Web开发
译自:Quick Tip: Understanding CSS3 Gradients 中文:理解CSS3渐变 请尊重版权,转载请注明
标签: Web开发
点击这里浏览本站 CSS 频道内容。 一位网友遇到了一个头疼的问题。需要对经过若干次修改以后的网站进行重整,需要剔除冗余的代码,在CSS样式重整方面,比较头疼,不仅需要对现有的样式进行合并与精简,还需要为网站增加换肤功能。 不难看出,这是一个令人感觉很烦躁的工作,面对一行一行代码头皮发麻。如果我们养成良好的习惯,或...
标签: Web开发
Snook.Ca最近给所有的CSSer提出了一些写CSS时候的“顶级技巧”。 字体大小使用px 在一行内声明CSS对比下面两个: 以下是引用片段: h2{font-size:18px;border:1pxsolidblue;color:#000;background-color:#FFF;} h2{ font-size:18px; border:1pxsolidblue; color:#000; background-color:#FFF; }   第二种看起来的确格...
标签: Web开发
按照CSS规范,浮动元素(floats)会被移出文档流,不会影响到块状盒子的布局而只会影响内联盒子(通常是文本)的排列。因此当其高度超出包含容器时,一般父容器不会自动伸长以闭合浮动元素。但是有时我们却需要这种自动闭合行为,具体如何处理呢? 有一种做法就是在父容器内再插入一个额外的标签,并令其清除浮动(clear)以撑大父容...

经验教程

991

收藏

33
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部