如何在全屏div标签上添加有边三角形

时间:2017-12-12 09:24:07

标签: html css

我想在移动视图端口上有一个全屏幕的div有一个有边框的三角形,我已经为工作中的桌面屏幕做了这个,但当我应用相同的属性并调整数字时,我确实得到了接近我想要的东西

HTML正在关注以及Codepen here

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class=" nav-items-wrapper">
    <div class="navbar-header">
     <a class="navbar-brand" style="margin-top:-8px;" href="/"><img style="width:50%;" src="../../../assets/logos/" alt="">brand</a>
    </div>
    <ul class="nav navbar-nav nav-ul">
     <li class="dem">
        <a href="#">Item 1</a>
     </li>
     <li class="dem">
        <a href="#">Dropdown3</a>
        <ul class="tri" style="visibility: hidden">
            <li class="ic"><a href="#">Option1</a></li>
            <li><a href="#">Option2</a></li>
            <li><a href="#">Option3</a></li>
        </ul>
     </li>
     <li class="dem" style="display: none;">
        <a href="#">Item 1</a>
     </li>
    </ul>
</div>
</nav>
<div class="mdiv">
  Mobile view
</div>

有效的是具有tri类的UL,这将在桌面屏幕上工作,我现在用内联visibility: hidden隐藏它

以下是两种情况的相应样式

.nav-items-wrapper {
  display: flex;
  justify-content: space-around;
}

.nav-ul {
  display: flex;
  flex-direction: row;
}

@media(max-width:767px) {
  .nav-items-wrapper ul li a{
    font-size: 13px;
  }

  .navbar-default {
    padding-top: 5px;
  }

  .nav-ul {
    width: 40vw;
    justify-content: center;
  }

}

.dem: hover > .tri {
    display:block;
}

.tri {
   // display: none;
    width: 300px;
    border-radius:2px;
    position: absolute;
    background-color: #000;
    top: 55px;
    padding: 10px 0;
    right: 0;
    left: auto;
    list-style: none;
}

.tri:after {
    position: absolute;
    left: 50%;
    margin-left: 70px;
    top: -8px;
    width: 0;
    height: 0;
    content:'';
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    border-bottom: 20px solid #000000;
}

.tri li {
    white-space: nowrap;
    padding: 7.5px 15px;
}

.mdiv {
  width: 100vw !important;
  max-width: 100vw !important;
  height: 100vh !important;
  background-color: #000;
  right: 0;
  left: auto;
  position: absolute;
} 

.mdiv:after {
    position: absolute !important;
    left: 50% !important;
    margin-left: 25% !important;
    top: 30vh !important;
    width: 0 ;
    height: 0 ;
    content:'';
    border-left: 20px solid green;
    border-right: 20px solid red;
    border-bottom: 20px solid #000000;
    pointer-events: none;
}.navbar-header {
  padding: 10px 10px;
}

我正在使用Bootstrap导航,我已经覆盖了导航栏崩溃等响应式样式,因为我不需要它们。

要查看的课程是我用于全屏的mdiv课程div

1 个答案:

答案 0 :(得分:0)

带有课程的div从顶部开始,所以它的某些部分位于navbar之下,我在margin-top添加了mdiv并根据需要调整了尺寸很好,谢谢,这是更新后的codePen