Dynamic Divider for Side-by-Side Menu - with a unique spin

I recently came across a question about creating responsive separators for horizontal lists on Stack Overflow

While attempting to implement this, I encountered some challenges.

document.onkeydown = function(event) {
var actionBox = document.getElementById('content');
switch (event.keyCode) {
  case 65:
    event.cancelBubble = true;
    event.returnValue = false;
    actionBox.innerHTML = '<ul id="content" class="name-container"> <li>Prename <strong>Name</strong></li> <li>Prename <strong>Name</strong></li> <li>Prename <strong>Name</strong></li> <li>Prename<strong>Name</strong></li></ul>';

    break;

}

return event.returnValue;
  }
ul {
  text-align: center;
  padding: 0;
}
li {
  display: inline;
}
li::after {
  content: " ";
  word-spacing: 1em;
  background-image: linear-gradient(
    -0.25turn,
    transparent 0 calc(50% - 0.03em),
    currentcolor 0 calc(50% + 0.03em),
    transparent 0
  );
}

body {
  overflow: hidden;
  margin: 0;
  font-family: 'Gill Sans Nova', sans-serif;
  background: no-repeat url('Hintergrund-01.jpg');
  background-size: cover;
}

#content {
  color: #FFF;
  display: flex;
  flex-wrap: wrap;
  flex: 1;
}

#name {
  font-size: 3em;
  color: #FFF;
  font-family: "gill-sans-nova", sans-serif;
  font-weight: 700;
  font-style: normal;
  padding-left: 10px;
}

#namestiftung {
  font-size: 3em;
  color: #FFF;
  font-family: "gill-sans-nova", sans-serif;
  font-weight: 700;
  font-style: normal;
  padding-left: 10px;
}

#vorname {
  font-size: 3em;
  color: #FFF;
  font-family: gill-sans-nova, sans-serif;
  font-weight: 300;
  font-style: normal;

}

#vornamestiftung {
  font-size: 3em;
  color: #FFF;
  font-family: gill-sans-nova, sans-serif;
  font-weight: 300;
  font-style: normal;

}

#titel {
  font-size: 1.5em;
  font-family: source-sans-pro, sans-serif;
  font-weight: 400;
  font-style: normal;
  display: block;
  width: 100%;
}

small {
  width: 100%;
  font-size: 1.5em;
  font-family: gill-sans-nova, sans-serif;
  font-weight: 500;
  font-style: normal;
  text-transform: uppercase;
}

.smalltext {
  width: 100%;
}

#logo {
  margin-left: 4em;
  text-align: right;
}

#logo img {
  height: 10em;
  text-align: right;
  margin-top: -20px;
}

.container {
  display: flex;
  flex-direction: row-reverse;
  padding: 40px;
  justify-content: space-around;
}

.name-container {
  display: flex;
  flex-wrap: wrap;
  column-gap: 12px;
  font-size: 40px;
  line-height: 1.3;
  align-content: space-between;
}

.name-container.four {
  font-size: 38px;
}

div.name-container div:not(:last-child) {
  border-right: 2px solid #fff;
  padding-right: 12px;
}

.name-container div:nth-child(n+3):nth-last-child(3n+1) {
  border-right: none;
}
<html>
<head>
  <meta charset="utf-8" />
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div class="container">
    <div id="logo">
      <img src="NOTG_2023_Logo.png" />
    </div>

    <div id="content">
      <!-- ############### -->
      <!-- Content of Page -->
      <!-- ############### -->
    </div>
  </div>
  <script src="names.js"></script>
  <script src="separator.js"></script>
</body>
</html>

The content is dynamically inserted using JavaScript:

I made use of the CSS provided in the earlier mentioned question.

However, despite having the ::after element, there seems to be no separator between the names.

https://i.stack.imgur.com/OUzPb.png

Interestingly, the same CSS works fine when applied to a predefined list.

The desired outcome should resemble the following:

ul {
  text-align: center;
  padding: 0;
}
li {
  display: inline;
}
li::after {
  content: " ";
  word-spacing: 1em;
  background-image: linear-gradient(
    -0.2turn,
    transparent 0 calc(50% - 0.03em),
    currentcolor 0 calc(50% + 0.03em),
    transparent 0
  );
}
<ul>
 <li>foo</li>
 <li>bar</li>
 <li>baz</li>
 <li>gazonk</li>
 <li>qux</li>
 <li>quux</li>
</ul>

It appears that the issue arises because the wrapping div#content is styled as a flexbox. Any insights on why this occurs? I would prefer to maintain the flexbox layout :)

Answer №1

To achieve a desired layout, apply display: flex; flex-wrap: wrap; to the <ul>. This will cause the list items to be displayed horizontally and wrap like normal inline-elements. You can also use gap to add spacing between the list items:

ul {
  list-style: none;
  padding-left: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1em;
}
<ul>
  <li>Max <strong>Mustermann</strong></li>
  <li>John <strong>Doe</strong></li>
  <li>Tommy <strong>Tentpeg</strong></li>
</ul>

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

I'm receiving the error message "app.get is not a function" when using Express.js. What could be

Having trouble understanding why I am getting an error: app.get is not a function in the upload.js file with the provided code snippet. In my index.js file, I have set up everything and exported my app using module.exports = app. I have also used app.set( ...

Ways to eliminate unnecessary items from a JavaScript object array and generate a fresh array

My JavaScript object array contains the following attributes: [ { active: true conditionText: "Really try not to die. We cannot afford to lose people" conditionType: "CONDITION" id: 12 identifier: "A1" ...

Run the command "node index.js" to simultaneously start and stop the server

After installing WSL2 and the Ubuntu 22.04 distribution on Windows 11, I set up my environment, installed nvm, Node version 16.17.1, and then ran npm init in my folder. Following that, I installed Express and created an index.js file with a simple structur ...

What is the best way to manipulate and update individual counters in React components?

I developed a ticket ordering system for a project, but encountered an issue where increasing the quantity of one ticket also resulted in the incrementation of the other ticket's counter. I suspect this occurs because only one value is stored in the s ...

`Prepare and load all materials in advance`

Question: On my page, I have a slideshow displaying images and videos. Before starting the slideshow, I want to ensure that all content on the page has loaded. Does $(window).load() verify if all content, including videos, has been loaded? Thanks in adv ...

What is the method for creating a hovering triangle on a particular element?

My navigation bar consists of two parts. On the left side, there is a logo image, and on the right side, there are 4 list elements. I am attempting to make a triangle appear at the bottom of the element when hovered. I have floated the list to the right an ...

Is it possible for me to create a CSS class based on a condition using [ngCLASS]?

I am struggling with logic writing in my Angular2 project. On a HTML page, I have two buttons - YES and NO that I want to style with different colors. I have set up a condition in the div tag like this: ngClass="'result'?'yes':' ...

Facing an obstacle in Angular as I am unable to view my data

How can I bind the model of my controller in the init function and see the data when the init is called? Index.html <!DOCTYPE html> <html ng-app="I-Sign"> <head> <meta http-equiv='X-UA-Compatible' content='IE=edge&apo ...

`How can I incorporate personalized animations on Google Map V3 Markers as they are individually dropped on the map?`

This is a basic example of dropping markers one by one on Google Maps V3. I have implemented the drop animation when adding markers to the map. However, I am interested in customizing the drop with a fade animation. Is it possible using JavaScript or any ...

AngularJS property sorting: organize your list by name

I have a complicated structure that resembles: { 'street35':[ {'address154': 'name14'}, {'address244': 'name2'} ], 'street2':[ {'address15& ...

"Learn the steps to toggle a sub menu using an onclick event and how to hide it using another

I created a sidebar navigation that displays submenus on mouseover, but I want them to open on click and close when clicking on the same tab. Please take a look at my code on this CodePen link. Thank you. <nav class="navigation"> <ul class="mai ...

Preventing users from inputting the same number more than once

Here are a series of text input fields pertaining to a single question: <input type="text" name="{{ $answer->id }}" value="" style="width:20px; text-align:center" maxlength="1" oninput="this.value=this.value.replace(/[^0-5]/g,'');" /> & ...

Utilizing the power of SimpleHTMLDom to retrieve high-resolution images through an advanced Google search

I want to display a large image that was retrieved from Google using simple_html_dom.php include_once( "simple_html_dom.php" ); $key="unique"; $html = new simple_html_dom(); $html=file_get_html('http://images.google.com/images?as ...

Using PHP to query the database and render text and links in the menu

On my website, users currently choose an "event" from a dropdown menu that is populated from a database (Check out the code below). Once a user selects an event from the menu, I want to display text links or a second dropdown menu with the "locations" ass ...

JQuery encountered a HTTP 404 error, signaling that the server was unable to locate anything that matched the requested URI

I am currently learning front-end development on my own and encountered an issue with implementing jQuery. You can find all the files for my site here: The problem I am facing is that there should be blog posts displayed between the header and navigation ...

Trouble with placing an absolutely positioned element using Tailwindcss

I am currently working on a project using TailwindCSS in which I have a logo positioned to the left and navigation to the right. Both elements are centered, but because the logo has a position of absolute, it appears in front of the navigation. I would lik ...

How can I load a specific div region using ajax for submitting a form?

I'm not sure if my approach is correct. On my main page, I have some information displayed. When you click a button, the form will load from a separate file: $('#viewport').load('/views/myView.php #targetDiv') This works fine ...

Tips for dynamically styling a Styled Component with all the CSS housed in an external file

My goal is to dynamically render a Styled Component. In the past, it was simple because all styling was contained within the component itself. However, I now strive to maintain a separation of concerns by storing the CSS in an external file. While this app ...

Using Selenium to Implement Accept Policy Targeting

I am attempting to locate and click on a button from dekudeals using selenium. Specifically, I am trying to target the accept button within the site's policy window. The button that needs to be clicked can be found here. I have made several attempt ...

What are the steps for implementing this javascript code in an HTML document?

Recently, I've been seeking advice on how to address the issue of wanting a button click to automatically select the search box on my website. Suggestions have pointed towards using Javascript for this functionality, with the following code recommend ...