unordered list bullet points are not aligned properly

I have been attempting to utilize the following code snippet:

<ul style="text-align:center">
  <li> 1794 - born in Berkeley, UK </li>
  <li> 1821 - began his training as a doctor </li>
</ul>

However, I am facing an issue where the bullets and text are not aligning correctly. I have experimented with using divs, but it has not resolved the problem.

This is the current situation:

This is the desired outcome:

https://i.sstatic.net/Gq3U4.png

Answer №1

Check out this easy-to-use code snippet

ul {
  display: table;
  margin: 0 auto;
}
<ul class="list">
  <li class="list-item">1794 - born in Berkeley, UK</li>
  <li class="list-item">1821 - began his training as a doctor</li>
</ul>

Answer №2

To maintain the center alignment of the list on the page/parent element while aligning the list items to the left, enclose the ul tag in a block container with a style of text-align: center;, and specify the ul as an display: inline-block; element with text-align: left;.

Answer №3

Are you interested in this resource? https://codepen.io/anon/pen/WdyVPJ

Programming HTML

<ul class="list">
  <li class="list-item">1794 - born in Berkeley, UK</li>
  <li class="list-item">1821 - started medical training</li>
</ul>

CSS Styling

ul {
  text-align: left;
}

li {
  text-align: center;
}

Answer №4

One reason for this is the need to center the internal elements (<li>) while keeping the external element aligned to the left (<ul>)

<ul style="text-align:left">
    <li style="text-align:center"> 1999 - born in Sydney, Australia </li>
    <li style="text-align:center"> 2005 - started learning how to play guitar </li>
</ul>

To see the outcome, visit: https://jsfiddle.net/E2fgtqL8/

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

Unable to detect HTML special characters in the text

In my current task, I am facing the challenge of matching two URLs. One URL is retrieved from a MySQL database, while the other one is sourced from an HTML page. When comparing both URLs as strings using Regex, the result shows match.Success = false. Despi ...

Issue with IE7 causing rollover navigation blocks to disappear when hovering over content

While conducting browser testing on the website The website's top navigation menu includes rollover effects for building services, exterior services, and commercial categories. The CSS-triggered navigation works seamlessly in all browsers except for ...

What method does nosotroshq.com use to achieve the navigation effect when hovering over a menu item?

Seeking advice from skilled individuals familiar with JQUERY: Can anyone explain the technique used by nosotroshq.com in their top navigation bar? Specifically, how do they create the slow animation when hovering over "ABOUT US"? Any insights would be ap ...

Enhance your CSS link in Yii framework 2.0 by incorporating media printing capabilities

While working on Yii framework 2.0, I typically include a CSS file by adding the following code snippet to assets/AppAsset.php: public $css = [ 'css/style.css', ]; Upon inspecting the element in the web browser, I notice the following code ...

What are some creative ways to customize the appearance of a PHP email form body?

I need assistance in creating a PHP form that will generate an email with visually appealing formatting. Currently, when I receive the submitted form via email, it lacks aesthetic presentation. After implementing the following code snippet, this is how th ...

Executing jQuery on page update can be achieved by utilizing event handlers to trigger

I have implemented jQuery multi-select to enhance the user experience of my Django app's multiselect feature. Upon initially rendering my page, I included the following script to bind any elements with the class 'multiselect' to the jQuery m ...

Having trouble accessing data attribute value with PHP in jQuery

Currently, I am utilizing both Jquery and PHP. In my code, there is a text box which includes a "data attribute" (data-vals) value that I am attempting to pass using jQuery. However, the response I am receiving is always "undefined." I have included my c ...

Creating a scrolling list group in a single column that moves in sync with another longer column

When working with two columns in Bootstrap, such as col-4 and col-8, how can you ensure that a list-group stays fixed within its column and vertically aligned even when the content in the other column is scrolled down? Dealing with this responsively can b ...

I'm encountering a Parse error: syntax error, wherein the file unexpectedly reaches its end

I'm currently in the process of creating a personalized search engine that enables users to search using multiple fields. However, an error message stating "syntax error, unexpected end of file" keeps popping up, specifically on line 201 of my code, r ...

Steps for creating a login form that redirects to a website

Looking to improve the HTML code (reviewing changes) Still learning how to create a website, so there might be errors in the code. I'm using neocities.org as the platform. I tried customizing the HTML source but struggling with removing the white sp ...

Struggling to align the navigation content alongside the brand name in Bootstrap 4

Seeking assistance with positioning my navigation menu next to my brand name using Bootstrap. Below is the current code snippet: <nav class="navbar-expand"> <a class="navbar-brand" href="https://example.com" target="_blank">Brand</a> ...

Add a filter and set a background color on the rows in jqGrid

After analyzing the code and output in firebug, I can filter the td and assign a different background color based on certain conditions. Here is the code snippet: loadComplete: function() { var i, names=this.p.groupingView.sortnames[0], l = n ...

Scrollable Bootstrap cshtml table with custom column widths

I am currently working on creating a side-scrolling table using Bootstrap formatting. The challenge I'm facing is displaying the entire string from the dropdown selects (DropdownList) as the column widths are limited due to being encapsulated within b ...

Can CSS namespace attribute selectors be used with XHTML/HTML elements?

I am trying to customize elements that have the xlink:href attribute in XHTML, but I am facing some difficulties with it. Here is the code I tested: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/19 ...

How to implement a two-column layout within an IE contenteditable element

Currently, I am working on a contenteditable element that requires content to be displayed in a two-column layout. Users should have the ability to place the cursor anywhere within the text and move between positions using arrow keys. To achieve this, I a ...

When additional form elements are introduced following the execution of an AJAX and PHP script, they fail to get transferred

Utilizing AJAX to retrieve the selected element value from a dropdown menu and triggering a PHP script to generate input checkbox fields. Here is an overview: HTML <form method="post" action="liens_chra.php" name="Form" id="Form"> <label f ...

Tabs in React display tab content vertically below each other when switching between tabs

I am currently working on creating Tabs using react-tabs. The tab contents are being displayed one after another (on different tabs) as shown below Here is the code snippet: <Tabs className="tabs"> <TabList className="tab-heade ...

What is the best way to showcase a collection of images stored in a hard drive folder on an ASP.NET website?

Currently, I am in the process of creating a simple photo gallery website using ASP.NET and C#. At this moment, I do not have a dedicated server set up. Instead, I am utilizing the development server provided by Visual Studio when starting a new website pr ...

Tips for updating the content of a DIV element on a separate page

One question that often arises is how to change the content of a div element on a different page within a website. While it is common to use Ajax to dynamically update div content within the same page by fetching data from an external .html file, the proce ...

Is there a way to achieve a flex layout without having to modify the HTML structure?

I am working on achieving a specific layout using CSS: https://i.stack.imgur.com/xg7ZA.png This is the HTML structure I have and it cannot be altered, along with what I have managed to add with CSS. It's almost there but missing something: .conta ...