The secondary element is taking precedence over the primary class

How can I create a menu with the logo in the center, where the logo is larger than the menu itself? I want to add a white line under the logo for aesthetic reasons. However, when I try to add this line using a pseudo-element of the logo (:after), it ends up overriding the logo. I attempted to use z-index, but it didn't solve the issue.

* {background-color: #ededed;}
header::before {
    content: "";
    display: block;
    width: 100%;
    height: 15px;
    background: linear-gradient(90deg, var(--main) 0, #7b31f4);
    position: relative;
}
.header-wrapper {
    width: 100%;
    height: 100px;
    display: flex;
}
.logo-wrapper {
    top: 70px;
    height: auto;
    position: absolute;
}
.logo::before{
    content: '';
    display: block;
    width: 334px;
    height: 82px;
    position: absolute;
    bottom: -40px;
    left: -50%;
    
    border-top: 80px solid #fff;
    border-left: 37px solid transparent;
    border-right: 37px solid transparent;
    
}
.logo {
    max-width: 150px;
}

nav {
    display: flex;
    justify-content: space-around;
    width: 100%;
    align-items: center;
}

ul.left,
ul.right {
    display: flex;
}
      <header>
      <div class="header-wrapper">
       <nav>
            <ul class="left">
                <li><a href="#" class="nav-item">Home</a></li>
                <li><a href="#" class="nav-item">Players</a></li>            
            </ul>
            <div class="logo-wrapper">
                <div class="logo"><img src="https://via.placeholder.com/150

C/O https://placeholder.com/" alt="HK Kúple Bojnice" width="100%"></div>
            </div> 
            <ul class="right">
                <li><a href="#" class="nav-item">Matches</a></li>
                <li><a href="#" class="nav-item">News</a></li>
            </ul>
        </nav>
        </div>
        </header>

Answer №1

Simply include the z-index property

.logo::before {
  z-index: -1;
}

Answer №2

If I understood correctly, you want to position the white object behind the logo, right? Try giving your white object a lower z-index. That should solve the issue. You can implement it like this:

* {
  background-color: #ededed;
}

header::before {
  content: "";
  display: block;
  width: 100%;
  height: 15px;
  background: linear-gradient(90deg, var(--main) 0, #7b31f4);
  position: relative;
}

.header-wrapper {
  width: 100%;
  height: 100px;
  display: flex;
}

.logo-wrapper {
  top: 70px;
  height: auto;
  position: absolute;
}

.logo::before {
  content: '';
  display: block;
  width: 334px;
  height: 82px;
  position: absolute;
  bottom: -40px;
  left: -50%;
  border-top: 80px solid #fff;
  border-left: 37px solid transparent;
  border-right: 37px solid transparent;
  z-index: -1; /* Lower Z-index */
}

.logo {
  max-width: 150px;
}

nav {
  display: flex;
  justify-content: space-around;
  width: 100%;
  align-items: center;
}

ul.left,
ul.right {
  display: flex;
}
<header>
  <div class="header-wrapper">
    <nav>
      <ul class="left">
        <li><a href="#" class="nav-item">Home</a></li>
        <li><a href="#" class="nav-item">Players</a></li>
      </ul>
      <div class="logo-wrapper">
        <div class="logo"><img src="https://via.placeholder.com/150" alt="HK Kúple Bojnice" width="100%"></div>
      </div>
      <ul class="right">
        <li><a href="#" class="nav-item">Matches</a></li>
        <li><a href="#" class="nav-item">News</a></li>
      </ul>
    </nav>
  </div>
</header>

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

Is it possible to utilize retina images with CSS3's :before selector?

Can I adjust the size of an image inserted using :before? For example, if I want to use a high resolution image in the content below - how can I specify the dimensions? .buy_tickets_btn:before{ content: url(../images/buttons/pink_ticket_btn_bg.pn ...

Positioning elements at the bottom of the container

There is a dilemma that only those in the world of web development will understand. Beware! I have envisioned a layout for a website I am constructing. The concept involves tilted <hr/> elements on the page, with text wrapping around them (refer to ...

"Can we have selection options or drop-down menus that are in line with today

Currently working on a website project for a client where I, as a designer learning to code, have integrated three select options. This is how it appears: The client's new requirement is that the arrival date should automatically display as the curr ...

What is the method for including a TabIndex property in a JSON file?

https://i.sstatic.net/ISi72.png I discussed the integration of HTML fields within a JSON file and highlighted how to utilize the TabIndex property effectively in JSON files. ...

Having difficulty recreating the arrow feature in the bootstrap sidebar

I am currently working on creating the fourth sidebar (from the left) using the templates provided in Bootstrap 5 examples. Everything seems to be falling into place except for one issue - I can't seem to get the arrow to rotate when aria-expanded=tr ...

What are the differences in rendering between Almost Standards Mode and Standards mode?

After researching extensively, I have found that the main difference between almost standards mode and standards mode is related to image alignment in table cells. However, a particular question on Internet Explorer 8 and Checkbox CSS Problem, has pointed ...

In a React application, the input field unexpectedly loses focus after typing just one character

Has anyone encountered an issue with a dropdown menu causing input field focus to be lost after typing one character? I've attempted setting unique keys for each field, but it hasn't resolved the problem. For reference, here is the link to the p ...

Issues retrieving information from MySQL through an AJAX request

I am encountering an issue while attempting to fetch data from a database. The code seems to only retrieve the initial row of data and not any subsequent rows. Although the data is correct, it remains the same regardless of the input provided in the HTML f ...

Image displayed in tooltip when hovering over

I have been experimenting with displaying an image in a tooltip when hovering over it. I came across a fantastic solution that suits my needs: Codepen CSS: @import "compass"; * { box-sizing: border-box; } .tooltip { position: relative; border-bo ...

Positioning a div on the right side of its parent div

Hi there! I'm currently working on a small navbar that has two sections: the left section with an arrow icon and the right section with two icons - an envelope and an exclamation triangle. I've been trying to position the right section in the top ...

Spacing Between Bootstrap Columns

Is there a way to add a gap between each column while still maintaining 4 columns per row? When I try using the margin property, the columns do not align properly. Can you suggest a solution? <style> .test { border: 5px solid red; } </style&g ...

I am having difficulty organizing my text into two grid columns and aligning it in the center

.hero { display: grid; grid-template-columns: repeat(2, 33.45rem); grid-template-rows: 12.5rem; border-bottom: .05em solid #05d31f; width: 69.8rem; height: 16.5rem; } .hero-title { grid-row-start: 1; grid-column-start: 1; } .hero-title h ...

What is causing this absolute list item to stray away from its parent container?

Why is the ul element taking up the full width of the wrapper element when the container div is its parent? How can this be adjusted? Here is the HTML structure: Wrapper | container | label | input | ul | botton Here is the ...

Effective URL structure with nested ui-view in AngularJS

It is common knowledge that Angular functions as a SPA (Single Page Application). I am seeking the most effective approach to display a main left-side menu selector page, where clicking on any menu item will load the content in the right-side view div. Th ...

Incorporate Error Text Spacing in Input Group Design

I'm currently working on developing a method to incorporate space for error messages within my form input group component. The main objective is to prevent any displacement of elements on my forms when displaying error messages. In this scenario, it ...

Sharing and soliciting information from online sites

My system is designed to capture and store every member's IP address, browser, and operating system details. I am interested in integrating this. Is there a method to automatically send the user's IP to their website, retrieve information like ...

Applying a translucent layer of color to a jpeg image to create a subtle background effect

I am attempting to create a semi-transparent, solid background color on top of an <img> tag, while still showing the original image underneath at the same ratio and size. Below is a snippet of the code I am working with (let me know if you need more ...

Adjusting the header row to match the width of the data row in an HTML table

I am facing an issue with the layout of my HTML table. I have set space between each cell using margin, but this is causing a problem with column width. Instead of having col-12 for a row, it has become col-11 due to the spacing. This has resulted in the h ...

Images are not displayed when utilizing font-awesome on a MVC 5 website

I'm having an issue where adding font-awesome to the style bundle is causing images not to display correctly. Instead of showing the right icon, I am getting a transparent box. My style bundle configuration looks like this: bundles.Add(new StyleBund ...

Enhancing image search functionality through dynamic HTML updates

I need help figuring out how to update the link address for profile pictures on my NHL stats website. Currently, I am using a script to append the image to the body, but I don't know how to properly add the player ID ({{p1_ID}}) to the link and includ ...