php – 如何缩短此悬停代码?我如何创建一个css文件,实现多个按钮的设置?

有人为我制作了这段代码,我认为其中有一些不必要的内容.

这是代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html 
xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" 
/> <title>IS THIS THING ON?</title> <link rel="stylesheet" 
href="./wp-content/themes/cosmicbuddy/_inc/css/screen.css" 
type="text/css" />
</style>
</head> <body>
<a href="<?php bp_send_public_message_link() ?>" class="myButton"><!-- 
button --></a>
</body> </html>

这也是它引用的CSS文件:

   .myButton {
    background: url(/wp-content/themes/cosmicbuddy/_inc/images/see.gif) no-repeat;
    border: 1;
    cursor: pointer;
    display: block;
    height: 22px;
    width: 22px;
    margin-left: 5px;
    } .myButton:hover {
    background: url(/wp-content/themes/cosmicbuddy/_inc/images/too.gif) no-repeat;
    }

现在我有两个问题:

>第一段代码可以缩短吗?
>如何创建一个CSS文件,对多个这些设置实现设置.就像这个在我的CSS文件中链接:

06002

解决方法:

1 Can the first piece of code shortened?

如果您对尺寸如此关注,请删除<! - button - > HTML评论.

./wp-content/themes/cosmicbuddy/_inc/css/screen.css

是等于:

wp-content/themes/cosmicbuddy/_inc/css/screen.css

保存2个字符:)

在我看来,在CSS文件中,您可以缩短图像的路径.代替:

background: url(/wp-content/themes/cosmicbuddy/_inc/images/see.gif) no-repeat;
...
background: url(/wp-content/themes/cosmicbuddy/_inc/images/too.gif) no-repeat;

使用相对URL:

background: url(../images/see.gif) no-repeat;
...
background: url(../images/too.gif) no-repeat;

2 How can I create a CSS file that implements settings to more than one of these settings. Just like this one does in my CSS file to links:

如果您不想将CSS类添加到每个元素,则必须将它们包装在其他元素中

...
</head> <body>
<div class="buttons">
<a href="<?php bp_send_public_message_link() ?>" ></a>
<div class="buttons"><a href="<?php bp_send_public_message_link() ?>" ></a>
<div class="buttons"><a href="<?php bp_send_public_message_link() ?>" ></a>
<div class="buttons"><a href="<?php bp_send_public_message_link() ?>" ></a>
</div>
</body> </html>

和CSS

.buttons a {
    background: url(../images/see.gif) no-repeat;
    border: 1;
    cursor: pointer;
    display: block;
    height: 22px;
    width: 22px;
    margin-left: 5px;
} 
.buttons a:hover {
    background: url(../images/too.gif) no-repeat;
}

如果未设置href属性,则通常使用光标.

上一篇:不可思议的纯CSS导航栏下划线跟随效果


下一篇:javascript – 带有getElementByClassName的innerHTML不起作用