Floating ribbons on the navigation bar

Could you help me with removing the space after the ribbon navbar in this fiddle: http://jsfiddle.net/BC3FL/?

I understand why it's there, but I'm struggling to find a solution without using fixed negative margins for elements below the navbar.

I've tried absolute positioning for flaps, but that causes issues with different browsers due to varying heights and widths. Additionally, overflow:hidden with another container doesn't work either: http://jsfiddle.net/KBs42/ since the flaps need to be positioned above the navigation bar.

Here is a simplified version of the code:

<div id="navigation_container">
<!-- the left side of the fork effect -->
<div class="l-triangle-top"></div>
<div class="l-triangle-bottom"></div>
<!-- the right side of the fork effect -->
<div class="r-triangle-top"></div>
<div class="r-triangle-bottom"></div>
<!-- the ribbon body -->
<div class="rectangle">
<!-- the navigation links -->
<ul id="navigation2">
   <li><a href="index.html"> Home</a></li>
   <li><a href="intro.html"> About</a></li>
   <li><a href="client.html"> Clients</a></li>
   <li><a href="catg.html"> Products</a></li>
   <li><a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97e3fff6fcfcf6e5d7e7f6f4faf6f4b9f4f8b9fef9">[email protected]</a>"> Contact</a></li>
</ul>
<!-- end the ribbon body -->
</div>
</div>
<!-- end container --> 
<div style="clear:both;"></div>
<div id="wrap">
<p>HEY</p>
</div> 
</div>

User CSS:

#navigation_container {
 margin: 0 auto;
 width: 1080px;
 overflow:hidden;
 height:80px;
 padding: auto;
}
#navigation2 li {
        list-style: none;
        display: block;
        float: left;
  margin: 1em 0.8em;
}
#navigation2 li a {
        text-shadow: 0 2px 1px rgba(0,0,0,0.5);
        display: block;
        text-decoration: none;
        color: #f0f0f0;
        font-size: 1.6em;
        margin: 0;
        line-height: 28px;
}
#navigation2 li.active a:hover,
#navigation2 li a:hover {
        margin-top: 2px;
}

#navigation2 li.active {
        font-style: italic;
}
#navigation2 li.active a {
}
.rectangle {
   background: #e5592e;
   height: 62px;
   width:920px;
   margin: 0 auto;
   position: relative;
   -moz-box-shadow: 0px 0px 4px rgba(0,0,0,0.55);
   -webkit-box-shadow: 0px 0px 4px rgba(0,0,0,0.55);
   box-shadow: 0px 0px 4px rgba(0,0,0,0.55);

   -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
 border-radius: 2px;

   z-index: 500; /* the stack order: foreground */
}
.l-triangle-top {
    border-color: #D9542B transparent transparent;
    border-style: solid;
    border-width: 50px;
    float: left;
    height: 0;
    left: 30px;
    position: relative;
    top: 10px;
    width: 0;
}

.l-triangle-bottom {
    border-color: transparent transparent #D9542B;
    border-style: solid;
    border-width: 50px;
    float: left;
    height: 0;
    left: -68px;
    position: relative;
    top: -35px;
    width: 0;
}
.r-triangle-top {
    border-color: #D9542B transparent transparent;
    border-style: solid;
    border-width: 50px;
    float: right;
    height: 0;
    position: relative;
    right: 30px;
    top: 10px;
    width: 0;
}
.r-triangle-bottom {
    border-color: transparent transparent #D9542B;
    border-style: solid;
    border-width: 50px;
    float: right;
    height: 0;
    position: relative;
    right: -68px;
    top: -35px;
    width: 0;
}
</style>

Thank you for any advice or feedback you can provide.

Answer №1

To ensure your triangle elements do not affect the layout of your container, you can give the container a relative position and set the triangles to absolute positioning.

#nav_container {
    position: relative;
}
.left-triangle-top {
    position: absolute;
    left: -50px;
    top: -5px;
}
.left-triangle-bottom: {
    position: absolute;
    left: -50px;
    top: -45px;
}
.right-triangle-top {
    position: absolute;
    right: -50px;
    top: -5px;
}
.right-triangle-bottom: {
    position: absolute;
    right: -50px;
    top: -45px;
}

By implementing this CSS structure, your content will not be shifted by the presence of the triangular elements.

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

Aligning Elements in the CSS Bootstrap Grid

Struggling to achieve perfect center alignment of an HTML element using the Bootstrap grid framework. Here's the current code: <div id="rentals" class="container pb-4"> <div class="row pt-5 mt-5 mb-4"> ...

My HTML5 design features buttons that overlap each other

When I zoom in, I notice two buttons - one on the left and one on the right. The larger button behind the main one changes color when hovered over but does not direct me to where I want to go. It seems like it's related to the width setting of 180px w ...

Is there a CSS3-compatible CSS parser available in C/C++?

Are there any C/C++ CSS parsers that currently support CSS3? I have come across a few, but none of them seem to offer full CSS3 compatibility. ...

How can I utilize Bootstrap ordering to rearrange the position of an element into a different column at a specific breakpoint?

I'm attempting to achieve a specific layout using Bootstrap order classes: https://i.sstatic.net/NKhg9.png Currently, I have something similar to this setup (assuming all elements are of equal height): <div class="row"> <div class="col- ...

The <a> tag styled as a button with the btn-primary class is malfunctioning specifically on MacOS Safari

Trying to use an anchor tag with type button and btn-primary class on MacOS safari is causing issues, while it works perfectly on Chrome and Edge browsers <a class="btn btn-primary " style="border-radius: 25px;" type="button&qu ...

Setting dynamic path in CSS background-image: url() is a common task for web developers

I have developed an HTML code and I am facing an issue with setting a dynamic URL for my background image: <div class="top-banner-bg" style="background-image: url({{ imageToShowURL }})"> </div> Below is the code in my Angular TS file: ngOnIn ...

What could be causing the password validation to fail in HTML/JS?

I created a JavaScript program for password validation in HTML, but something isn't working correctly. I've double-checked for syntax errors and can't seem to find any. Here's my code: <!DOCTYPE html> <html> <head&g ...

CSS: Issue with rounding errors in Em units

Recently, I decided to update the CSS file for a website I'm working on by making most elements and fonts dynamic in size using the em unit instead of px. The new sizes seem to be working, but there's an issue that's been bothering me. It s ...

Unable to trigger click event after slider is modified

One of the tasks at hand is to change the image/div margins in a slider upon click. Change the image margin in the slider Adjust text opacity in the top section of the slider Initially, the code operates as intended when the page first loads for the firs ...

Is it possible for CSS in React to cause the vanishing of all buttons

I'm encountering an issue where the CSS styling applied to every button in my NavBar is causing a specific button labeled 'Search' to disappear when it shouldn't. The problem stems from NavBar.css, which contains a media query that unin ...

Can you explain the purpose of the role attribute in XHTML? How is it commonly utilized?

After reviewing W3C's information about the role attribute, I am still unclear about its purpose. Is the role attribute meant to simply clarify the code, or do some browsers or spiders interpret it in a specific way? Could the role attribute serve as ...

Struggling to generate a 16x16 grid of divs with jQuery, encountering issues with divs constantly overlapping each other

Currently working on a small project for an online course where I need to create a 16x16 grid of divs using jQuery for DOM manipulation. However, I've encountered an issue - the divs are overlapping each other. As a beginner seeking constructive criti ...

Query CSS to target an empty array within the .data() method

I have a scenario where I am storing an array in a button using Jquery's .data() method. If the array happens to be empty, I want the button to appear in red color. How can I target the button with an empty array using CSS? var values1 = []; var ...

CSS: Position an element based on the size of the screen

I'm currently developing a program that will dynamically resize elements based on the viewer's screen size. The program is being built using JSP/SQL/XHTML/CSS, and I have a couple of queries. Is there a way to select a CSS file by storing the sc ...

Styling Icons for Tabs in Material UI

I am dynamically using these tabs: <Tabs value={value} onChange={handleChange} variant="scrollable" scrollButtons="off" indicatorColor="primary" textColor="pr ...

Can the automatically generated canvas from three.js be manipulated for styling and positioning?

I've been working through an online guide on three.js that illustrates how to create a rotating 3D cube. The JavaScript code I've implemented in a separate script file is as follows: function spin() { var scene = new THREE.Scene(); var came ...

Implementing a Method to Detect Keypress Event on Anchor Element

Within our application, we have implemented anchor tags as buttons to enable specific style implementations. An interesting feature of the anchor tag is that it does not receive focus when navigating through tabs. Although we have successfully implemented ...

Can elements be styled differently using the CSS :hover selector even if the hovered element and affected element are not related?

Within this demonstration fiddle, hovering over the element a triggers a change in background color for the First paragraph to red. Since a and #p1 are siblings, By altering the selector between them, this method (changing the relationship between elem ...

Incorporate a text input feature into the Pikaday modal dialogue box

I'm currently in the process of revamping Pikaday and want to swap out the year select for a text input. However, every time I add an input field, it ends up being unresponsive. Despite not being disabled, z-indexed to the background, or having any op ...