首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在parent上使用skew会导致sidenav失去位置

在parent上使用skew会导致sidenav失去位置
EN

Stack Overflow用户
提问于 2017-06-08 18:22:03
回答 0查看 31关注 0票数 2

很抱歉我的措辞,我不知道该怎么表达。

我有一个标头和一个容器,其中包含一个sidenav和按钮来切换它。我试图在保持容器正常的同时向相反的方向倾斜头部。然而,这样做会导致sidenav失去它的高度:100%,它不会粘在左边。

怎样才能在不影响边框的情况下倾斜背景?

下面是小提琴和代码https://jsfiddle.net/q0ddzw4v/

HTML

代码语言:javascript
复制
<body id="body">
    <header class="header">
        <div class="header__container">
            <div id="mySidenav" class="sidenav">
                <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
                <a href="#">About</a>
                <a href="#">Services</a>
                <a href="#">Clients</a>
                <a href="#">Contact</a>
            </div>

            <div id="main">
                <h2>Sidenav Push Example</h2>
                <p>Click on the element below to open the side navigation menu, and push this content to the right.</p>
                <span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; open</span>
            </div>
        </div>
    </header>

    <script>
        function openNav() {
            document.getElementById("mySidenav").style.width = "250px";
        }

        function closeNav() {
            document.getElementById("mySidenav").style.width = "0";
        }
    </script>
</body>

CSS

代码语言:javascript
复制
body {
    font-family: sans-serif;
}

.sidenav {
    height: 100%;
    width: 0;
    position: fixed;
    z-index: 1;
    top: 0;
    left: 0;
    background-color: #111;
    overflow-x: hidden;
    transition: 0.5s;
    padding-top: 60px;
}

.sidenav a {
    padding: 8px 8px 8px 32px;
    text-decoration: none;
    font-size: 25px;
    color: #818181;
    display: block;
}

.sidenav a:hover,
.offcanvas a:focus {
    color: #f1f1f1;
}

.sidenav .closebtn {
    position: absolute;
    top: 0;
    right: 25px;
    font-size: 36px;
    margin-left: 50px;
}

#main {
    padding: 16px;
}

.header {
    width: 100%;
    height: 100vh;
    background-color: #C18D8D;
    transform: skewY(-10deg);
}

.header__container {
    width: 80%;
    max-width: 71.25rem;
    margin: auto;
    display: flex;
    flex-direction: column;
    height: 100%;
    transform: skewY(10deg);
}
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44433060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档