Php 如何缩短此悬停代码?我如何创建一个css文件来实现多个按钮的设置?
有人为我编写了这段代码,我认为其中有一些不必要的部分 代码如下:Php 如何缩短此悬停代码?我如何创建一个css文件来实现多个按钮的设置?,php,css,hover,Php,Css,Hover,有人为我编写了这段代码,我认为其中有一些不必要的部分 代码如下: <!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>
<!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文件来实现多个设置。就像我的CSS文件中的链接一样:
css几乎和它得到的一样短 由于这将应用于a,因此可以删除游标:pointer 此外,如果使用的是背景图像,则可能不需要边框:1 其他样式看起来是渲染按钮所必需的,即高度、宽度和显示 您也可以像您的另一个示例一样将其涂抹在一起:
.myButton {background: url(/wp-content/themes/cosmicbuddy/_inc/images/see.gif) no-repeat; display: block; height: 22px; width: 22px; margin-left: 5px;}
.myButton:hover {background: url(/wp-content/themes/cosmicbuddy/_inc/images/too.gif) no-repeat;}
对于重用这些样式,您可以执行以下两种操作之一:
将.myButton添加到其他a元素或
向规则添加更多类,例如,.myButton、.otherClass{//css in here}引用另一个a中的.otherClass
css几乎和它得到的一样短 由于这将应用于a,因此可以删除游标:pointer 此外,如果使用的是背景图像,则可能不需要边框:1 其他样式看起来是渲染按钮所必需的,即高度、宽度和显示 您也可以像您的另一个示例一样将其涂抹在一起:
.myButton {background: url(/wp-content/themes/cosmicbuddy/_inc/images/see.gif) no-repeat; display: block; height: 22px; width: 22px; margin-left: 5px;}
.myButton:hover {background: url(/wp-content/themes/cosmicbuddy/_inc/images/too.gif) no-repeat;}
对于重用这些样式,您可以执行以下两种操作之一:
将.myButton添加到其他a元素或
向规则添加更多类,例如,.myButton、.otherClass{//css in here}引用另一个a中的.otherClass
第一段“代码”是一个完整的html页面。如果只需要在页面上添加按钮,此部分将执行以下操作:
<a href="<?php bp_send_public_message_link() ?>" class="myButton"><!--button--></a>
第一段“代码”是一个完整的html页面。如果只需要在页面上添加按钮,此部分将执行以下操作:
<a href="<?php bp_send_public_message_link() ?>" class="myButton"><!--button--></a>
1第一段代码可以缩短吗
如果您非常关心大小,请删除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如何创建一个CSS文件来实现多个设置。就像我的CSS文件中的链接一样:
如果不想将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>
如果未设置href属性,则通常使用光标
1第一段代码可以缩短吗
如果您非常关心大小,请删除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如何创建一个CSS文件来实现多个设置。就像我的CSS文件中的链接一样:
如果不想将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>
如果未设置href属性,则通常使用光标。我的2美分:
使用两种按钮状态创建一个图像a sprite,然后:
.myButton {
background-image: url(/wp-content/themes/cosmicbuddy/_inc/images/see.gif);
display: block;
height: 22px;
width: 22px;
}
.myButton:hover {
background-position: x y;
}
这也将解决悬停链接时的flickring问题
希望这有意义我的两分钱:
使用两种按钮状态创建一个图像a sprite,然后:
.myButton {
background-image: url(/wp-content/themes/cosmicbuddy/_inc/images/see.gif);
display: block;
height: 22px;
width: 22px;
}
.myButton:hover {
background-position: x y;
}
这也将解决悬停链接时的flickring问题
希望这是有意义的您可以使用HTML5并省略一些可选元素、属性和结束斜杠,这将给您留下以下内容:
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>IS THIS THING ON?</title>
<link rel="stylesheet" href="/wp-content/themes/cosmicbuddy/_inc/css/screen.css">
<a href="<?php bp_send_public_message_link() ?>" class="myButton"></a>
至于CSS,我可以在antitoxic和gutierrezalex关于使用相对URL和CSS精灵的评论中添加一点内容,只需通过一个缩微器运行最终代码即可。可以通过删除属性块中的空格和最后分号等内容来减少几个字节。您可以使用HTML5并省略一些可选元素、属性和结束斜杠,这将给您带来以下问题:
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>IS THIS THING ON?</title>
<link rel="stylesheet" href="/wp-content/themes/cosmicbuddy/_inc/css/screen.css">
<a href="<?php bp_send_public_message_link() ?>" class="myButton"></a>
至于CSS,我可以在antitoxic和gutierrezalex关于使用相对URL和CSS精灵的评论中添加一点内容,只需通过一个缩微器运行最终代码即可。可以通过删除属性块中的空格和最后分号等内容来减少几个字节。.myButton{background image:url/wp content/themes/cosmicbuddy/_inc/images/see.gif;display:block;高度:22px;宽度:22px;}。myButton:hover{background position:x y;}我试图通过复制粘贴您提供给userbar.php文件的代码来制作一个sprite。我保持CSS与上面相同。我用photoshop save for web->gif 64无抖动保存了文件,并在文件中的两个图像之间保留了一个小空间。然后我上传了它并参考了这个文件。但由于某些原因,它只显示正常图像,没有悬停。你知道我做错了什么吗?php代码:我试图通过复制粘贴您提供给userbar.php文件的代码来制作一个sprite。我保留了那本书
CSS同上。我用photoshop save for web->gif 64无抖动保存了文件,并在文件中的两个图像之间保留了一个小空间。然后我上传了它并参考了这个文件。但由于某些原因,它只显示正常图像,没有悬停。你知道我做错了什么吗?php代码:.myButton{background image:url/wp content/themes/cosmicbuddy/_inc/images/see.gif;display:block;高度:22px;宽度:22px;}.myButton:hover{background position:xy;}.myButton{background image:url/wp content/themes/cosmicbuddy/_inc/images/see/see.gif;display:block;高度:22px;宽度:22px;}.myButton:hover{背景位置:xy;}我试图通过复制粘贴您提供给userbar.php文件的代码来制作一个精灵。我保持CSS与上面相同。我使用photoshop save for web->gif 64 no抖动保存了该文件,并在文件中的两个图像之间保留了一个小空间。然后我上传了它并引用了该文件。但出于某种原因,它只显示了正常的图像,而没有悬停。你知道我做错了什么吗?php代码:我试图通过复制粘贴你提供给userbar.php文件的代码来制作一个精灵。我保持CSS与上面相同。我使用photoshop save for web->gif 64 no抖动保存了文件,并在文件中的两个图像之间保留了一个小空间。然后我上传了它并参考了文件。B但出于某种原因,它只显示正常的图像,没有悬停。你知道我做错了什么吗?php代码:.myButton{background image:url/wp content/themes/cosmicbuddy/_inc/images/see.gif;display:block;height:22px;width:22px;}。myButton:hover{background position:xy;}