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

Inject a list of titles into a pipe and randomize the items

I have a list of recipes on my website, with a "view more" button to redirect users to the full recipes page: <div class="recipes_list"> <ul> <li>Recipe 1</li> <li>Recipe 2</li> <li>Recipe 3</li> ...

Using JavaScript to manage form input values in React

I am currently coding a basic application using NextJS and bulma CSS. The snippet below shows the form I am working on: const MyPage = () =>{ const [firstName, setFirstName] = useState('') const [secondName, setSecondName] = useState('&ap ...

Creating a post request in Express.JS with an empty object

Currently, I am working with Express version 4.18.2. I have created routing and controller files along with an HTML form that uses the POST method. However, when I submit the form, I attempt to display the req.body object sent in the request through the co ...

Simple server using node.js and express to host an HTML file and associated resources

I am currently experimenting with frontend development and need a basic web server to quickly start projects and serve files. Specifically, I have one index.html file along with some css/js/img files. I decided to work with Node.js and Express for this pur ...

The script functions perfectly in jsfiddle, yet encounters issues when used in an HTML

I stumbled upon a seemingly peculiar issue with my script in jsfiddle: https://jsfiddle.net/oxw4e5yh/ Interestingly, the same script does not seem to work when embedded in an HTML document: <!DOCTYPE html> <html lang="en"> <head> & ...

JavaScript Array failing to transfer to PHP using AJAX

I've encountered a recurring issue with my code and despite searching for solutions, I can't seem to find one that works for me. The problem lies in trying to delete a specific row from a table based on whether the user selects a checkbox associa ...

Footer div is being covered by the page

I am currently working on a website built with "WordPress", and I have implemented a mobile footer plugin that is designed to only appear on mobile devices. However, I am encountering an issue where the page content overlaps the footer on phones. I attemp ...

Steps to convert HTML <li> elements into HTML <datalist> elements

In my HTML file, I have a list of objects within li elements that I would like to transfer to an HTML datalist within the same file. I am currently working on a Node.js Express framework application where the data within the li elements is coming from an S ...

Having difficulty loading the controller into my AngularJS module

I've been attempting to organize my angularjs controllers into separate files without success. Folder Structure: --public-- --js/controller/resturant.js --js/master.js --index.php Content of master.js angular.module("rsw",[ ...

After redirection to a new page, the Ionic-vue menu malfunctioned

I have developed a reusable header component named Header, which contains an IonMenu component for consistency across pages. The menu is associated with the IonRouterOutlet as per the documentation, but I am encountering an issue when navigating between pa ...

Leverage the sync function within the await .then("sync") method in JavaScript

If a synchronous function is called within the .then part of an asynchronous await .then, such as: await asyncFunc(...) .then(res => sendMSG(res)) .catch(err => next(err)); function sendMSG(res){ xyz } The sync function sendMSG i ...

When a container is styled with 'overflow-y: auto', it will display additional horizontal and vertical scrolling bars

I have two files, one HTML and one CSS. The HTML file contains the following code: <div class="app"> <div class="header"></div> <div class="main"> <div class="container_1"> ...

Tips on getting the bot to react to a single "event" mentioned in the sentence, without multiple occurrences

Things are a bit complicated, but here's an example to illustrate: I've set up this event: client.on('message', async message => { if (message.content.toLowerCase().includes("megumin")) { message.channel.send("W ...

Create a unique bar chart plugin using Javascript/jQuery that allows users to drag and drop data

My current project involves developing a custom bar chart generator that must meet specific criteria: Input fields for entering data to display on the chart The ability to drag and resize bars once the chart is generated I've conducted research and ...

Is it possible to use vanilla JavaScript scroll event with AngularJS framework?

I am attempting to track the window offset from the top of the document, but I am facing issues with jQuery scroll functionality. Can a vanilla JavaScript scroll event listener be used effectively within an Angular environment? app.directive('owlCaro ...

Creating Email Designs with Multiple Layers for Outlook Versions 2007 and 2010

I hope you're all having a fabulous Aloha Friday! I have a question regarding HTML emails, specifically in relation to Outlook 2007 and 2010. Currently, I am working on a project that involves layering a couple of PNG images on top of each other, wel ...

Using Selenium WebDriver in JavaScript to Extract Text from an Array

During my experimentation with Selenium webdriver in javacript, I encountered a challenge when trying to extract text from an array of WebElements (specifically cells within a table). The usual command getText() did not work as expected when attempting to ...

Having trouble converting Buffered Byte Array into Image in Browser

Hello there! I am currently facing an issue while attempting to generate an image from a buffered byte array. The reason behind this is that I need to transfer the image from the server to the client using JSON. Below is the code snippet in question: The ...

Working with JSON structure using Javascript

I successfully transformed an XML file into a JSON format, but now I need to manipulate the data in order to achieve a specific desired structure. Here is the Original format { "machine": "Hassia2", "actual_product_date": "08/24/2017", "holdi ...

I want to know how to move data (variables) between different HTML pages. I am currently implementing this using HTML and the Django framework

I am currently working on a code where I am fetching elements from a database and displaying them using a loop. When the user clicks on the buy button, I need to pass the specific product ID to another page. How can I retrieve the product ID and successful ...