Nav item with unconventional alignment in flexbox

My footer's central navigation item is not centered, and I'm struggling to align it while maintaining even spacing between the links. I attempted to center it by adding a margin-right: 45px in the CSS file at the bottom (commented out in the Codepen). However, this additional margin disrupts the uniform spacing.

How can I keep the nav-container as a flexbox, centering the middle link with equal spacing between all three links?

I'm uncertain if achieving what I envision would be aesthetically pleasing. It might throw off the entire navigation bar since the left and right links differ in text length. I simply find it frustrating that I can't seem to resolve this issue.

Link to the code on Codepen

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="wedding-index.css">
  <link href="https://fonts.googleapis.com/css?family=Great+Vibes" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
  <title>Mc-Stamm Wedding</title>
</head>

<body>
  <header class="main-header">
    <i class="fas fa-heart"></i>
    <a class="main-header__link" href="index.html">The Mc-Stamm Wedding</a>
    <i class="fas fa-heart"></i>
  </header>

  <main class="main-container">
    <div class="main-container__image main-container__image-one"><img src="http://www.freegreatpicture.com/files/146/25102-colorful-high-resolution-background.jpg" alt="Walking down beach to the proposal"></div>
...
    <p class="main-container__paragraph main-container__paragraph-one">Please join us</p>
    <p class="main-container__paragraph main-container__paragraph-two">September 28, 2019</p>
  </main>

  <footer class="main-footer">
    <nav class="main-nav">
      <a class="main-nav__link" href="venue-information.html">Venue Information</a>
      <a class="main-nav__link" href="accommodations.html">Accommodations</a>
      <a class="main-nav__link" href="wedding-party.html">Wedding Party</a>
    </nav>
  </footer>  
</body>
</html>

CSS

/* Wedding Index CSS */

/* browser reset */
html {
  box-sizing: border-box;
  font-size: 16px;
}
...
}
/* End of positioning rules for scaled image div's */

/* Changes primary image border shape from circle to same as other image div's on hover */
.main-container__image-ten:hover img {
  border-radius: 20px;
}

/* Styles "Please join us" and "September 28, 2019" */
.main-container__paragraph {
  color: rgb(255, 255, 255);
  font-family: "Great Vibes", cursive;
  font-size: 2.5rem;
  letter-spacing: 0.1em;
}

/* Positions "Please join us" on grid */
.main-container__paragraph-one {
  grid-area: 23 / 9 / 27 / 26;
}

/* Positions "September 28, 2019" on grid */
.main-container__paragraph-two {
  grid-area: 23 / 72 / 27 / 97;
}

/* Style and positons <footer> element */
.main-footer {
  width: 100%;
  height: auto;
  background: rgb(255, 255, 255);
  padding-top: 30px;
}

/* Makes <nav> container a flexbox and positions flex items */
.main-nav {
  display: flex;
  height: auto;
  width: 100%;
  justify-content: space-evenly;
  align-items: center;
}

/* Styles link flex items */
.main-nav__link {
  text-decoration: none;
  color: rgb(0, 0, 0);
  font-family: "Montserrat", sans-serif;
  letter-spacing: 0.3em;
}

/* .main-nav__link:nth-of-type(2) {
  margin-right: 45px; /* pushed middle link more toward center, but disrupted space-evenly positioning */
} */

Answer №1

If you want to align your middle link and ensure equal spacing between all items, you can achieve that by applying the following CSS:

.main-nav__link:not(:nth-of-type(2)) { flex: 1; }
.main-nav__link:first-child { text-align: right; }
.main-nav__link:nth-of-type(2) { margin: 0 10%; } /* Adjust margin as needed */
.main-nav__link:last-child { text-align: left; }

Additionally, make sure to remove this line from the .main-nav selector:

justify-content: space-evenly;

The flex: 1; property instructs the items to utilize the remaining space available. Since both the first and last items have this property in this code snippet, they evenly distribute the remaining space, thus centering the middle item.

It's worth noting that this solution may interfere with responsiveness due to the specified margins on the middle item. To address this issue, consider implementing a media query for optimal responsiveness across different devices.

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

Using Angular 2 to assign unique ids to checkbox values

Is there a way to retrieve the value of a checkbox in Angular 2 without needing an additional Boolean variable? I am trying to toggle the enabled/disabled state of an input field based on the selection of a checkbox. While I know this can be accomplished ...

In the XHTML mode, MathOverflow's invaluable mathematical expertise shines brightly

I am interested in incorporating the unique “piece of valuable flair™” from MathOverflow onto my website. The issue I am facing is that I want my webpage to comply with XHTML5 standards, meaning it should be served with the MIME type application/xht ...

TabContainer - streamline your selection process with inline tabs

I am currently working on a GUI that includes a TabContainer with two tabs, each containing a different datagrid. I initially created the tabcontainer divs and datagrids declaratively in HTML for simplicity, but I am open to changing this approach if it wo ...

Creating an MPG4 Video from a Three.js Scene: What Are the Steps?

I am working with a three.js scene that includes numerous animated objects. I am looking to export this animation as an mpg4 video. Here are my questions: What is the best method for exporting a scene to create an mpg4 video? Is it recommended to perfo ...

What is the best way to place two span elements beside each other?

Is there a way to align the name and address on the same line, with the address positioned on the right and the name on the left? Currently, the address is appearing on a separate line from the name. How can I resolve this issue? Here is the provided cod ...

a height of 100% with a minimum height of 100%

Is there a way to make the third and fourth rectangles have the same position while filling all the remaining height in %? Keep in mind that we can't change the min-height:100% on the body or html. Feel free to use CSS and HTML for your code solution. ...

The excessive number of hidden newline elements in tables created with TinyMCE causes formatting issues

After successfully saving a table created inside TinyMCE to the database, I encountered an issue when trying to fetch the content using PHP. The retrieved data had an excessive amount of <br> tags appearing before the table. Although removing the nl2 ...

Condition for button functionality

I have a Submit button that, when pressed, triggers the onSubmit function. <b-form @submit.stop.prevent="handleSubmit(onSubmit)"> ... <b-button type="submit" >Submit</b-button> <script lang="ts ...

Creating interactive and adaptable maps

Currently, I am working on making a Joomla website responsive. However, I have encountered an issue with the SobiPro Map. The problem arises when displaying a map (background img) and points (a link + img) over it with an absolute position. As a result, wh ...

Tips for executing a join query in CodeIgniter

Hello, I am brand new to the CodeNighter framework and could really use some guidance on how to convert this join query into CodeNighter framework. Additionally, I need to know whether this join query should be placed in the model or controller. How can I ...

What are the essential files needed in Kendo UI Core for a mobile app?

Several months ago, I created a trial Kendo mobile app but now I want to verify it using the most recent version of Kendo UI Core. In my previous project, I referenced the following files: <link href="../styles/kendo.common.min.css" rel="stylesheet" / ...

Looking for two sliders in a row simultaneously

I currently have between 40 to 50 logos displayed on my website in a slider format, but it takes a lot of time to view the entire slider. Here's a snippet of my code: Below is the code snippet: <script src="https://ajax.googleapis.com/ajax/lib ...

Display all pages in the DataTables plugin while utilizing responsive tables and additional features

I am struggling to combine the responsive and fixed header attributes of my current function with the "Show All" list feature, similar to what is demonstrated in this example: https://datatables.net/examples/advanced_init/length_menu.html I need assistanc ...

What is the method for enlarging an element without regard to surrounding elements?

I am working on a code where I want the element to zoom in when hovered, completely disregarding its normal flow. By "ignoring its flow," I mean that other elements like tags might obstruct parts of its content. https://i.sstatic.net/NBoez.png https:// ...

Adjusting color in yii by utilizing html

Is there a way to customize the color of error messages in YII view using HTML? I have the following code, but I'm unsure how to combine the echo and html command. foreach ($inventoryModelsAndResults as $result) { echo implode(", ", $result["da ...

Update the select tag to display as radio buttons

Hey there, I've got a webpage where users can rate different systems. I've written a JavaScript function to dynamically add and remove systems for evaluation. The only issue is that I have to manually change the radio button names to prevent th ...

Experience seamless video playback on both mobile and web browsers with JW Player

I have integrated the JW Player for video playback on both mobile and web browsers. Currently, I have a library of 100 videos with dimensions set at 1280*700 pixels. These videos work well on web browsers and load quickly depending on internet speed. Howe ...

The hovering of the mouse over a dropdown menu causes a division on the page to shift

Creating a website with a dropdown menu and slider division can be tricky. When hovering over the menu, the submenu displays but causes the slider division to shift down. Does anyone have suggestions on how to fix this issue? Below is the code: <html& ...

PHP image retrieval is not functioning correctly and the image is not appearing as it

I'm facing some challenges when it comes to displaying images with PHP. I attempted to use this solution from Stack Overflow, but unfortunately, the image is still not appearing correctly. Within my PHP file that deals with the HTML layout, the code ...