Creating CSS Buttons (二)

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

下面图老师小编要跟大家分享Creating CSS Buttons (二),简单的过程中其实暗藏玄机,还是要细心学习,喜欢还请记得收藏哦!

【 tulaoshi.com - Web开发 】

  A CSS Button Creation Class

Introduction
In an earlier article, Creating CSS Buttons, I examined how to create graphical-appearing buttons using nothing but HTML and CSS. While this approach is fairly simple to implement - just add a few style tags and a suitable HREF and DIV tag - it is a bit mundane to have to do for each and every button, especially since you need to have a unique set of style classes and IDs for each unique button. (If you are thoroughly confused by this point, be sure you''ve read the Creating CSS Buttons article before delving into this one...) In this article we will examine a small, but handy class to help automate the process of creating CSS buttons. Furthermore, when using a class we''ll be creating and placing buttons much like you would in a VB project. (For more information on creating and using classes in VBScript, be sure to read Mark Lidstone''s Excellent article: Using Classes within VBScript!)

Determining the Class Properties
The first step in creating our CSS button creating class is to decide what properties makeup a CSS button. While there is literally no limit to the number of properties one could conceivably attribute to a button, for this article I am going to assume that this set of properties conveys the basic features one would like to have in a button:

CSSButton Class Properties
Name Uniquely identifies each button.
BackColor Specifies the background color of the button.
BorderColor Specifies the color of the button''s border.
Font The font to use for the button''s label. Must be in the format: style size font-name, such as: bold 12pt arial.
FontColor The color of the font when the button is not selected.
Width The width of the button.
Text The text to display on the button.
Url The Url to take the user to when the click the button.
MouseOverColor The color to make the font when the user''s mouse moves over the button.
This will only work for visitors using IE...

These properties describe each button. Realize that you must use a unique Name for each independent button you want on a given Web page. If you create multiple buttons with the same name, when you mouse over one button, all of those buttons will highlight.

Creating the Class Methods
Now that we''ve looked at the properties for the CSSButton class, let''s examine the two methods we''ll need: GenerateStyleTag() and GenerateButtonTag(). Since each CSS button needs its own classes/IDs declared in a STYLE tag, and, additionally, needs an HREF/DIV section to display the button, these two methods return the applicable STYLE tag and HTML. These methods are very simple, and can be seen below:

Public Function GenerateStyleTag()
  ''Create the STYLE tag
  Dim strStyle
  strStyle = "STYLE TYPE=""text/CSS""" & vbCrLf & _
        "!--" & vbCrLf & _
        "#mybutton" & Name & "   {border-style: inset; " & vbCrLf & _
        "             border-color: " & BorderColor & ";" & vbCrLf & _
        "             background-color: " & BackColor & ";" & vbCrLf & _
        "     &nbs

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

CSS教程是:Creating CSS Buttons (二)。p;       width: " & Width & ";" & vbCrLf & _
        "             text-align: center; }" & vbCrLf & vbCrLf & vbCrLf & _
        "A.buttontext" & Name & " {color: " & FontColor & "; " & vbCrLf & _
        "              text-decoration: none; " & vbCrLf & _
        "              font: " & Font & ";" & vbCrLf & _
        "              cursor: hand; }" & vbCrLf & vbCrLf & vbCrLf & _
        ".buttonover" & Name & " {color: " & MouseOverColor & ";" & vbCrLf & _
        "             text-decoration: none; " & vbCrLf & _
        "             font: " & Font & ";" & vbCrLf & _
        "             cursor: hand; }" & vbCrLf & _
        " // --" & vbCrLf & _
        "/STYLE"

  GenerateStyleTag = strStyle
End Function

Public Function GenerateButtonTag()
  Dim strHTML
  strHTML = "a href=../../""" & Url & """ class=""buttontext" & Name & """ " & _
        "onMouseOver=""this.className=''buttonover" & Name & "'';"" " & _
        "onMouseOut=""this.className=''buttontext" & Name & "'';""" & _
        vbCrLf & "div id=""mybutton" & Name & """" & vbCrLf & Text & _
        vbCrLf & "/div/a" & vbCrLf

  GenerateButtonTag = strHTML
End Function

Creating a Button - the Whole Process
Now that we have outlined the properties in our class, along with the two needed methods, let''s examine how we will actually create some buttons on a Web page. The first thing to do is to create an instance of our CSSButton class for each CSS button that we wish to display on the page. (The complete source for the CSSButton class is available in a download at the end of this article.)

A very simple example can be seen below. It creates two buttons, one that links to Yahoo! and one that links to Lycos. (Be sure to try out the live demo!)

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

''... Insert declaration of CSSButton class here ...

Dim btnYahoo, btnLycos
Set btnYahoo = New CSSButton
Set btnLycos = New CSSButton

btnYah

CSS教程是:Creating CSS Buttons (二)。oo.BackColor = "#aaaaaa"
btnYahoo.BorderColor = "#bbbbbb"
btnYahoo.Font = "bold 12pt Verdana"
btnYahoo.FontColor = "black"
btnYahoo.Width = "80px"
btnYahoo.MouseOverColor = "yellow"
btnYahoo.Url = "http://www.yahoo.com/"

来源:https://www.tulaoshi.com/n/20160219/1618073.html

延伸阅读
标签: Web开发
七.控制文字的样式 控制文字的样式包括文字大小写、文字修饰两个部分。 1.文字大小写 文字大小写使网页的设计者不用在输入文字时就完成文字的大小写,而可以在输入完毕后,再根据需要对局部的文字设置大小写。 基本格式如下: text-transform: 参数 参数取值范围: ·uppercase:所有文字大写显示 ·lowercase:所有文字...
  说到CSS,笔者用的最多的还是它的排版和字型设计功能。因为网页嘛,最终还是要做给人家看的,要传递信息给对方的,所以不管怎么说,这种传递形式非常重要,具体说来,也就是字的控制和版面的控制。另外一个很重要的原因就是中文相当难处理,Windows自带的中文字库很少,而中文的美术效果又很难做,远不如英文那么随随便便写几个字...
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As LongConst SM_CMOUSEBUTTONS = 43Const SM_CLEANBOOT = 67Private Sub Form_Load()Dim mode As LongDim NumbButtons As Longmode = GetSystemMetrics(SM_CLEANBOOT)Select Case modeCase 1 Debug.Print "The System is in Safe Mode"...
标签: PS PS教程
1.渐变背景 文件新建,尺寸为800X600像素,72分辨率的文件在颜色面板,设置前景色值#eceff6,背景色值#bec1cc 图像新建填充图层渐变(确定)下拉找到刚才设置的颜色勾上(反向-仿色-与图层对齐) 2.创建和调整圆 用形状工具画3个圆,选择3个圆的图层,回到选择工具然后如下图点击红色部分对齐 ...
自本人教程 发表以来,一直获得各位网友的好评与支持,今天应各位网友的要求,也为了答谢各位网友的支持,本人将推出续篇教程,以加深各位网友对CSS盒子模式的理解。此教程面向读者还是DIV排版入门者,如果你是高手,那就不要浪费自己时间了。 本人这次将讲解一个纵向CSS导航栏实例的制作,在讲解过程中将会延用之前发表教程所讲到的...

经验教程

840

收藏

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