how2j.cn


工具版本兼容问题
css的语法
selector {property: value}
即 选择器{属性:值}

学习css即学些有哪些选择器,哪些属性以及可以使用什么样的值

示例 1 : 选择所有的p元素   
示例 2 : 也可以直接在元素上增加style属性   

示例 1 :

选择所有的p元素

选择所有的p元素,并且设置文字颜色为红色
"); window.frames["iframe_show448"].document.write(decodeHtml($("textarea#stepcodeTextarea448").val())); window.frames["iframe_show448"].document.close(); $(window.frames["iframe_show448"]).load(function(){ $("#iframe_show448").height($("#iframe_show448").contents().find("body").height()+showittryitheight); }); $("#iframe_show448").height($("#iframe_show448").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<style> p{ color:red; } </style> <p>这是一个P</p> <p>这是一个P</p> <p>这是一个P</p> <p>这是一个P</p>
<style>
p{
   color:red;
}
</style>
<p>这是一个P</p>
<p>这是一个P</p>
<p>这是一个P</p>
<p>这是一个P</p>
"); window.frames["iframe448"].document.write(decodeHtml(code448)); window.frames["iframe448"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe448"]).load(function(){ $("#iframe448").height($("#iframe448").contents().find("body").height()+showittryitheight); }); $("#iframe448").height($("#iframe448").contents().find("body").height()+showittryitheight); alreadyWriteCode448 = code448; $("#rendering448").hide(); $("#rendered448").show(); } var tRereshRetry2DemoPanel448 = setInterval(rereshRetry2DemoPanel448,1000); var binded448 = false; $("textarea#stepcodeTextarea448").keyup(function(){ if(!binded448){ $(window).bind('beforeunload',function(){ binded448 = true; return "xxxx"; }); } var newCode = $(this).val() code448 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code448!=newCode){ // window.frames["iframe448"].document.write("
"); // window.frames["iframe448"].document.write(decodeHtml($("textarea#stepcodeTextarea448").val())); // window.frames["iframe448"].document.close(); // $(window.frames["iframe448"]).load(function(){ // $("#iframe448").height($("#iframe448").contents().find("body").height()+showittryitheight); // }); // code448 = newCode; // } }); $(".tryButton448").click(function(){ $("#tryDiv448").show(); $("#stepcodeTextarea448").focus(); $("#stepcodeTextarea448").height(200); $("#iframe448").height(0); window.frames["iframe448"].document.write("
"); window.frames["iframe448"].document.write(decodeHtml($("textarea#stepcodeTextarea448").val())); window.frames["iframe448"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe448"]).load(function(){ $("#iframe448").height($("#iframe448").contents().find("body").height()+showittryitheight); }); $("#iframe448").height($("#iframe448").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor448.focus(); editor448.setSize(null, "250"); $("#rendering448").hide(); $("#rendered448").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 editor448 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea448"), { 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); } } }); editor448.on("change",function(doc){ if(!binded448){ $(window).bind('beforeunload',function(){ binded448 = true; return "xxxx"; }); } var newCode = doc.getValue(); code448 = newCode; $("textarea#stepcodeTextarea448").val(newCode); if(alreadyWriteCode448!=code448){ lastModifedTime448 = new Date().getTime(); $("#rendering448").show(); $("#rendered448").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor448 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor448.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv448").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果
示例 2 :

也可以直接在元素上增加style属性

直接在某一个元素上增加style属性即可达到css一样的效果
"); window.frames["iframe_show495"].document.write(decodeHtml($("textarea#stepcodeTextarea495").val())); window.frames["iframe_show495"].document.close(); $(window.frames["iframe_show495"]).load(function(){ $("#iframe_show495").height($("#iframe_show495").contents().find("body").height()+showittryitheight); }); $("#iframe_show495").height($("#iframe_show495").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<p style="color:red">这是style为红色的</p> <p>这是一个没有style的p</p>
<p style="color:red">这是style为红色的</p>
<p>这是一个没有style的p</p>
"); window.frames["iframe495"].document.write(decodeHtml(code495)); window.frames["iframe495"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe495"]).load(function(){ $("#iframe495").height($("#iframe495").contents().find("body").height()+showittryitheight); }); $("#iframe495").height($("#iframe495").contents().find("body").height()+showittryitheight); alreadyWriteCode495 = code495; $("#rendering495").hide(); $("#rendered495").show(); } var tRereshRetry2DemoPanel495 = setInterval(rereshRetry2DemoPanel495,1000); var binded495 = false; $("textarea#stepcodeTextarea495").keyup(function(){ if(!binded495){ $(window).bind('beforeunload',function(){ binded495 = true; return "xxxx"; }); } var newCode = $(this).val() code495 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code495!=newCode){ // window.frames["iframe495"].document.write("
"); // window.frames["iframe495"].document.write(decodeHtml($("textarea#stepcodeTextarea495").val())); // window.frames["iframe495"].document.close(); // $(window.frames["iframe495"]).load(function(){ // $("#iframe495").height($("#iframe495").contents().find("body").height()+showittryitheight); // }); // code495 = newCode; // } }); $(".tryButton495").click(function(){ $("#tryDiv495").show(); $("#stepcodeTextarea495").focus(); $("#stepcodeTextarea495").height(200); $("#iframe495").height(0); window.frames["iframe495"].document.write("
"); window.frames["iframe495"].document.write(decodeHtml($("textarea#stepcodeTextarea495").val())); window.frames["iframe495"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe495"]).load(function(){ $("#iframe495").height($("#iframe495").contents().find("body").height()+showittryitheight); }); $("#iframe495").height($("#iframe495").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor495.focus(); editor495.setSize(null, "250"); $("#rendering495").hide(); $("#rendered495").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 editor495 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea495"), { 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); } } }); editor495.on("change",function(doc){ if(!binded495){ $(window).bind('beforeunload',function(){ binded495 = true; return "xxxx"; }); } var newCode = doc.getValue(); code495 = newCode; $("textarea#stepcodeTextarea495").val(newCode); if(alreadyWriteCode495!=code495){ lastModifedTime495 = new Date().getTime(); $("#rendering495").show(); $("#rendered495").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor495 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor495.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv495").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


源代码
1. 双击选中单词 2. 三击选中整行 3. CTRL+F 查找 4. F8 全屏编辑,再次点击恢复
渲染中 渲染完成
效果


HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。


关于 前端部分-CSS-语法 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 620943819
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: http://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图