|
示例
1
:
相对定位
示例
2
:
练习-相对定位,但是又不占用位置
示例
3
:
答案-相对定位,但是又不占用位置
属性:position
值: relative
与绝对定位不同的是,相对定位不会把该元素从原文档删除掉,而是在原文档的位置的基础上,移动一定的距离
");
window.frames["iframe_show487"].document.write(decodeHtml($("textarea#stepcodeTextarea487").val()));
window.frames["iframe_show487"].document.close();
$(window.frames["iframe_show487"]).load(function(){
$("#iframe_show487").height($("#iframe_show487").contents().find("body").height()+showittryitheight);
});
$("#iframe_show487").height($("#iframe_show487").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<style>
p.r{
position: relative;
left: 150px;
top: 50px;
}
</style>
<p >正常文字1</p>
<p >正常文字2</p>
<p class="r" >相对定位的文字3</p>
<p >正常文字4</p>
<p >正常文字5</p>
<style>
p.r{
position: relative;
left: 150px;
top: 50px;
}
</style>
<p >正常文字1</p>
<p >正常文字2</p>
<p class="r" >相对定位的文字3</p>
<p >正常文字4</p>
<p >正常文字5</p>
");
window.frames["iframe487"].document.write(decodeHtml(code487));
window.frames["iframe487"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe487"]).load(function(){
$("#iframe487").height($("#iframe487").contents().find("body").height()+showittryitheight);
});
$("#iframe487").height($("#iframe487").contents().find("body").height()+showittryitheight);
alreadyWriteCode487 = code487;
$("#rendering487").hide();
$("#rendered487").show();
}
var tRereshRetry2DemoPanel487 = setInterval(rereshRetry2DemoPanel487,1000);
var binded487 = false;
$("textarea#stepcodeTextarea487").keyup(function(){
if(!binded487){
$(window).bind('beforeunload',function(){
binded487 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code487 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code487!=newCode){
// window.frames["iframe487"].document.write("
");
// window.frames["iframe487"].document.write(decodeHtml($("textarea#stepcodeTextarea487").val()));
// window.frames["iframe487"].document.close();
// $(window.frames["iframe487"]).load(function(){
// $("#iframe487").height($("#iframe487").contents().find("body").height()+showittryitheight);
// });
// code487 = newCode;
// }
});
$(".tryButton487").click(function(){
$("#tryDiv487").show();
$("#stepcodeTextarea487").focus();
$("#stepcodeTextarea487").height(200);
$("#iframe487").height(0);
window.frames["iframe487"].document.write("
");
window.frames["iframe487"].document.write(decodeHtml($("textarea#stepcodeTextarea487").val()));
window.frames["iframe487"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe487"]).load(function(){
$("#iframe487").height($("#iframe487").contents().find("body").height()+showittryitheight);
});
$("#iframe487").height($("#iframe487").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor487.focus();
editor487.setSize(null, "250");
$("#rendering487").hide();
$("#rendered487").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 editor487 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea487"), {
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);
}
}
});
editor487.on("change",function(doc){
if(!binded487){
$(window).bind('beforeunload',function(){
binded487 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code487 = newCode;
$("textarea#stepcodeTextarea487").val(newCode);
if(alreadyWriteCode487!=code487){
lastModifedTime487 = new Date().getTime();
$("#rendering487").show();
$("#rendered487").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor487 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor487.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv487").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
示例
2
:
练习-相对定位,但是又不占用位置
练习难度
顶
折
Or
姿势不对,事倍功半!
点击查看做练习的正确姿势
相对定位的文字3 在原来的位置的基础上,向右移动150个像素,但是又不占用原来的坑。
结合相对定位和绝对定位实现这个效果
");
window.frames["iframe_show3080"].document.write(decodeHtml($("textarea#stepcodeTextarea3080").val()));
window.frames["iframe_show3080"].document.close();
$(window.frames["iframe_show3080"]).load(function(){
$("#iframe_show3080").height($("#iframe_show3080").contents().find("body").height()+showittryitheight);
});
$("#iframe_show3080").height($("#iframe_show3080").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<style>
div.r{
position: relative;
left: 0;
top: 0;
}
div.a{
position: absolute;
left: 150px;
top: 0px;
}
</style>
<p>正常文字1</p>
<p>正常文字2</p>
<div class="r">
<div class="a">相对定位的文字3(不占坑)</div>
</div>
<p>正常文字4</p>
<p>正常文字5</p>
<style>
div.r{
position: relative;
left: 0;
top: 0;
}
div.a{
position: absolute;
left: 150px;
top: 0px;
}
</style>
<p>正常文字1</p>
<p>正常文字2</p>
<div class="r">
<div class="a">相对定位的文字3(不占坑)</div>
</div>
<p>正常文字4</p>
<p>正常文字5</p>
");
window.frames["iframe3080"].document.write(decodeHtml(code3080));
window.frames["iframe3080"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe3080"]).load(function(){
$("#iframe3080").height($("#iframe3080").contents().find("body").height()+showittryitheight);
});
$("#iframe3080").height($("#iframe3080").contents().find("body").height()+showittryitheight);
alreadyWriteCode3080 = code3080;
$("#rendering3080").hide();
$("#rendered3080").show();
}
var tRereshRetry2DemoPanel3080 = setInterval(rereshRetry2DemoPanel3080,1000);
var binded3080 = false;
$("textarea#stepcodeTextarea3080").keyup(function(){
if(!binded3080){
$(window).bind('beforeunload',function(){
binded3080 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code3080 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code3080!=newCode){
// window.frames["iframe3080"].document.write("
");
// window.frames["iframe3080"].document.write(decodeHtml($("textarea#stepcodeTextarea3080").val()));
// window.frames["iframe3080"].document.close();
// $(window.frames["iframe3080"]).load(function(){
// $("#iframe3080").height($("#iframe3080").contents().find("body").height()+showittryitheight);
// });
// code3080 = newCode;
// }
});
$(".tryButton3080").click(function(){
$("#tryDiv3080").show();
$("#stepcodeTextarea3080").focus();
$("#stepcodeTextarea3080").height(200);
$("#iframe3080").height(0);
window.frames["iframe3080"].document.write("
");
window.frames["iframe3080"].document.write(decodeHtml($("textarea#stepcodeTextarea3080").val()));
window.frames["iframe3080"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe3080"]).load(function(){
$("#iframe3080").height($("#iframe3080").contents().find("body").height()+showittryitheight);
});
$("#iframe3080").height($("#iframe3080").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor3080.focus();
editor3080.setSize(null, "250");
$("#rendering3080").hide();
$("#rendered3080").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 editor3080 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea3080"), {
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);
}
}
});
editor3080.on("change",function(doc){
if(!binded3080){
$(window).bind('beforeunload',function(){
binded3080 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code3080 = newCode;
$("textarea#stepcodeTextarea3080").val(newCode);
if(alreadyWriteCode3080!=code3080){
lastModifedTime3080 = new Date().getTime();
$("#rendering3080").show();
$("#rendered3080").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor3080 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor3080.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv3080").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
示例
3
:
答案-相对定位,但是又不占用位置
顶
折
请先登录
在查看答案前,尽量先自己完成,碰到问题再来查看答案,收获会更多
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|