我刚刚开始学习jQuery和CSS,并且对使用特定jQuery插件 Notify.js 生成的toast / notifications设置样式有疑问。
插件网站上有文档,但我无法正确理解如何限制我的JS文件中有关样式的代码量,而是将其保存在我的外部CSS文件中。看起来你应该能够为CSS类使用正确的命名约定,然后以一种简单的方式进行操作。
所以而不是
$.notify.addStyle('check', {
html : "<div><span data-notify-text/></div>",
classes : {
base : {
"white-space" : "nowrap",
"background-color" : "#cccccc",
"padding" : "5px",
"font-family" : "Comic Sans MS"
},
uncheck : {
"color" : "white",
"background-color" : "#252525"
}
}
});
我想在我的外部CSS文件中使用这样的东西
.notifyjs-check-base {
white-space: nowrap;
background-color: #D3D3D3;/*lightgray*/
padding: 5px;
font-family: Comic Sans MS; }
.notifyjs-check-uncheck{
color: white,
background-color: #252525;}
然后就像
一样$.notify.addStyle('check');
在我的js文件中使用我的通知样式。
所有这些都在Chrome扩展程序中用于向用户显示消息。
你会怎么做?让今天做好事并帮助初学者:)
答案 0 :(得分:1)
如果我理解你的问题,我想你想分开你的javascript和css代码。然后你可以在你的javascript文件中写到这个。
$.notify.addStyle('foo', {
html:
"<div>" +
"<div class='clearfix'>" +
"<div class='title' data-notify-html='title'/>" +
"<div class='buttons'>" +
"<button class='no'>Cancel</button>" +
"<button class='yes' data-notify-text='button'></button>" +
"</div>" +
"</div>" +
"</div>"
});
和外部css文件中的其余css类
.notifyjs-foo-base {
opacity: 1;
width: 200px;
background-color: #DFF0D8;
color:#468847;
border-color:#D6E9C6;
padding: 5px;
border-radius: 10px;
font-weight:bold;
}
.notifyjs-foo-base .title {
width: 100px;
float: left;
margin: 10px 0 0 10px;
text-align: right;
}
.notifyjs-foo-base .buttons {
width: 70px;
float: right;
font-size: 9px;
padding: 5px;
margin: 2px;
}
.notifyjs-foo-base button {
font-size: 9px;
padding: 5px;
margin: 2px;
width: 60px;
}