What is the best way to align bullet points in CSS lists?

These bullet points in my list are not aligned properly, and I am looking for a way to make them even. I remember finding a solution before, but I can’t seem to locate it now. Any assistance would be greatly appreciated.

#div1 {
  border: black;
  border-style: inset;
  margin-top: 5em;
  text-align: center;
}

.div2 {
  border: blue;
  border-style: inset;
  height: 100%;
}

#salty {
  display: block;
  transform: rotate(90deg);
  width: 45em;
  height: 50em;
  margin-left: auto;
  margin-right: auto;
}

ul {
  list-style-position: inside;
  padding-left: 0;
  margin: 10px;
}
<div class="container">
  <div class="row">
    <div class="col-md-1"></div>
    <div class="col-md-10" id="div1">
      <p id="p1">
        <h1>My Cat Salty</h1>
      </p>
      <p id="p2">
        <h2>Salty is a floofball</h2>
      </p>
      <div class="div2"><img src="babysalty.jpg" id="salty" />
        <p id="p3"> This is my cat, Salty. </p>
      </div>
      <div class="div3">
        <ul>
          <li>Salty is a cat.</li>
          <li>This is a list item.</li>
          <li>This is a list item.</li>
          <li>Salty is fluffy.</li>
          <li>This is a list item.</li>
          <li>This is a list item.</li>
          <li>Salty also has a fluffy tail.</li>
          <li>This is a list item.</li>
</ul>
      </div>
    </div>
    <div class="col-md-1"></div>
  </div>
</div>

For some reason, the CSS code is not displaying in the post, so I have included a link to the JSFiddle below:

https://jsfiddle.net/dus0tLyt/4/

Answer №1

Adjust the styling of the ul element to display as an inline-block, while aligning the list items to the left.

.div3 {
  text-align: center;
}

.div3 ul {
  display: inline-block;
}

.div3 ul li {
  text-align: left;
}
<div class="div3">
  <ul>
    <li>Salty is a cat.</li>
    <li>This is a list item.</li>
    <li>This is a list item.</li>
    <li>Salty is fluffy.</li>
    <li>This is a list item.</li>
    <li>This is a list item.</li>
    <li>Salty also has a fluffy tail.</li>
    <li>This is a list item.</li>
  </ul>
</div>

Answer №2

To begin, make sure to properly close your <ul> tag by using </ul>.

The reason the <li> elements are not aligned evenly is due to the styling of the <ul> tag being set to text-align: center;. Consider changing it to text-align: left;

If you prefer to center the <ul> element, you can adjust the styling accordingly to achieve a centered look.

#div1 {
  border: black;
  border-style: inset;
  margin-top: 5em;
  text-align: center;
}

.div2 {
  border: blue;
  border-style: inset;
  height: 100%;
}

#salty {
  display: block;
  transform: rotate(90deg);
  width: 45em;
  height: 50em;
  margin-left: auto;
  margin-right: auto;
}

ul {
  list-style-position: inside;
  padding-left: 0;
  margin: 10px;
  text-align: left;
  max-width: 35%;
  margin: auto;
}
<div class="container">

  <div class="row">

    <div class="col-md-1"></div>

    <div class="col-md-10" id="div1">
      <p id="p1">
        <h1>My Cat Salty</h1>
      </p>
      <p id="p2">
        <h2>Salty is a floofball</h2>
      </p>

      <div class="div2"><img src="babysalty.jpg" id="salty" />
        <p id="p3"> This is my cat, Salty. </p>
      </div>

      <div class="div3">
        <ul>
          <li>Salty is a cat.</li>
          <li>This is a list item.</li>
          <li>This is a list item.</li>
          <li>Salty is fluffy.</li>
          <li>This is a list item.</li>
          <li>This is a list item.</li>
          <li>Salty also has a fluffy tail.</li>
          <li>This is a list item.</li>
        </ul>
      </div>

    </div>
    <div class="col-md-1"></div>
  </div>
</div>

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

Default modal overlay closure malfunctioning; encountering errors when manually managed through jQuery

A custom overlay has been designed and implemented. <div class="overlay modal" id="11"> <div class="background-overlay"></div> <div class="description"> <div class="hidden-xs"> <img src=' ...

Choose the content in the second column

Can anyone help me with CSS selectors? I've been trying to target the second .col_content element in my code to apply a specific background image, but I haven't had any luck so far. Adding a second class would be an easy fix, but I'm curious ...

Angular's table data display feature is unfortunately lacking

Below is a simple HTML code snippet: <div class="dialogs"> <div id="wrapper" > <p>{{createTestingConstant()}}</p> <ng-container *ngFor="let one of contacts"> <p>{{one ...

Ways to center Bootstrap panel in the middle of a webpage

Is there a way to center this entire panel on the web page? I could use some guidance with this. Does anyone have recommendations for a good book to learn Bootstrap design? <div class="panel panel-default" style="max-width:500px;margin-left:auto;margi ...

Need to conceal certain images in Isotope, but ensure they can easily be revealed when necessary?

I have a collection of various images on my website coded with isotope. My question is, how can I hide specific images that I don't want to display initially, but have them appear when needed? I have managed to create a "show all" list using the code ...

Fade or animate the opacity in jQuery to change the display type to something other than block

I am currently using display: table and display: table-cell to vertically align multiple divs. However, I have encountered an issue when animating the opacity with jQuery using either fadeTo() or fadeIn. The problem is that it always adds inline style di ...

How can I correctly link and open a PDF file in HTML without an extension provided in the filename?

Looking for some advice. I have a client project where there are PDF files uploaded to a file structure within a LAMP Stack, but the files do not have extensions. I need the browsers to recognize that these files are PDFs and open them accordingly. Adding ...

Having trouble retrieving the routeName as it consistently returns empty

I attempted to extract the routeName from the URL in order to apply a different class to the body's layout when on the /Category page. https://i.stack.imgur.com/J0hsp.png @{string classContent = Request.QueryString["routeName"] != "/ ...

Adjust the width of a textarea to expand evenly within its container when exceeding the specified width limit using CSS

I am currently attempting to adjust the size of this textarea proportionally. However, when I try to increase it beyond 100% width, it only expands to the right side. I have already experimented with using margin: auto and display: block but unfortunately, ...

Converting multi-dimensional array into a structured table format

Query about arrays: Here is the array structure I am working with: Array ( [0] => Array ( [0] => Project [1] => Time ) [1] => Array ( [0] => Google [1] => 2 ...

What is the interaction between CSS and URL fragments (the #stuff)?

Can URL fragments affect CSS behavior? For instance, let's consider a sample page at: http://example.boom/is_this_a_bug.html. You can view the code for this page on https://gist.github.com/3777018 Upon loading the page with the given URL, the element ...

How to align a button vertically centered next to a matInput using Angular Material

Is there a way to vertically center a button next to matInput in Angular material? The submit button appears too low compared to the "First Name" input field, as shown in the images below: https://i.sstatic.net/PZGAg.png https://i.sstatic.net/ZuxHc.png ht ...

Guide on how to enable the first dropdown menu item upon clicking in Bootstrap 5

I am using Bootstrap 5 dropdowns and have defined them as follows: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4a2825253e393e382b3a0a7f647b">[email protected]</a>/ ...

Adding data from PHP into a designated div element

update: After some trial and error, I managed to find a solution using jQuery and append() methods. From my PHP code, I created an array containing all the necessary information that I wanted to insert into the tab divs. I then encoded this array into JSON ...

Tips for showcasing an image on an HTML page

I am encountering an issue with my HTML page that includes a Button. When clicked, it is supposed to display an image using an Ajax call. The functionality works properly in Postman Rest Client. However, when accessed through a browser, it only shows raw ...

Tips for splitting a container of specific height into sections measuring 80% and 20%

I am working on a container with a fixed position that I want to split into two halves: 80% and 20% at the bottom. This is what I want it to look like: Click here to see the image. Note: The layout should adjust itself when the window is resized. You c ...

create a function that automatically assigns colors to table fields based on their values

I have a table that dynamically displays a field with the id complaint_status, which can have values of "PENDING" or "CLEARED". I need help to set different background colors for the field based on these values: GREEN for CLEARED RED for PENDING Is the ...

HTML integration of JavaScript not working as expected

My experience with separating files in HTML and JS has been positive - everything works smoothly when I link the JS file to the HTML. However, an issue arises when I decide to include the JS code directly within <script> tags in the HTML itself. The ...

Undefined will be returned if the data in AngularJS is not set within the $scope

I have developed a factory that contains a list of functions which are called when the state changes. On page load, I am calling dtoResource.rc1Step1DTO(). Although the function executes, when I check the result in the console, it returns undefined. Below ...

Arrange the header and input within a div using flexbox to achieve different alignments

I need help aligning the header section vertically and ensuring responsiveness. Using margin-top isn't fully responsive, so I want to align the header at the beginning of the input field.https://i.sstatic.net/w3xSP.jpg { margin: 0px; paddin ...