Enhancing your navbar with a stylish ribbon touch

I'm currently stuck with a problem in my bootstrap navbar menu. I want to achieve a "ribbon" effect similar to the image below:

https://i.sstatic.net/ROftS.png

I have tried using :after and :before properties on two elements, but I'm struggling to create the triangles in the left part.

Here is my code and a link to the CodePen for reference:

<nav class="navbar navbar-default">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#about">Link2</a></li>
        <li><a href="#contact">Link3</a></li>
        <li><a href="#contact">Link4</a></li>
        <li><a href="#contact">Link5</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</nav>

.navbar .navbar-nav li a{
  color:white !important;
}
.navbar-nav li.active:before{
   content: '';
    position: absolute;
    bottom: -20px;
    left: 0;
    right: 0;
    height: 5px;
    border: 10px transparent solid;
    border-top-color: #990033;
    border-left-width: 0;
    border-right-width: 0;
}
... (additional CSS styles)

Check out the result here: CodePen

Any suggestions on how to achieve this effect? Thank you!

Answer №1

Note: The element does not adjust its size based on height. Be cautious when using as the height is hardcoded; However, heights are customizable. If necessary, utilize JavaScript to dynamically adjust heights and translations.

.nav {
  margin-top: 30px;
  height: 20px;
  background-color: orange;
}
.nav-item {
  margin: -10px 0 0 30px;
  display:inline-block;
  padding:10px;
  color: white;
  background-color: #AA0000;
  position: relative;
  font-family: "Helvetica";
  box-shadow: 3px 2px 5px 0 rgba(0,0,0,0.4)
}
.nav-item:before {
  position: absolute;
  top: 0; left:-10px ; bottom:0;
  display: inline-block;
  content: '';
  border-top: 10px solid #770000;
  border-bottom: 10px solid transparent;
  border-left: 10px solid transparent;
  transform: translateY(28px);
}

.nav-item:after {
  position: absolute;
  top: 0; left:-10px ; bottom:0;
  display: inline-block;
  content: '';
  border-top: 10px solid #440000;
  border-bottom: 10px solid transparent;
  border-right: 10px solid transparent;
  transform: rotate(180deg) translateY(28px);
}
<div class="nav">
  <div class="nav-item">zeke</div>
  <div class="nav-item">dran</div>
<div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Calculate the position of an element's top property using dynamic JavaScript calculations

I am currently working on a script to control the scrolling speed of elements on a webpage relative to their parent div. The code I have written so far is as follows: $('#two').css({'top' : 600-($(this).scrollTop() / 1.2)+"px"}); The ...

Exclude strong tag inside div using Jsoup Select

Here is a sample of HTML code: <div class="address"> <strong>John Doe </strong> <br>Main Street 5 <br>12345 Anytown </div> This is the code snippet I am using: html = html.r ...

Ways to eliminate the gap produced by a fixed element

Why is my chatbox (marked in red) creating unnecessary space at the top (highlighted in yellow), even though it has a sticky position and should not be affecting that area? The other elements on the webpage seem to be impacted by this. How can I prevent th ...

Tips for keeping a label above an input field

Is it possible to add a styled label on top of an input element? I have seen images placed inside input elements for indicating the type of input accepted. For example, in a login form, a user icon represents the username field and a key icon represents th ...

Error message: "Link binding error in knockout collection"

In this example, you'll find my Knockout ViewModel. $(document).ready( function () { var Incident = function (CaseNumber, DateOfIncident, Description) { this.CaseNumber = CaseNumber; this.DateOfIncident = DateOfIn ...

Is it possible to establish globally applicable values using CSS?

Is it possible to set global attributes within a wordpress site to override all instances of specific CSS styles across multiple locations for themes, 3rd party plugins and more? For instance, if I want to apply 'border-radius: 0px;' to all butt ...

I'm wondering why my positive numbers aren't displayed in green and negative numbers in red

I am currently working on a commodities quotes widget. I have already set up the 'Current' and '24-hour' divs, but I'm facing an issue where positive values are not displaying in green and negatives in red as intended. I have check ...

The CSS "mask" property is experiencing compatibility issues on Google Chrome

Hey there! I've recently developed a unique progress bar component in React that showcases a stunning gradient background. This effect is achieved by utilizing the CSS mask property. While everything runs smoothly on Firefox, I'm facing a slight ...

Unrestricted heading for a spreadsheet

My goal is to create a table with a leftmost header column that has no border, but is still part of the table. In my attempt to achieve this, I used the following HTML code: <table class="my-table" style="border-left: 0"> <tr> < ...

Could you please advise me on where I should apply line-height in order for it to work properly?

My div is structured like this: https://i.sstatic.net/3fUNs.png I am trying to decrease the spacing between the lines. I attempted adding a line-height attribute to both the parent div and one of the label elements like this: <div class="row" ...

Use ng-class in a P tag to assess a variety of expressions

Is there a way to apply ng-class to automatically evaluate negative values within a < p > tag? <p <strong>LW$:</strong> {{d.lw_metric}} <strong>LW:</strong> {{d.lw_metric_percentage}} <strong>L4W:</strong> {{ ...

background image alteration when scrolling

I've been attempting to change the background image on scroll, but I haven't had any luck finding a guide. So, I'm hoping someone here can help me out. I found a video that showcases exactly what I'm trying to accomplish - https://www.y ...

Reducing the size of a collection of CSS shapes

I'm attempting to position a group of elements in the top left corner of a webpage. Everything looks good when the browser is at its maximum width. However, once the browser width decreases to less than the width of the largest element (outer-circle o ...

CSS grid tracks remain fixed in size while other tracks expand

Why won't the grid track cells dynamically shrink when other cells are enlarged in the following code? In this snippet, hovering over any track section causes that cell to grow to 75% of the viewpoint. However, instead of the other sections shrinking ...

Arranging Bootstrap divs vertically and then horizontally in mobile view

My website layout is relatively straightforward. It consists of a header at the top, a navigation bar with an image inside a column on the left, and the main content displayed on the right side. https://i.stack.imgur.com/yYzaG.png For mobile responsive vi ...

Can we incorporate <a> tags in XML as we do in HTML?

Currently, I am honing my XML skills. I am planning to incorporate the <a> tag within the XML file in order to create a hyperlink to another webpage. ...

Steps to incorporate iframe into a webpage with 100% height and enable page scrollbars

Looking to seamlessly integrate an iframe into a webpage? Here are the requirements: The iframe height must adjust to fit its content, occupying 100% of available space. Hide scrollbars within the iframe, allowing the page's scrollbars to adjust acc ...

Amend the value in the database

I am looking to adjust a value in my database by clicking on an image on my webpage. Can someone guide me on how to achieve this using JavaScript and AJAX? ...

What is the best way to show or hide a child element when I hover over its parent?

Here is a snippet of HTML code for you: <style> .icon {display:none;} </style> <ul> <li>ABC <i id="abc" class="icon">x</i></li> <li>DEF <i id="def" class="icon">x</i></li> <l ...

Comparison of XPath operators //* versus //element versus //

My mind is a bit muddled when it comes to finding XPath: I'm not sure when to use //* at the beginning and when just // will suffice. For instance, I recently encountered this issue while trying to understand it on . On their homepage, there is a sea ...