如何使用HTML和CSS创建倾斜的导航栏设计?

我试图制作一个带有倾斜形状的导航菜单,如下图所示。当我的导航栏链接是标签时,有人可以给我提供有关创建此方法的最佳方法的任何信息吗?

任何帮助将不胜感激!

如何使用HTML和CSS创建倾斜的导航栏设计?

这是我当前的导航栏:

.navbar {
  width: 100%;
  background-color: #555;
  overflow: auto;
}

/* Style the links inside the navigation bar */
.topnav a {
  float: left;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
  color: black;
  width: 25%;
  text-align: center;
  z-index: 1;
}

/* Change the color of links on hover */
.topnav a:hover {
   background-color: #637BAD;
  color: black;
}

/* Add a color to the active/current link */
.topnav a.active {
  background-color: #637BAD;
  
}
<div class="col-md-10"><div class="topnav" id="navigation" style="margin-top: -2%;">
      <a class="active" href="MusicFestival.php">Home <i class="far fa-arrow-alt-circle-right"></i></a>
      <a style="background-color: blueviolet" href="Friday.php">Friday <i class="far fa-arrow-alt-circle-right"></i></a>
      <a style="background-color: steelblue"href="Saturday.php">Saturday <i class="far fa-arrow-alt-circle-right"></i></a>
        <a style="background-color: lightblue"href="Sunday.php">Sunday <i class="far fa-arrow-alt-circle-right"></i></a>  
  </div></div>

yishuitian1 回答:如何使用HTML和CSS创建倾斜的导航栏设计?

查看小提琴:http://jsfiddle.net/HRWqq/

CSS:

li{
    float: left;
    background: #ccc;
    margin-right: 50px;
}
li > a {
    text-decoration: none;
    display: block;
    position: relative;
    line-height: 40px;
    padding: 0 8px;
}
li > a:before {
    content: '';
    position: absolute;
    border: 20px solid #ccc;
    border-left-color: transparent;
    border-top-color: transparent;
    right: 100%;
    top: 0;
}
li > a:after {
    content: '';
    position: absolute;
    border: 20px solid #ccc;
    border-right-color: transparent;
    border-bottom-color: transparent;
    left: 100%;
    top: 0;
}





li:first-child > a {
    background: #aaa;
}
li:first-child > a:after {
    border-top-color: #aaa;
    border-left-color: #aaa;
}

li:last-child > a {
    background: #ddd;
}
li:last-child > a:before{
    border-right-color: #ddd;
    border-bottom-color: #ddd;
}
li:last-child > a:after {
    border: 0;
}
HTML :

<ul>
    <li><a href="#">Some Text</a></li>
    <li><a href="#">Some Text</a></li>
    <li><a href="#">Some Text</a></li>
    <li><a href="#">Some Text</a></li>
    <li><a href="#">Some Text</a></li>
</ul>

,

您可以使用类似这样的东西。我只做了一个。

#home{
  margin-top: -2%; 
  padding:20px; 
  background:linear-gradient(300deg,transparent 30px,#777 30px);
  }
<div class="col-md-10">
  <div class="topnav" id="navigation" style="margin-top: -2%;">
      <a id="home" class="active" href="MusicFestival.php">Home
        <i class="far fa-arrow-alt-circle-right"></i>
      </a>
      <a style="background-color: blueviolet" href="Friday.php">Friday 
        <i class="far fa-arrow-alt-circle-right"></i>
      </a>
      <a style="background-color: steelblue"href="Saturday.php">Saturday 
        <i class="far fa-arrow-alt-circle-right"></i>
      </a>
        <a style="background-color: lightblue"href="Sunday.php">Sunday 
          <i class="far fa-arrow-alt-circle-right"></i>
          </a>  
  </div>
</div>

,

尝试这个https://jsfiddle.net/uzts3omw/

.nav {
  display: flex;
  justify-content: center;
  margin: 0;
  padding: 0;
}

.nav li {
  display: block;
  position: relative;
  list-style: none;
  padding: 0;
  margin: 0 20px;
}

.nav li a {
  display: block;
  position: relative;
  font: normal 18px/100%;
  text-decoration: none;
  background: #000;
  padding: 0 15px;
  margin: 0 5px;
  line-height: 40px;
  -webkit-text-fill-color: #fff;
}

.nav li:nth-child(1) a {
    background: #005771;
    color: #005771;
}

.nav li:nth-child(2) a {
    background: #710000;
    color: #710000;
}

.nav li:nth-child(3) a {
    background: #147100;
    color: #147100;
}

.nav li:nth-child(4) a {
    background: #716a00;
    color: #716a00;
}

.nav li a::before {
  content: '';
  position: absolute;
  top: 0;
  right: 100%;
  border: 20px solid;
  border-left-color: transparent !important;
  border-top-color: transparent !important;
}

.nav li a::after {
  content: '';
  position: absolute;
  top: 0;
  left: 100%;
  border: 20px solid;
  border-right-color: transparent !important;
  border-bottom-color: transparent !important;
}

.nav li a:hover {
  background: #0040ff;
}

.nav li a:hover::before,.nav li a:hover::after {
  border-color: #0040ff;
}
<ul class="nav">
  <li><a href="javascript:;">Home</a></li>
  <li><a href="javascript:;">About Us</a></li>
  <li><a href="javascript:;">Services</a></li>
  <li><a href="javascript:;">Contact Us</a></li>
</ul>

本文链接:https://www.f2er.com/3166317.html

大家都在问