Struggling to achieve evenly separated DIV's with this method

The other day, I encountered something completely new to me and decided to embark on a quest for answers.

I had a menu with various items inside it, and I wanted these items to span the full width of their parent element. After trying out different solutions, I settled on one that seemed simple and didn't involve any tricks:

HTML

<div id="menu">
    <a href="#"><div class="menu_item">Item 1</div></a>
    <a href="#"><div class="menu_item">Item 2</div></a>
    <a href="#"><div class="menu_item">Item 3</div></a>
</div>

CSS

div#menu {
    display:flex;
    justify-content:space-between;
}
div.menu_item {
    white-space:nowrap;
}

I even found a working example on JSFiddle. When I tested it in a new document, it worked perfectly. However, when I tried implementing it on my fully developed website, it just wouldn't cooperate. I considered several factors like inheritance of properties and conflicts, but nothing seems to work. The only option I have left is to start from scratch (which I'd rather avoid).

So here's my question: any insights on what might be causing this issue? Any thoughts at all?

PS: I've experimented with all this on my local computer, but the actual website is already live. If you want to take a look: (the section where I'm facing this challenge is where the buttons "Home," "Engenharia de sistemas," "Sobre o curso," etc., are located - with the container being div#menu and items as div.menu_item).

Answer №1

To make it work, simply add the code to the parent of your a tag, which is div.container in your actual code rather than div#menu:

div.container{
  display:flex;
  justify-content:space-between;
}

div.menu_item {
   white-space:nowrap;
}

UPDATE

Upon reviewing your code, the issue lies in using .container multiple times (which is okay because it's a class, but adding properties to it will affect other areas). You should target .container under a specific identifier, like #menu:

#menu .container{
   display:flex;
   justify-content:space-between;    
}

#menu .container a{
   white-space:nowrap;
}

FIDDLE

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

The display: flex property is not being properly implemented in Tailwind CSS for the sm:flex

I have a div with the following styles <div class="hidden sm:visible sm:flex"> .... </div> The sm:visible style is applied like this @media (min-width: 640px) .sm\:visible { visibility: visible; } However, the property disp ...

Tips for utilizing mysql_connect(...) on a web hosting platform

Recently, I signed up for a web hosting service and have just started learning PHP and MySQL. I came across this video tutorial https://www.youtube.com/watch?v=gvGb5Z0yMFY which demonstrates how to add a row to a table. In my MySQL database, I have a table ...

I'm a beginner in Ajax and I'm wondering how I can reset my CSS back to its original value after making an Ajax call. Is there a way to reload the CSS?

Currently, I am utilizing a jQuery ajax() call to fetch a response from a PHP page for form submission/validation purposes. Upon success, the response contains a list of form elements along with corresponding error messages (such as missing field or invali ...

How to Turn Off Hover Effect in Essential Grid for Mobile Devices

My website, tyloz.com, features four panels on the homepage that act as landing pages. These panels have a hover effect that also works on mobile devices. However, I am looking to disable the hover and double tap functionality specifically on phones. Is th ...

Questions regarding the flow-model in relation to svg

My code is as follows: body { background-color: black; } .root { background-color: aqua; } .svg-container { background-color: lightgray; } svg { background-color: red; } .btn { background-color: yellow; } .svg-container, .btn { display: inline-bloc ...

Tips for styling an inline list using CSS before revealing it with jQuery's .show method:

In my project, I want to display a row of 'cells' which are simply images of black or white squares based on their ID. The issue I am facing is that when the button is clicked, the row list is shown without the CSS applied, and then after a brief ...

The PHP file fails to load JavaScript because it requires another JavaScript file to be loaded beforehand

I created a chat widget using PHP (chat.php) and now I want to embed it into another PHP page (blank.php). To make this work, chat.php requires some scripts that are located in external JavaScript files. So, in blank.php, I added the necessary JS files th ...

challenge encountered while trying to remove ScrollTop feature on mobile gadgets

Currently facing a challenge with responsive design - I have implemented a sticky navbar effect that works seamlessly on desktop, but causes usability issues on mobile. When scrolling down on the mobile version, the sticky navbar obscures the text on the s ...

Optimizing Material UI Themes: Adjusting the spacing between labels and inputs for improved design

Currently, I am in the process of updating my MUI themes using the overrides functionality. This is how my input field looks like: https://i.sstatic.net/OFAGf.png I am looking to increase the space between the label and the input field. Below is the co ...

"Using Bootstrap to specifically align a grid of images in the center on any screen size

I'm currently utilizing bootstrap to center a group of social icons beneath an h1 text on all screen sizes. While I've managed to achieve this, there are two specific sizes where the alignment seems to be off. Here's a snapshot showing a sl ...

What is the best way to keep wp_nav_menu expanded while accessing submenu links?

Recently, I joined the Wordpress community and am currently in the process of converting a static HTML site to the WP platform. Almost everything is working smoothly except for the navigation menu. I am attempting to utilize the built-in navigation featur ...

Creating a new image by extracting a specific HTML div tag that contains an image and its layers

I currently have a div element that includes an image element along with multiple other div elements containing small text displayed above the image. I am looking to save the image along with its content to a new image file. Any suggestions or ideas are ...

Modifying the color of elements within a picture

I am in search of the perfect web technology or JavaScript library that can help me achieve a specific functionality. My aim is to change the colors of particular objects within an image. I am looking to create a tool where users can select a color, and th ...

Allow the checkbox to only be functional for one use

Toggle the checkboxes between enable and disable based on user's choice to edit or cancel operation. This functionality has been tested on both my Android phone and tablet devices. Upon loading the page, the HTML code appears like this: <div class ...

Creating an HTML Excel file in ASP.NET

I am using a StringBuilder to dynamically generate a file. The file contains a table with two rows and two columns. In the second row, the first column has text and the second column contains another table. I have successfully created this design in HTML ...

What is the best way to create a Material toolbar that changes from transparent to opaque when scrolling?

I'm in the process of familiarizing myself with Angular. I have incorporated Angular Material and I am trying to achieve a sticky and opaque material toolbar that becomes transparent with visible text when scrolling at the top of the page. Most soluti ...

The left-floating elements are only partially functional

I recently encountered an issue with my HTML page that features a basic image gallery enhanced by lightboxes (fancybox). The images are meant to align left, with the first row containing three images and the second row containing two. <div class="image ...

What is the best way to distribute multiple inline-block elements evenly?

Is it feasible to evenly distribute numerous elements in a div with adjustable width? Check out this example that doesn't work. While using text-align:center; will center the elements, margin:0 auto; does not have any effect. I am aiming for somethin ...

What is causing jQuery toggleClass to fail in removing a class?

I have successfully implemented a Skills accordion feature, but I am now trying to add a button that toggles all the skill sections at once. However, I am facing issues with jQuery not correctly adding or removing classes on the .accordion-trigger-all elem ...

Challenges with placement of Div elements

Check out my jsFiddle example here: http://jsfiddle.net/pqCGd/. Within the jsFiddle, you will find a large messages div that contains multiple message divs. In this example, I have manually provided an example of a message div instead of using auto-genera ...