how2j.cn


工具版本兼容问题
元素内边距
指的是元素里的内容与边框之间的距离
属性:
padding-left: 左内边距
padding-right: 右内边距
padding-top: 上内边距
padding-bottom: 下内边距
padding: 上 右 下 左

示例 1 : 左内边距   
示例 2 : 内边距,写1个和写4个的区别   
示例 3 : 当内边距的值少于4个的时候   

示例 1 :

左内边距

属性:padding-left
值:数字
指的是,元素中的内容,与边框之间的距离
"); window.frames["iframe_show479"].document.write(decodeHtml($("textarea#stepcodeTextarea479").val())); window.frames["iframe_show479"].document.close(); $(window.frames["iframe_show479"]).load(function(){ $("#iframe_show479").height($("#iframe_show479").contents().find("body").height()+showittryitheight); }); $("#iframe_show479").height($("#iframe_show479").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<style> .red{ border:5px solid red; background-color:green; } .pad-left{ border:5px solid red; background-color:green; padding-left:50px; } </style> <span class="red"> 无内边距的span </span><br/> <br/> <span class="pad-left"> 左边距为50的span </span><br/>
<style>
.red{
   border:5px solid red;
   background-color:green;
}

.pad-left{
   border:5px solid red;
   background-color:green;
   padding-left:50px;
}

</style>

<span class="red"> 无内边距的span  </span><br/> <br/>

<span class="pad-left"> 左边距为50的span  </span><br/>

"); window.frames["iframe479"].document.write(decodeHtml(code479)); window.frames["iframe479"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe479"]).load(function(){ $("#iframe479").height($("#iframe479").contents().find("body").height()+showittryitheight); }); $("#iframe479").height($("#iframe479").contents().find("body").height()+showittryitheight); alreadyWriteCode479 = code479; $("#rendering479").hide(); $("#rendered479").show(); } var tRereshRetry2DemoPanel479 = setInterval(rereshRetry2DemoPanel479,1000); var binded479 = false; $("textarea#stepcodeTextarea479").keyup(function(){ if(!binded479){ $(window).bind('beforeunload',function(){ binded479 = true; return "xxxx"; }); } var newCode = $(this).val() code479 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code479!=newCode){ // window.frames["iframe479"].document.write("
"); // window.frames["iframe479"].document.write(decodeHtml($("textarea#stepcodeTextarea479").val())); // window.frames["iframe479"].document.close(); // $(window.frames["iframe479"]).load(function(){ // $("#iframe479").height($("#iframe479").contents().find("body").height()+showittryitheight); // }); // code479 = newCode; // } }); $(".tryButton479").click(function(){ $("#tryDiv479").show(); $("#stepcodeTextarea479").focus(); $("#stepcodeTextarea479").height(200); $("#iframe479").height(0); window.frames["iframe479"].document.write("
"); window.frames["iframe479"].document.write(decodeHtml($("textarea#stepcodeTextarea479").val())); window.frames["iframe479"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe479"]).load(function(){ $("#iframe479").height($("#iframe479").contents().find("body").height()+showittryitheight); }); $("#iframe479").height($("#iframe479").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor479.focus(); editor479.setSize(null, "250"); $("#rendering479").hide(); $("#rendered479").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 editor479 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea479"), { 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); } } }); editor479.on("change",function(doc){ if(!binded479){ $(window).bind('beforeunload',function(){ binded479 = true; return "xxxx"; }); } var newCode = doc.getValue(); code479 = newCode; $("textarea#stepcodeTextarea479").val(newCode); if(alreadyWriteCode479!=code479){ lastModifedTime479 = new Date().getTime(); $("#rendering479").show(); $("#rendered479").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor479 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor479.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv479").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

内边距,写1个和写4个的区别

属性:padding
值:如果只写一个,即四个方向的值
值:如果写四个,即四个方向的值
上 右 下 左,依顺时针的方向依次赋值
"); window.frames["iframe_show480"].document.write(decodeHtml($("textarea#stepcodeTextarea480").val())); window.frames["iframe_show480"].document.close(); $(window.frames["iframe_show480"]).load(function(){ $("#iframe_show480").height($("#iframe_show480").contents().find("body").height()+showittryitheight); }); $("#iframe_show480").height($("#iframe_show480").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<style> .pad-left-one{ border:5px solid red; background-color:green; padding: 20; } .pad-left-four{ border:5px solid red; background-color:green; padding: 10 20 30 40; } </style> <br/> <span class="pad-left-one"> padding:20的span </span> <br/> <br/> <br/> <br/> <span class="pad-left-four"> padding: 10 20 30 40 的span </span> <br/> <br/> <br/> <br/>
<style>
.pad-left-one{
   border:5px solid red;
   background-color:green;
   padding: 20;
}
 
.pad-left-four{
   border:5px solid red;
   background-color:green;
   padding: 10 20 30 40;
}
 
</style>
<br/>
<span class="pad-left-one"> padding:20的span  </span> <br/> <br/> <br/> <br/>
 
<span class="pad-left-four"> 
padding: 10 20 30 40 的span </span> <br/> <br/> <br/> <br/>
"); window.frames["iframe480"].document.write(decodeHtml(code480)); window.frames["iframe480"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe480"]).load(function(){ $("#iframe480").height($("#iframe480").contents().find("body").height()+showittryitheight); }); $("#iframe480").height($("#iframe480").contents().find("body").height()+showittryitheight); alreadyWriteCode480 = code480; $("#rendering480").hide(); $("#rendered480").show(); } var tRereshRetry2DemoPanel480 = setInterval(rereshRetry2DemoPanel480,1000); var binded480 = false; $("textarea#stepcodeTextarea480").keyup(function(){ if(!binded480){ $(window).bind('beforeunload',function(){ binded480 = true; return "xxxx"; }); } var newCode = $(this).val() code480 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code480!=newCode){ // window.frames["iframe480"].document.write("
"); // window.frames["iframe480"].document.write(decodeHtml($("textarea#stepcodeTextarea480").val())); // window.frames["iframe480"].document.close(); // $(window.frames["iframe480"]).load(function(){ // $("#iframe480").height($("#iframe480").contents().find("body").height()+showittryitheight); // }); // code480 = newCode; // } }); $(".tryButton480").click(function(){ $("#tryDiv480").show(); $("#stepcodeTextarea480").focus(); $("#stepcodeTextarea480").height(200); $("#iframe480").height(0); window.frames["iframe480"].document.write("
"); window.frames["iframe480"].document.write(decodeHtml($("textarea#stepcodeTextarea480").val())); window.frames["iframe480"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe480"]).load(function(){ $("#iframe480").height($("#iframe480").contents().find("body").height()+showittryitheight); }); $("#iframe480").height($("#iframe480").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor480.focus(); editor480.setSize(null, "250"); $("#rendering480").hide(); $("#rendered480").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 editor480 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea480"), { 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); } } }); editor480.on("change",function(doc){ if(!binded480){ $(window).bind('beforeunload',function(){ binded480 = true; return "xxxx"; }); } var newCode = doc.getValue(); code480 = newCode; $("textarea#stepcodeTextarea480").val(newCode); if(alreadyWriteCode480!=code480){ lastModifedTime480 = new Date().getTime(); $("#rendering480").show(); $("#rendered480").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor480 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor480.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv480").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

当内边距的值少于4个的时候

如果缺少左内边距的值,则使用右内边距的值。
如果缺少下内边距的值,则使用上内边距的值。
如果缺少右内边距的值,则使用上内边距的值。
举例说明
这是完整4个的
padding: 10 20 40 80
如果只有3个
padding: 10 20 40
那么left取right
padding: 10 20 40 = padding: 10 20 40 20
如果只有两个
padding: 10 20
那么bottom取top,left取right
padding: 10 20 = padding:10 20 10 20
如果只有一个
padding:10
那么right取top,bottom取top,left取top
padding:10 = padding:10 10 10 10
当内边距的值少于4个的时候


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


关于 前端部分-CSS-内边距 的提问

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

上传截图