Dividing an unordered list into two parts using HTML and CSS

Hey there, I've been struggling with this issue for two weeks now and I finally decided to ask for help.

My goal is to create a new line in an unordered list inside a div. Here's what I want:

Home Contact Us Education

FAQ Stores Services

However, my current code displays this instead:

Home Contact Us Education FAQ Stores Services

I've tried using methods like float and center, but nothing seems to be working.

Please help me out before I lose all my hair over this... Thank you!

Answer №1

Take a look at this pen:

http://codepen.io/anon/pen/qabZqm

This code snippet demonstrates the following:

HTML

<ul>
  <li><a href="#">Home</a></li>
  <li><a href="#">Contact</a></li>
  <li><a href="#">Us</a></li>
  <li><a href="#">Education</a></li>
  <li><a href="#">FAQ</a></li>
  <li><a href="#">Stores</a></li>
  <li><a href="#">Services</a></li>
</ul>

CSS

li {
  display: inline;
  list-style: none;
}
li:nth-child(4):after {
  content: "\A";
  white-space: pre;
}
/* style the A tag within the li */
li a {
  display: inline-block;
  margin: 10px;
}

The :nth-child(4) selector adds a pseudo-element that creates a line break (\A). Styling the A tag within the li is necessary for proper formatting as the LIs cannot be styled directly due to using display:inline.

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

Migration of Bootstrap Template to ASP.NET 4.5 Forms and Addressing Rendering Problems with Full Width Display

is a Bootstrap Template that I purchased and incorporated into my project. After migrating it to an ASP.NET 4.5 Web Forms setup, I encountered issues with the LayerSlider and Footer not rendering correctly in full width as they did on the original template ...

Can you explain the distinction between ng-init and ng-bind?

Here is a code snippet utilizing ng-init: <!DOCTYPE html> <html> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <body> <div ng-app="" ng-init="names=['Jani','Heg ...

Maintain the aspect ratio of an image using CSS and flexbox styling

I have a gallery of images that looks great on a full-size PC screen. However, when I resize it for viewing on a phone, the aspect ratio is not maintained and the images only stretch in width. Currently, this is how it appears: https://gyazo.com/a1f605bb4 ...

What is causing the action button in my MUI snackbar to occupy an additional line?

I'm currently learning how to use MUI and I'm struggling with a specific issue. The close button in my code is appearing on a separate line, but I want it to be on the same line as the word "again". I've tried experimenting with absolute pos ...

Impossible to create margins on both the left and right side

Check out this cool pen: http://codepen.io/helloworld/pen/BcjCJ?editors=110 I'm facing an issue where I'm unable to create both left and right margins around my datagrid. Only the left margin seems to be possible. Any suggestions on how I can f ...

Having trouble passing data between view controllers

In my AngularJS application, I have a table column in main.html that is clickable. When clicked, it should redirect to a new customer page with the value of the column cell as the customer's name. There is a corresponding service defined for the app m ...

Using PHP to send a JSON request via cURL

I am attempting to make a cURL request in PHP. The request I am trying to send is as follows: $ curl -H 'Content-Type: application/json' -d '{"username":"a", "password":"b","msisdn":"447000000001","webhook":"http://example.com/"}' http ...

Choosing Elements from Twin Dropdown Lists in PHP

I am currently working on building a dynamic drop-down menu where the options in the second dropdown depend on the selection made in the first one. The initial dropdown consists of a list of tables, and based on which table is chosen, the columns of that s ...

Can you explain what is meant by an "out of DOM" element?

I'm feeling a bit lost when it comes to DOM nodes and all the terminology surrounding them. Initially, I believed that the DOM consisted solely of what I could see in my inspector - nothing more, nothing less. However, I've come across functions ...

unable to detect image input type

My dilemma lies in trying to submit a form using an image input type. The ajax request works as expected, and I receive a response from my php script. However, I encountered an issue where the image button was not changing its image upon submission. Accord ...

Utilizing TypeScript to incorporate media queries into styled components theme

In my development project using styled components with React and typescript, I have set up a theme.ts file to define the variables that are used in my ThemeProvider to expose them across the application. Additionally, I have created a styled.d.ts file wher ...

Is there a way for me to customize the appearance of the Material UI switch component when it is in the checked

I am seeking to customize the color of the switch component based on its checked and unchecked state. By default, it displays in red. My goal is to have the "ball knob" appear yellow when the switch is checked and grey when it is not. This styling must be ...

How can one ensure a consistent way to enclose a text input/textarea within a div across all browsers?

Currently experimenting with the following CSS: .twrap { position: relative; display: inline-block; padding: 0; border: 1px solid red; margin: 0 0 26px 0; } Implementing it in the HTML like so: <div class="twrap"> <inp ...

The HTML <select> element is currently styled with a locked CSS, but I am looking to have it displayed with the default

Unfortunately, I am unable to make changes to the CSS file at this time. The current styles in the CSS file are as follows: font-size: 13px; padding: 6px 4px; background-color: rgb(238, 238, 238); border: 1px solid rgb(204, 204, 204); clear: both; margin- ...

Radio button value failing to display accurately

I seem to be encountering a problem with the radio buttons. I am pulling all the necessary information such as labels, components, etc. from JSON and displaying it on the view. For example, when I retrieve two values for the component of a radio button fr ...

Troubleshooting: CSS file not functional within nested routes of ExpressJS

I'm currently working on a notes app to enhance my skills in routing using express. There are two endpoints: "/notes" and "/notes/add". The "/notes" endpoint displays a page with a list of all the notes created so far. ...

Utilizing Unicode characters within the content of a pseudo element in data-content

Is there a way to include unicode in the data-content attribute using JQuery for pseudo element content? I'm having trouble with the correct formatting. How can I properly display unicode characters? Currently, all I see is &#x25BC;. a::after { ...

Using Javascript to move the cursor within an editable table before saving the row

I have a Javascript code where I can navigate a table using the up, down, and enter keys. It works perfectly, but I want to enhance it by allowing the cursor to move left and right within the same row. Is there a way to achieve this? I attempted implement ...

How to place a stylish font over an image and recreate hover effects

I am looking to place social media icons below an image next to the photo's title, including Facebook, Twitter, Soundcloud, and Instagram. I want these icons to rotate along with the image when it is hovered over. HTML <div class="polaroid-image ...

Trouble arises when attempting to include numerous Visualforce components on a single page

When using a visualforce component multiple times on a page, the hover function does not open any of the dialogs. The problem seems to be related to the ids but I'm unsure about how to resolve it. Below is an example of the code for the visualforce c ...