how2j.cn


工具版本兼容问题
超链状态有4种
link - 初始状态,从未被访问过
visited - 已访问过
hover - 鼠标悬停于超链的上方
active - 鼠标左键点击下去,但是尚未弹起的时候

示例 1 : 超链状态   
示例 2 : 去除超链的下划线   
示例 3 : 练习-下拉菜单风格   
示例 4 : 答案-下拉菜单风格   

示例 1 :

超链状态

伪类,所谓的伪类即被选中的元素处于某种状态的时候
超链状态有4种
link - 初始状态,从未被访问过
visited - 已访问过
hover - 鼠标悬停于超链的上方
active - 鼠标左键点击下去,但是尚未弹起的时候
"); window.frames["iframe_show493"].document.write(decodeHtml($("textarea#stepcodeTextarea493").val())); window.frames["iframe_show493"].document.close(); $(window.frames["iframe_show493"]).load(function(){ $("#iframe_show493").height($("#iframe_show493").contents().find("body").height()+showittryitheight); }); $("#iframe_show493").height($("#iframe_show493").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<style> a:link {color: #FF0000} a:visited {color: #00FF00} a:hover {color: #FF00FF} a:active {color: #0000FF} </style> <a href="http://www.12306.com">超链的不同状态</a>
<style>
a:link {color: #FF0000}
a:visited {color: #00FF00}
a:hover {color: #FF00FF}
a:active {color: #0000FF}
</style>
 
<a href="http://www.12306.com">超链的不同状态</a>
"); window.frames["iframe493"].document.write(decodeHtml(code493)); window.frames["iframe493"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe493"]).load(function(){ $("#iframe493").height($("#iframe493").contents().find("body").height()+showittryitheight); }); $("#iframe493").height($("#iframe493").contents().find("body").height()+showittryitheight); alreadyWriteCode493 = code493; $("#rendering493").hide(); $("#rendered493").show(); } var tRereshRetry2DemoPanel493 = setInterval(rereshRetry2DemoPanel493,1000); var binded493 = false; $("textarea#stepcodeTextarea493").keyup(function(){ if(!binded493){ $(window).bind('beforeunload',function(){ binded493 = true; return "xxxx"; }); } var newCode = $(this).val() code493 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code493!=newCode){ // window.frames["iframe493"].document.write("
"); // window.frames["iframe493"].document.write(decodeHtml($("textarea#stepcodeTextarea493").val())); // window.frames["iframe493"].document.close(); // $(window.frames["iframe493"]).load(function(){ // $("#iframe493").height($("#iframe493").contents().find("body").height()+showittryitheight); // }); // code493 = newCode; // } }); $(".tryButton493").click(function(){ $("#tryDiv493").show(); $("#stepcodeTextarea493").focus(); $("#stepcodeTextarea493").height(200); $("#iframe493").height(0); window.frames["iframe493"].document.write("
"); window.frames["iframe493"].document.write(decodeHtml($("textarea#stepcodeTextarea493").val())); window.frames["iframe493"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe493"]).load(function(){ $("#iframe493").height($("#iframe493").contents().find("body").height()+showittryitheight); }); $("#iframe493").height($("#iframe493").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor493.focus(); editor493.setSize(null, "250"); $("#rendering493").hide(); $("#rendered493").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 editor493 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea493"), { 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); } } }); editor493.on("change",function(doc){ if(!binded493){ $(window).bind('beforeunload',function(){ binded493 = true; return "xxxx"; }); } var newCode = doc.getValue(); code493 = newCode; $("textarea#stepcodeTextarea493").val(newCode); if(alreadyWriteCode493!=code493){ lastModifedTime493 = new Date().getTime(); $("#rendering493").show(); $("#rendered493").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor493 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor493.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv493").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

去除超链的下划线

默认状态下,超链是有下划线的,但是现在网站上的超链普遍采用无下划线风格。

使用 text-decoration: none 文本修饰的样式来解决
"); window.frames["iframe_show2895"].document.write(decodeHtml($("textarea#stepcodeTextarea2895").val())); window.frames["iframe_show2895"].document.close(); $(window.frames["iframe_show2895"]).load(function(){ $("#iframe_show2895").height($("#iframe_show2895").contents().find("body").height()+showittryitheight); }); $("#iframe_show2895").height($("#iframe_show2895").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
运行效果
<style> a.no_underline {text-decoration: none} </style> <a href="http://www.12306.com">默认的超链</a> <br> <a class="no_underline" href="http://www.12306.com">去除了下划线的超链</a>
<style>
a.no_underline {text-decoration: none}
</style>
  
<a href="http://www.12306.com">默认的超链</a>
<br>
<a class="no_underline" href="http://www.12306.com">去除了下划线的超链</a>
"); window.frames["iframe2895"].document.write(decodeHtml(code2895)); window.frames["iframe2895"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe2895"]).load(function(){ $("#iframe2895").height($("#iframe2895").contents().find("body").height()+showittryitheight); }); $("#iframe2895").height($("#iframe2895").contents().find("body").height()+showittryitheight); alreadyWriteCode2895 = code2895; $("#rendering2895").hide(); $("#rendered2895").show(); } var tRereshRetry2DemoPanel2895 = setInterval(rereshRetry2DemoPanel2895,1000); var binded2895 = false; $("textarea#stepcodeTextarea2895").keyup(function(){ if(!binded2895){ $(window).bind('beforeunload',function(){ binded2895 = true; return "xxxx"; }); } var newCode = $(this).val() code2895 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code2895!=newCode){ // window.frames["iframe2895"].document.write("
"); // window.frames["iframe2895"].document.write(decodeHtml($("textarea#stepcodeTextarea2895").val())); // window.frames["iframe2895"].document.close(); // $(window.frames["iframe2895"]).load(function(){ // $("#iframe2895").height($("#iframe2895").contents().find("body").height()+showittryitheight); // }); // code2895 = newCode; // } }); $(".tryButton2895").click(function(){ $("#tryDiv2895").show(); $("#stepcodeTextarea2895").focus(); $("#stepcodeTextarea2895").height(200); $("#iframe2895").height(0); window.frames["iframe2895"].document.write("
"); window.frames["iframe2895"].document.write(decodeHtml($("textarea#stepcodeTextarea2895").val())); window.frames["iframe2895"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe2895"]).load(function(){ $("#iframe2895").height($("#iframe2895").contents().find("body").height()+showittryitheight); }); $("#iframe2895").height($("#iframe2895").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor2895.focus(); editor2895.setSize(null, "250"); $("#rendering2895").hide(); $("#rendered2895").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 editor2895 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea2895"), { 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); } } }); editor2895.on("change",function(doc){ if(!binded2895){ $(window).bind('beforeunload',function(){ binded2895 = true; return "xxxx"; }); } var newCode = doc.getValue(); code2895 = newCode; $("textarea#stepcodeTextarea2895").val(newCode); if(alreadyWriteCode2895!=code2895){ lastModifedTime2895 = new Date().getTime(); $("#rendering2895").show(); $("#rendered2895").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor2895 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor2895.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv2895").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

练习-下拉菜单风格

练习难度
Or  姿势不对,事倍功半! 点击查看做练习的正确姿势
"); window.frames["iframe_show2960"].document.write(decodeHtml($("textarea#stepcodeTextarea2960").val())); window.frames["iframe_show2960"].document.close(); $(window.frames["iframe_show2960"]).load(function(){ $("#iframe_show2960").height($("#iframe_show2960").contents().find("body").height()+showittryitheight); }); $("#iframe_show2960").height($("#iframe_show2960").contents().find("body").height()+showittryitheight); setTimeout(function(){ },500); });
<style> a{ font-size:14px; color: CornflowerBlue; text-decoration: none; } div.menu { width:80px; border: 1px solid lightgray; margin-top:15px; position: absolute; left: 80px; top: 20px; } div.menu a{ display:block; font-size:14px; font-family:宋体; color: #888; text-decoration: none; padding:10 0 10 15; } div.menu a:hover { background-color: #f1f1f1; } </style> <a href="#nowhere"> 武器 </a> <a href="#nowhere"> 护甲 </a> <a href="#nowhere"> 英雄 </a> <div class="menu"> <a href="#nowhere"> 盖伦 </a> <a href="#nowhere"> 提莫 </a> <a href="#nowhere"> 安妮 </a> <a href="#nowhere"> 死哥 </a> </div> <div style="height:200px"></div>
"); window.frames["iframe2960"].document.write(decodeHtml(code2960)); window.frames["iframe2960"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe2960"]).load(function(){ $("#iframe2960").height($("#iframe2960").contents().find("body").height()+showittryitheight); }); $("#iframe2960").height($("#iframe2960").contents().find("body").height()+showittryitheight); alreadyWriteCode2960 = code2960; $("#rendering2960").hide(); $("#rendered2960").show(); } var tRereshRetry2DemoPanel2960 = setInterval(rereshRetry2DemoPanel2960,1000); var binded2960 = false; $("textarea#stepcodeTextarea2960").keyup(function(){ if(!binded2960){ $(window).bind('beforeunload',function(){ binded2960 = true; return "xxxx"; }); } var newCode = $(this).val() code2960 = newCode; /*below code is replaced by function rereshRetry2DemoPanel()*/ // if(code2960!=newCode){ // window.frames["iframe2960"].document.write("
"); // window.frames["iframe2960"].document.write(decodeHtml($("textarea#stepcodeTextarea2960").val())); // window.frames["iframe2960"].document.close(); // $(window.frames["iframe2960"]).load(function(){ // $("#iframe2960").height($("#iframe2960").contents().find("body").height()+showittryitheight); // }); // code2960 = newCode; // } }); $(".tryButton2960").click(function(){ $("#tryDiv2960").show(); $("#stepcodeTextarea2960").focus(); $("#stepcodeTextarea2960").height(200); $("#iframe2960").height(0); window.frames["iframe2960"].document.write("
"); window.frames["iframe2960"].document.write(decodeHtml($("textarea#stepcodeTextarea2960").val())); window.frames["iframe2960"].document.close(); //load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式 $(window.frames["iframe2960"]).load(function(){ $("#iframe2960").height($("#iframe2960").contents().find("body").height()+showittryitheight); }); $("#iframe2960").height($("#iframe2960").contents().find("body").height()+showittryitheight); this.scrollIntoView(true); editor2960.focus(); editor2960.setSize(null, "250"); $("#rendering2960").hide(); $("#rendered2960").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 editor2960 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea2960"), { 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); } } }); editor2960.on("change",function(doc){ if(!binded2960){ $(window).bind('beforeunload',function(){ binded2960 = true; return "xxxx"; }); } var newCode = doc.getValue(); code2960 = newCode; $("textarea#stepcodeTextarea2960").val(newCode); if(alreadyWriteCode2960!=code2960){ lastModifedTime2960 = new Date().getTime(); $("#rendering2960").show(); $("#rendered2960").hide(); } // alert(doc.getValue()); }); $(".CodeMirror").addClass("form-control"); // var editor2960 = CodeMirror.fromTextArea(, { // lineNumbers: true, // styleActiveLine: true, // matchBrackets: true, // theme:"eclipse", // }); editor2960.on("change",function(doc){ // alert(doc.getValue()); }); $("#tryDiv2960").hide(); }); $("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");


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

答案-下拉菜单风格

在查看答案前,尽量先自己完成,碰到问题再来查看答案,收获会更多


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


关于 前端部分-CSS-超链状态 的提问

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

上传截图