Skip to content

二级菜单

思路:

  • 一般需要一个蒙层,蒙层使用fixed定位,相对于视口定位。
  • 内部的内容使用居中。

代码

html
    <!-- 遮罩层 -->
    <div class="modal">
        <div class="container">
            Lorem ipsum dolor sit amet consectetur adipisicing elit. At qui illum, est vitae rerum a dignissimos voluptatum consequuntur culpa natus, nesciunt impedit, ipsum magnam! Doloribus repudiandae ipsum animi corrupti reiciendis!
            <div class="close">
                X
            </div>
        </div>
    </div>
css
.main img {
    width: 100%;
}

.modal {
    position: fixed;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    background: rgba(0, 0, 0, .5);
}

.modal .container{
    width:404px;
    height: 512px;
    background: #fff;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
    box-sizing: border-box;
    padding: 1em;
    border-radius: 6px;
}

.modal .container .close{
    width:30px;
    height: 30px;
    background: red;
    border-radius: 50%;
    color:#fff;
    text-align: center;
    line-height: 30px;
    position: absolute;
    right: -15px;
    top: -15px;
    border: 2px solid #fff;
    cursor: pointer;
}

MIT License