css如何在菜單上實現對勾?(代碼)

來源:互聯網
上載者:User
本篇文章給大家帶來的內容是關於css如何在菜單上實現對勾?(代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所協助。

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>:after :before</title>    <style>    li {        list-style-type: none;        position: relative;        margin: 2px;        padding: 0.5em 0.5em 0.5em 2em;        background: lightgrey;        font-family: sans-serif;    }        li.done {        background: #CCFF99;    }        li.done::before {        content: '';        position: absolute;        border-color: #009933;        border-style: solid;        border-width: 0 0.3em 0.25em 0;        height: 1em;        top: 1.3em;        left: 0.6em;        margin-top: -1em;        transform: rotate(45deg);        width: 0.5em;    }    </style></head><body>    <ul>        <li>Buy milk</li>        <li>Take the dog for a walk</li>        <li>Exercise</li>        <li>Write code</li>        <li>Play music</li>        <li>Relax</li>    </ul></body><script>var list = document.querySelector('ul');list.addEventListener('click', function(ev) {    if (ev.target.tagName === 'LI') {        ev.target.classList.toggle('done');    }}, false);</script></html>


效果如下:

關鍵的css:

li.done::before {    content: '';    position: absolute;    border-color: #009933;    border-style: solid;    border-width: 0 0.3em 0.25em 0;    height: 1em;    top: 1.3em;    left: 0.6em;    margin-top: -1em;    transform: rotate(45deg);    width: 0.5em;}

* bootstrap 向下的三角形 用於下拉式功能表

.caret {    border-left: 4px solid transparent;    border-right: 4px solid transparent;    border-top: 4px dashed;    display: inline-block;    height: 0;    margin-left: 2px;    vertical-align: middle;    width: 0;}
相關文章

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.