css中偽類元素:before及:after用法淺談

來源:互聯網
上載者:User

標籤:tag   編輯   text   技術分享   mouseover   span   for   images   osi   

JS代碼:

<!DOCTYPE html><html><head><meta charset="utf-8" /><title></title><style>*{margin: 0;padding: 0;}.wrap{margin-top: 10px;width: 150px;padding: 10px;position: relative;}.wrap span:nth-of-type(1){vertical-align: bottom;display: inline-block;border: 1px solid black;padding: 10px;transition: 0.5s;}.wrap span:nth-of-type(2){height: 17px;vertical-align: bottom;display: inline-block;padding: 10px;padding-left: 100px;border-bottom: 1px solid black;transition: 0.5s;}.wrap span:nth-of-type(3){display: inline-block;position: absolute;left: 50px;top: 22px;}</style></head><body><div class="wrap" id="wrap"><span>?</span><span></span><span> Read More</span></div></body><script>var oDiv = document.getElementById("wrap");var Span1 = document.getElementsByTagName("span")[0];var Span2 = document.getElementsByTagName("span")[1];var Span3= document.getElementsByTagName("span")[2];oDiv.onmouseover = function(){oDiv.style.color ="red";Span1.style.borderColor="red";Span1.style.transform="rotateX(180deg)";Span2.style.borderColor="red";Span2.style.transform="rotateX(180deg)";oDiv.onmouseout =  function(){oDiv.style.color ="";Span1.style.borderColor="";Span1.style.transform="";Span2.style.borderColor="";Span2.style.transform="";}}</script></html>

無JS,用偽類編輯的css代碼

<!DOCTYPE html><html><head><meta charset="UTF-8"><title></title><style type="text/css">* {margin: 0;padding: 0;}.sp:hover{color: red;}.sp:hover:before,.sp:hover:after {color: red;transform: rotateX(180deg);border-color: red;}.sp:before {transition:0.5s;padding: 10px;content: ‘?‘;border: 1px solid black;display: inline-block;}.sp:after {content: ‘ ‘;width: 80px;transition:0.5s;padding: 19px;position: relative;top: 14px;left: -96px;border-bottom: 1px solid black;display: inline-block;}</style></head><body><div class="wrap" id="wrap"><span class="sp">  Read More</span></div></body></html>

 效果:

css中偽類元素:before及:after用法淺談

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.