|
工具版本兼容问题
如果把所有的css都写在html文件里面,一旦样式比较多的时候,就会显得不易维护
这个时候就会选择把所有的css内容,放在一个独立文件里
然后在html中引用该文件
通常这个文件会被命名为style.css
示例
1
:
直接在html里面写样式
示例
2
:
把样式代码写在style.css,并在html中包含它
示例
3
:
css是本地文件 如何包含
");
window.frames["iframe_show497"].document.write(decodeHtml($("textarea#stepcodeTextarea497").val()));
window.frames["iframe_show497"].document.close();
$(window.frames["iframe_show497"]).load(function(){
$("#iframe_show497").height($("#iframe_show497").contents().find("body").height()+showittryitheight);
});
$("#iframe_show497").height($("#iframe_show497").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<style>
.p1{
color:red;
}
.span1{
color:blue;
}
</style>
<p class="p1">红色</p>
<span class="span1">蓝色</span>
<style>
.p1{
color:red;
}
.span1{
color:blue;
}
</style>
<p class="p1">红色</p>
<span class="span1">蓝色</span>
");
window.frames["iframe497"].document.write(decodeHtml(code497));
window.frames["iframe497"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe497"]).load(function(){
$("#iframe497").height($("#iframe497").contents().find("body").height()+showittryitheight);
});
$("#iframe497").height($("#iframe497").contents().find("body").height()+showittryitheight);
alreadyWriteCode497 = code497;
$("#rendering497").hide();
$("#rendered497").show();
}
var tRereshRetry2DemoPanel497 = setInterval(rereshRetry2DemoPanel497,1000);
var binded497 = false;
$("textarea#stepcodeTextarea497").keyup(function(){
if(!binded497){
$(window).bind('beforeunload',function(){
binded497 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code497 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code497!=newCode){
// window.frames["iframe497"].document.write("
");
// window.frames["iframe497"].document.write(decodeHtml($("textarea#stepcodeTextarea497").val()));
// window.frames["iframe497"].document.close();
// $(window.frames["iframe497"]).load(function(){
// $("#iframe497").height($("#iframe497").contents().find("body").height()+showittryitheight);
// });
// code497 = newCode;
// }
});
$(".tryButton497").click(function(){
$("#tryDiv497").show();
$("#stepcodeTextarea497").focus();
$("#stepcodeTextarea497").height(200);
$("#iframe497").height(0);
window.frames["iframe497"].document.write("
");
window.frames["iframe497"].document.write(decodeHtml($("textarea#stepcodeTextarea497").val()));
window.frames["iframe497"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe497"]).load(function(){
$("#iframe497").height($("#iframe497").contents().find("body").height()+showittryitheight);
});
$("#iframe497").height($("#iframe497").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor497.focus();
editor497.setSize(null, "250");
$("#rendering497").hide();
$("#rendered497").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor497 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea497"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor497.on("change",function(doc){
if(!binded497){
$(window).bind('beforeunload',function(){
binded497 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code497 = newCode;
$("textarea#stepcodeTextarea497").val(newCode);
if(alreadyWriteCode497!=code497){
lastModifedTime497 = new Date().getTime();
$("#rendering497").show();
$("#rendered497").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor497 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor497.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv497").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
示例
2
:
把样式代码写在style.css,并在html中包含它
顶
折
创建一个文件叫 style.css其内容为 .p1{ color:red; }
.span1{ color:blue; }
然后在html中包含该文件 <link rel="stylesheet" type="text/css" href="/study/style.css" />
注:style.css文件里, 就不要再使用style标签了
");
window.frames["iframe_show496"].document.write(decodeHtml($("textarea#stepcodeTextarea496").val()));
window.frames["iframe_show496"].document.close();
$(window.frames["iframe_show496"]).load(function(){
$("#iframe_show496").height($("#iframe_show496").contents().find("body").height()+showittryitheight);
});
$("#iframe_show496").height($("#iframe_show496").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<link rel="stylesheet" type="text/css" href="http://127.0.0.1/study/style.css" />
<p class="p1">红色</p>
<span class="span1">蓝色</span>
<link rel="stylesheet" type="text/css" href="http://127.0.0.1/study/style.css" />
<p class="p1">红色</p>
<span class="span1">蓝色</span>
");
window.frames["iframe496"].document.write(decodeHtml(code496));
window.frames["iframe496"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe496"]).load(function(){
$("#iframe496").height($("#iframe496").contents().find("body").height()+showittryitheight);
});
$("#iframe496").height($("#iframe496").contents().find("body").height()+showittryitheight);
alreadyWriteCode496 = code496;
$("#rendering496").hide();
$("#rendered496").show();
}
var tRereshRetry2DemoPanel496 = setInterval(rereshRetry2DemoPanel496,1000);
var binded496 = false;
$("textarea#stepcodeTextarea496").keyup(function(){
if(!binded496){
$(window).bind('beforeunload',function(){
binded496 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code496 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code496!=newCode){
// window.frames["iframe496"].document.write("
");
// window.frames["iframe496"].document.write(decodeHtml($("textarea#stepcodeTextarea496").val()));
// window.frames["iframe496"].document.close();
// $(window.frames["iframe496"]).load(function(){
// $("#iframe496").height($("#iframe496").contents().find("body").height()+showittryitheight);
// });
// code496 = newCode;
// }
});
$(".tryButton496").click(function(){
$("#tryDiv496").show();
$("#stepcodeTextarea496").focus();
$("#stepcodeTextarea496").height(200);
$("#iframe496").height(0);
window.frames["iframe496"].document.write("
");
window.frames["iframe496"].document.write(decodeHtml($("textarea#stepcodeTextarea496").val()));
window.frames["iframe496"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe496"]).load(function(){
$("#iframe496").height($("#iframe496").contents().find("body").height()+showittryitheight);
});
$("#iframe496").height($("#iframe496").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor496.focus();
editor496.setSize(null, "250");
$("#rendering496").hide();
$("#rendered496").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor496 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea496"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor496.on("change",function(doc){
if(!binded496){
$(window).bind('beforeunload',function(){
binded496 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code496 = newCode;
$("textarea#stepcodeTextarea496").val(newCode);
if(alreadyWriteCode496!=code496){
lastModifedTime496 = new Date().getTime();
$("#rendering496").show();
$("#rendered496").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor496 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor496.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv496").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
在测试的时候,大家写的css文件都是放在本地的,比如d:/style.css
这时就应该写成
href="file://d:/style.css"
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|