How to set sidebar with css

藏色散人
Release: 2021-07-03 10:42:35
Original
4198 people have browsed it

How to set the sidebar with css: first create an HTML sample file; then set the navigation bar content in the body; finally set the css style to "#sidemenu:checked aside {left: 0;}.. ." to achieve the sidebar effect.

How to set sidebar with css

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.

How to set the sidebar in css?

CSS to implement sidebar navigation

##

<!DOCTYPE html><html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
        /*隐藏checked复选框*/
            #sidemenu{                display: none;            }

            #sidemenu:checked + aside {                /*为被选中的sidemenu后的aside设置属性(紧邻)*/
                left: 0;                /*点击按钮即选中checked后,侧边栏位置变为贴着左边,配合ease-out使用,有渐变滑出的效果*/
            }

            #sidemenu:checked ~ #wrap {                /*为被选中的sidemenu后的wrap设置属性(非紧邻)*/
                padding-left: 220px;            }

            aside {                /*侧边栏,初始位置为-200px,即隐藏效果*/
                position: absolute;                top: 0;                bottom: 0;                left: -200px;                width: 200px;                background: black;                transition: 0.2s ease-out;                /*动画效果的执行方式是ease-out,即侧边栏滑动效果为渐变式,而不是生硬的突然变化*/
            }

            h2 {                color: white;                text-align: center;                font-size: 2em;            }

            /*控制侧边栏进出的按钮(外部包裹)*/
            #wrap {                margin-left: 20px;                padding: 10px;                transition: 0.2s ease-out;            }

            /*控制侧边栏进出的按钮(内部文字样式)*/
            label {                /*控制侧边栏进出的按钮*/
                background: white;                border-radius: 70px;                color: orange;                cursor: pointer;                display: block;                font-family: Courier New;                font-size: 2em;                width: 1.5em;                height: 1.5em;                line-height: 1.5em;                text-align: center;                display: inline-block;            }

            label:hover {                background: #000;            }

            #sideul li {                list-style: none;                color: white;                width: 100%;                height: 1.8em;                font-size: 1.5em;                text-align: center;            }

            a {                text-decoration: none;            }

            #sideul li:hover {                color: orange;            }
        </style>
    </head>

    <body>
        <input type=&#39;checkbox&#39; id=&#39;sidemenu&#39;>
        <aside>
            <h2>主菜单</h2>
            <br />
            <ul id="sideul">
                <a href="##">
                    <li>首页</li>
                </a>
                <a href="##">
                    <li style="color: orange;">导航1</li>
                </a>
                <a href="##">
                    <li>导航2</li>
                </a>
                <a href="##">
                    <li>导航3</li>
                </a>
                <a href="##">
                    <li>导航4</li>
                </a>
                <a href="##">
                    <li>导航5</li>
                </a>
                <a href="##">
                    <li>导航6ʳ</li>
                </a>
            </ul>
        </aside>
        <p id=&#39;wrap&#39;>
            <label id=&#39;sideMenuControl&#39; for=&#39;sidemenu&#39;>≡</label>
            <!--for 属性规定 label 与哪个表单元素绑定,即将这个控制侧边栏进出的按钮与checkbox绑定-->
        </p>

    </body></html>
Copy after login

How to set sidebar with css
How to set sidebar with css

[Recommended study: "

css video tutorial"]

The above is the detailed content of How to set sidebar with css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template