how2j.cn

"); window.frames["iframe_toc"+sid].document.write(decodeHtml($("pre#stepCodePre"+sid).html())); window.frames["iframe_toc"+sid].document.close(); $(window.frames["iframe_toc"+sid]).load(function(){ $("#iframe_toc"+sid).height($("#iframe_toc"+sid).contents().find("body").height()+(showittryitheight)); }); $("#iframe_toc"+sid).height($("#iframe_toc"+sid).contents().find("body").height()+(showittryitheight)); } $("input.tocName").hover(function(){ $(this).select(); }); function refresh(){ var sid = tocstepids.shift(); if(null!=sid) refreshIframe(sid); else go2ArchorFlag = true; } var t = setInterval(refresh,300); // $("div.steptoc iframe").height($(showittryitheight+50)); });
效果 说明 示例代码
<!DOCTYPE html>
<script src="http://127.0.0.1/study../../../js/jquery/2.0.0/jquery.min.js"></script>
<link
	href="http://127.0.0.1/study../../../css/bootstrap/3.3.6/bootstrap.min.css"
	rel="stylesheet">
<script
	src="http://127.0.0.1/study../../../js/bootstrap/3.3.6/bootstrap.min.js"></script>

<style>
  
div.container div.row div {
	margin:5px 0px;
	
}
div.container div.row div {
	background-color: lightgray;
	border: 1px solid gray;
	text-align:center;
}
</style>

<div class="container">
	<div class="row">
		<div class="col-xs-12 ">一共12列</div>
	</div>
</div>

<div class="container">
	<div class="row">
		<div class="col-xs-1 ">1列</div>
		<div class="col-xs-1 ">1列</div>
		<div class="col-xs-1 ">1列</div>
		<div class="col-xs-1 ">1列</div>
		<div class="col-xs-1 ">1列</div>
		<div class="col-xs-1 ">1列</div>
		<div class="col-xs-1 ">1列</div>
		<div class="col-xs-1 ">1列</div>
		<div class="col-xs-1 ">1列</div>
		<div class="col-xs-1 ">1列</div>
		<div class="col-xs-1 ">1列</div>
		<div class="col-xs-1 ">1列</div>
	</div>
</div>
<div class="container">
	<div class="row">
		<div class="col-xs-4 ">占4列</div>
		<div class="col-xs-4 ">占4列</div>
		<div class="col-xs-4 ">占4列</div>
	</div>
</div>
栅格系统
示例代码
<!DOCTYPE html>
<script src="http://127.0.0.1/study../../../js/jquery/2.0.0/jquery.min.js"></script>
<link
	href="http://127.0.0.1/study../../../css/bootstrap/3.3.6/bootstrap.min.css"
	rel="stylesheet">
<script
	src="http://127.0.0.1/study../../../js/bootstrap/3.3.6/bootstrap.min.js"></script>

<style>

div.container div.row div {
	margin:5px 0px;
	
}

div.container div.row div {
	background-color: lightgray;
	border: 1px solid gray;
	text-align:center;
}
</style>

<div class="container">
	<div class="row">
		<div class="col-xs-6 ">一半</div>
		<div class="col-xs-6 ">一半</div>
	</div>
</div>
<div class="container">
	<div class="row">
		<div class="col-xs-4 ">1/3</div>
		<div class="col-xs-4 ">1/3</div>
		<div class="col-xs-4 ">1/3</div>
	</div>
</div>
<div class="container">
	<div class="row">
		<div class="col-xs-3 ">1/4</div>
		<div class="col-xs-3 ">1/4</div>
		<div class="col-xs-3 ">1/4</div>
	</div>
</div>
一半,1/3, 1/4
示例代码
<!DOCTYPE html>
<script src="http://127.0.0.1/study../../../js/jquery/2.0.0/jquery.min.js"></script>
<link
    href="http://127.0.0.1/study../../../css/bootstrap/3.3.6/bootstrap.min.css"
    rel="stylesheet">
<script
    src="http://127.0.0.1/study../../../js/bootstrap/3.3.6/bootstrap.min.js"></script>
 
<style>
 
div.container div.row div {
    margin:5px 0px;
     
}
 
div.container div.row div {
    background-color: lightgray;
    border: 1px solid gray;
    text-align:center;
}
</style>
 
<div class="container">
    <div class="row">
        <div class="col-xs-6 ">一半</div>
        <div class="col-xs-6 ">一半</div>
    </div>
</div>

<div class="container">
    <div class="row">
        <div class="col-xs-8 ">8格</div>
        <div class="col-xs-6 ">6格</div>
    </div>
</div>
自动换行
示例代码
步骤 1 : 栅格系统   
步骤 2 : 一半,1/3, 1/4   
步骤 3 : 自动换行   

步骤 1 :

栅格系统

运用Bootstrap的栅格系统,可以做出像table那样定义多少行,多少列效果,但是又比table灵活。
运用Bootstrap的栅格系统,首选需要准备一个class=container的div
紧接着需要一个class=row的 div,表示行
再挨着的div,就是列了。

Bootstrap的栅格系统会默认把一行,分成12列。
"); window.frames["iframe_show3052"].document.write(decodeHtml($("textarea#stepcodeTextarea3052").val())); window.frames["iframe_show3052"].document.close(); $(window.frames["iframe_show3052"]).load(function(){ $("#iframe_show3052").height($("#iframe_show3052").contents().find("body").height()+showittryitheight); }); $("#iframe_show3052").height($("#iframe_show3052").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<!DOCTYPE html> <script src="http://127.0.0.1/study../../../js/jquery/2.0.0/jquery.min.js"></script> <link href="http://127.0.0.1/study../../../css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet"> <script src="http://127.0.0.1/study../../../js/bootstrap/3.3.6/bootstrap.min.js"></script> <style> div.container div.row div { margin:5px 0px; } div.container div.row div { background-color: lightgray; border: 1px solid gray; text-align:center; } </style> <div class="container"> <div class="row"> <div class="col-xs-12 ">一共12列</div> </div> </div> <div class="container"> <div class="row"> <div class="col-xs-1 ">1列</div> <div class="col-xs-1 ">1列</div> <div class="col-xs-1 ">1列</div> <div class="col-xs-1 ">1列</div> <div class="col-xs-1 ">1列</div> <div class="col-xs-1 ">1列</div> <div class="col-xs-1 ">1列</div> <div class="col-xs-1 ">1列</div> <div class="col-xs-1 ">1列</div> <div class="col-xs-1 ">1列</div> <div class="col-xs-1 ">1列</div> <div class="col-xs-1 ">1列</div> </div> </div> <div class="container"> <div class="row"> <div class="col-xs-4 ">占4列</div> <div class="col-xs-4 ">占4列</div> <div class="col-xs-4 ">占4列</div> </div> </div>
"); window.frames["iframe3052"].document.write(decodeHtml(code3052)); window.frames["iframe3052"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3052"]).load(function(){ $("#iframe3052").height($("#iframe3052").contents().find("body").height()+showittryitheight); }); $("#iframe3052").height($("#iframe3052").contents().find("body").height()+showittryitheight); alreadyWriteCode3052 = code3052; $("#rendering3052").hide(); $("#rendered3052").show(); } var tRereshRetry2DemoPanel3052 = setInterval(rereshRetry2DemoPanel3052,1000); var binded3052 = false; $("textarea#stepcodeTextarea3052").keyup(function(){ if(!binded3052){ $(window).bind('beforeunload',function(){ binded3052 = true; return "xxxx"; }); } var newCode = $(this).val() code3052 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code3052!=newCode){ // window.frames["iframe3052"].document.write("
"); // window.frames["iframe3052"].document.write(decodeHtml($("textarea#stepcodeTextarea3052").val())); // window.frames["iframe3052"].document.close(); // $(window.frames["iframe3052"]).load(function(){ // $("#iframe3052").height($("#iframe3052").contents().find("body").height()+showittryitheight); // }); // code3052 = newCode; // } }); $(".tryButton3052").click(function(){ $("#tryDiv3052").show(); $("#stepcodeTextarea3052").focus(); $("#stepcodeTextarea3052").height(200); $("#iframe3052").height(0); window.frames["iframe3052"].document.write("
"); window.frames["iframe3052"].document.write(decodeHtml($("textarea#stepcodeTextarea3052").val())); window.frames["iframe3052"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3052"]).load(function(){ $("#iframe3052").height($("#iframe3052").contents().find("body").height()+showittryitheight); }); $("#iframe3052").height($("#iframe3052").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor3052.focus(); editor3052.setSize(null, "250"); $("#rendering3052").hide(); $("#rendered3052").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 editor3052 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea3052"), { 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); } } }); editor3052.on("change",function(doc){ if(!binded3052){ $(window).bind('beforeunload',function(){ binded3052 = true; return "xxxx"; }); } var newCode = doc.getValue(); code3052 = newCode; $("textarea#stepcodeTextarea3052").val(newCode); if(alreadyWriteCode3052!=code3052){ lastModifedTime3052 = new Date().getTime(); $("#rendering3052").show(); $("#rendered3052").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor3052 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor3052.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv3052").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

一半,1/3, 1/4

根据栅格系统的规划,要实现一半,1/3,1/4的布局,就很容易实现了。

注:一行不是必须添满的,比如第3行,只填了3个 1/4,最后一个1/4就可以空着
"); window.frames["iframe_show3053"].document.write(decodeHtml($("textarea#stepcodeTextarea3053").val())); window.frames["iframe_show3053"].document.close(); $(window.frames["iframe_show3053"]).load(function(){ $("#iframe_show3053").height($("#iframe_show3053").contents().find("body").height()+showittryitheight); }); $("#iframe_show3053").height($("#iframe_show3053").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<!DOCTYPE html> <script src="http://127.0.0.1/study../../../js/jquery/2.0.0/jquery.min.js"></script> <link href="http://127.0.0.1/study../../../css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet"> <script src="http://127.0.0.1/study../../../js/bootstrap/3.3.6/bootstrap.min.js"></script> <style> div.container div.row div { margin:5px 0px; } div.container div.row div { background-color: lightgray; border: 1px solid gray; text-align:center; } </style> <div class="container"> <div class="row"> <div class="col-xs-6 ">一半</div> <div class="col-xs-6 ">一半</div> </div> </div> <div class="container"> <div class="row"> <div class="col-xs-4 ">1/3</div> <div class="col-xs-4 ">1/3</div> <div class="col-xs-4 ">1/3</div> </div> </div> <div class="container"> <div class="row"> <div class="col-xs-3 ">1/4</div> <div class="col-xs-3 ">1/4</div> <div class="col-xs-3 ">1/4</div> </div> </div>
"); window.frames["iframe3053"].document.write(decodeHtml(code3053)); window.frames["iframe3053"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3053"]).load(function(){ $("#iframe3053").height($("#iframe3053").contents().find("body").height()+showittryitheight); }); $("#iframe3053").height($("#iframe3053").contents().find("body").height()+showittryitheight); alreadyWriteCode3053 = code3053; $("#rendering3053").hide(); $("#rendered3053").show(); } var tRereshRetry2DemoPanel3053 = setInterval(rereshRetry2DemoPanel3053,1000); var binded3053 = false; $("textarea#stepcodeTextarea3053").keyup(function(){ if(!binded3053){ $(window).bind('beforeunload',function(){ binded3053 = true; return "xxxx"; }); } var newCode = $(this).val() code3053 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code3053!=newCode){ // window.frames["iframe3053"].document.write("
"); // window.frames["iframe3053"].document.write(decodeHtml($("textarea#stepcodeTextarea3053").val())); // window.frames["iframe3053"].document.close(); // $(window.frames["iframe3053"]).load(function(){ // $("#iframe3053").height($("#iframe3053").contents().find("body").height()+showittryitheight); // }); // code3053 = newCode; // } }); $(".tryButton3053").click(function(){ $("#tryDiv3053").show(); $("#stepcodeTextarea3053").focus(); $("#stepcodeTextarea3053").height(200); $("#iframe3053").height(0); window.frames["iframe3053"].document.write("
"); window.frames["iframe3053"].document.write(decodeHtml($("textarea#stepcodeTextarea3053").val())); window.frames["iframe3053"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3053"]).load(function(){ $("#iframe3053").height($("#iframe3053").contents().find("body").height()+showittryitheight); }); $("#iframe3053").height($("#iframe3053").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor3053.focus(); editor3053.setSize(null, "250"); $("#rendering3053").hide(); $("#rendered3053").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 editor3053 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea3053"), { 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); } } }); editor3053.on("change",function(doc){ if(!binded3053){ $(window).bind('beforeunload',function(){ binded3053 = true; return "xxxx"; }); } var newCode = doc.getValue(); code3053 = newCode; $("textarea#stepcodeTextarea3053").val(newCode); if(alreadyWriteCode3053!=code3053){ lastModifedTime3053 = new Date().getTime(); $("#rendering3053").show(); $("#rendered3053").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor3053 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor3053.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv3053").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

自动换行

当同一行的栅格总数超过12的时候,就会自动换行
"); window.frames["iframe_show3055"].document.write(decodeHtml($("textarea#stepcodeTextarea3055").val())); window.frames["iframe_show3055"].document.close(); $(window.frames["iframe_show3055"]).load(function(){ $("#iframe_show3055").height($("#iframe_show3055").contents().find("body").height()+showittryitheight); }); $("#iframe_show3055").height($("#iframe_show3055").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<!DOCTYPE html> <script src="http://127.0.0.1/study../../../js/jquery/2.0.0/jquery.min.js"></script> <link href="http://127.0.0.1/study../../../css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet"> <script src="http://127.0.0.1/study../../../js/bootstrap/3.3.6/bootstrap.min.js"></script> <style> div.container div.row div { margin:5px 0px; } div.container div.row div { background-color: lightgray; border: 1px solid gray; text-align:center; } </style> <div class="container"> <div class="row"> <div class="col-xs-6 ">一半</div> <div class="col-xs-6 ">一半</div> </div> </div> <div class="container"> <div class="row"> <div class="col-xs-8 ">8格</div> <div class="col-xs-6 ">6格</div> </div> </div>
"); window.frames["iframe3055"].document.write(decodeHtml(code3055)); window.frames["iframe3055"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3055"]).load(function(){ $("#iframe3055").height($("#iframe3055").contents().find("body").height()+showittryitheight); }); $("#iframe3055").height($("#iframe3055").contents().find("body").height()+showittryitheight); alreadyWriteCode3055 = code3055; $("#rendering3055").hide(); $("#rendered3055").show(); } var tRereshRetry2DemoPanel3055 = setInterval(rereshRetry2DemoPanel3055,1000); var binded3055 = false; $("textarea#stepcodeTextarea3055").keyup(function(){ if(!binded3055){ $(window).bind('beforeunload',function(){ binded3055 = true; return "xxxx"; }); } var newCode = $(this).val() code3055 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code3055!=newCode){ // window.frames["iframe3055"].document.write("
"); // window.frames["iframe3055"].document.write(decodeHtml($("textarea#stepcodeTextarea3055").val())); // window.frames["iframe3055"].document.close(); // $(window.frames["iframe3055"]).load(function(){ // $("#iframe3055").height($("#iframe3055").contents().find("body").height()+showittryitheight); // }); // code3055 = newCode; // } }); $(".tryButton3055").click(function(){ $("#tryDiv3055").show(); $("#stepcodeTextarea3055").focus(); $("#stepcodeTextarea3055").height(200); $("#iframe3055").height(0); window.frames["iframe3055"].document.write("
"); window.frames["iframe3055"].document.write(decodeHtml($("textarea#stepcodeTextarea3055").val())); window.frames["iframe3055"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe3055"]).load(function(){ $("#iframe3055").height($("#iframe3055").contents().find("body").height()+showittryitheight); }); $("#iframe3055").height($("#iframe3055").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor3055.focus(); editor3055.setSize(null, "250"); $("#rendering3055").hide(); $("#rendered3055").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 editor3055 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea3055"), { 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); } } }); editor3055.on("change",function(doc){ if(!binded3055){ $(window).bind('beforeunload',function(){ binded3055 = true; return "xxxx"; }); } var newCode = doc.getValue(); code3055 = newCode; $("textarea#stepcodeTextarea3055").val(newCode); if(alreadyWriteCode3055!=code3055){ lastModifedTime3055 = new Date().getTime(); $("#rendering3055").show(); $("#rendered3055").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor3055 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor3055.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv3055").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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


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


关于 前端部分-BootStrap-栅格布局 的提问

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

上传截图