Aligning a list in the center without adding any indentation

So, I have this list that I want to center using some CSS magic.

I did some searching and found a solution to remove the list style and left margin. But I really want to make sure it's perfectly centered, so I added text-align:center;. However, I noticed an indent issue that prevents it from being exactly in the center like I intended.

If you need to see an example, check out tst.burngames.net

Apparently, code is necessary when describing websites..

This is my HTML:

<body>
    <div id="search">
        <input id="search_input" placeholder="Search for game.">
        <ul id="search_list">
            <li>
                One
            </li>
            <li>
                Two
            </li>
            <li>
                Three
            </li>
        </ul>
    </div>
</body>

And here's my CSS:

body {

    background: url(../images/fire.png) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

#search {

    background-color:white;
    border-color:black;
    border-style:double;
    border-width: thick;
    margin-left:auto;
    margin-right:auto;
    margin-top:auto;
    margin-bottom:auto;
    width:600px;
    height:100%;
}

#search_input {

    width:99%;
    height:50px;
    margin-top:20px;
    text-align:center;
}

#search_list {

    width: 99%;
    margin-left:auto;
    margin-right:auto;

}
li {

    list-style-type:none;
    padding-left: 0px;
    margin-top:10px;
    margin-bottom:10px;
    text-align:center;

}

Answer №1

For illustration purposes, consider the following example:

HTML:

<ul class="stylish">
    <li>Sarah</li>
    <li>Mike</li>
</ul>

CSS:

.stylish {
    list-style-type: none;
    text-align: center;
    padding: 0px;
}

To see this code in action, check out this jsFiddle - http://jsfiddle.net/8NjfW/1/.

Update

To view a demonstration based on your revised code, visit this jsFiddle link - http://jsfiddle.net/APv9P/

Answer №2

Consider placing it inside a DIV element and aligning the DIV to the center.

Answer №3

The reason for the indentation appearing is due to the default document formatting set by the user agent style sheet. To remove this padding, simply include padding: 0 in your CSS for the element with ID #search_list.

#search_list {
    list-style-type: none;
    width: 99%;
    margin-left: auto;
    margin-right: auto;
    list-style: none;
    padding: 0;
} 

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

Maintaining the dropdown in the open position after choosing a dropdown item

The dropdown menu in use is from a bootstrap framework. See the code snippet below: <li id="changethis" class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown>LINK</a> <ul class="dropdown-menu"> <li id ...

Bootstrap 4 does not have the capability to include spacing between two columns

I'm encountering an issue with adding a gutter between 2 columns on my website layout. I have a row that needs to be 1280px wide (based on a reference resolution of 1366x768 with padding of 43px on each side of the page), containing two sections that ...

Is there a reason we are able to simultaneously assign the disabled and selected attributes to <option> elements?

What is the rationale behind permitting the simultaneous setting of disabled and selected attributes on <option> elements, knowing that their values will not be submitted to a server? I was surprised that I did not receive an error in VS Code when I ...

What causes the form to vanish when using the ngFor directive?

Whenever I use the ngFor directive within a form tag, the entire form seems to disappear. Does anyone have any advice on how to resolve this issue? <form #myforms="ngForm" *ngFor="let i of editaddress"> <div class="p-3 p-lg-5 border"> < ...

Changing the width of an SVG path from 0 to 100% using CSS

I have an SVG design of wires that I want to animate the width from "0 to 100%", but I'm having trouble achieving this effect. It's easy to do with a div element, but not with an SVG image. Below is my code snippet: svg path { animation: f ...

Utilizing CSS to place an image on top of the upcoming <div> container

My goal is to create a layout similar to the one displayed in the linked image. https://i.stack.imgur.com/7DSE9.jpg Currently, I am using Bootstrap 3 and my HTML markup looks like this: <body class="gray-bg"> <section class="white-bg"> <d ...

Ways to remove the line under a logo in HTML using CSS and Bootstrap

While working on a website design, I encountered an issue with the logo where it has a line of the background color under it. This is frustrating and affects the overall design. Does anyone have a straightforward solution to remove this line? I need someth ...

Utilizing Bootstrap 4 to ensure the final DIV is vertically stacked and fills the remaining space in the container

Having trouble creating a responsive layout using Bootstrap 4? Specifically, when two divs wrap vertically on smaller devices, the top div pushes the lower div down, exceeding the parent container. I want the lower div to fit within the container. How can ...

The linked list is experiencing issues with properly deleting nodes

I've run into an issue with a linked list I'm developing. The problem arises when I free the head node within a function - it works as expected within that specific function. However, when attempting to access my linked list from the main functio ...

What is the best way to supersede an inline CSS rule with an external file?

Is there a method to replace an inline CSS rule with an external stylesheet file? Review my HTML code: <div class="mydiv" style="background:#000"> lorem ipsom</div> I aim to modify the background color using CSS. Here is my CSS code: .mydiv ...

The ultimate guide to resizing a div using radio buttons!

I've managed to create a functionality that allows for showing and hiding a div based on radio button selection. However, I am facing an issue where the main div grows infinitely when the "yes" option is clicked multiple times, and shrinks to nothing ...

How can the seating arrangement be optimized for a seating chart and what is the most effective way to transition away from a traditional table structure?

Currently, I am attempting to create a dynamic seating chart on a webpage within an asp.net-mvc site using data retrieved from a database. Initially, I used a table to organize the grid layout of rows and columns, which resembled this structure: The datab ...

The code in the head section is not running as expected

I've been exploring the possibilities of using lambda on AWS in combination with api gateway to create a contact form for a static S3 website, all inspired by this informative blog post: https://aws.amazon.com/blogs/architecture/create-dynamic-contact ...

What location is most ideal for incorporating JavaScript/Ajax within a document?

Sorry for the seemingly simple question, but I would appreciate some clarification from the experts. When it comes to the three options of placing JavaScript - head, $(document).ready, or body, which would be the optimal location for ajax that heavily rel ...

Troubleshooting: Jquery show effects not functioning as expected

Currently, I am facing an issue where I am attempting to display a fixed div using the show function of jQuery. Although the show function itself is working properly, when I try to include an effect from jQuery UI, it does not seem to work as expected. Bot ...

Revisiting the Issue: Jquery Hover Effect Fails to Function in Internet Explorer

Can anyone provide assistance with this issue? The code snippet works perfectly in all browsers except for IE, where the menu does not fade in and looks unattractive. html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...

Can a function add elements to a list that is outside of its scope?

I am in the process of creating a function that can perform various calculations and then return the results to be stored in a list. Eventually, I will need to find the average of all these results. I am exploring whether it is possible to include the ca ...

Is there a way to prevent EasyTabs from automatically selecting the second tab?

I'm facing an issue with setting the default tab using easytabs. Currently, the second option is automatically selected as the default tab. Previously, I had successfully set the first tab (statistics) as the active tab but lost the file. Now, I am s ...

Effect of Active or Focus on the HTML <ul> element

Check out this example of a UL tag: <ul style="list-style-type:none; padding:5px ; border:solid 1px #666666;"> <li>I am waiting </li> <li>I am waiting </li> <li>I am waiting </li> <li>I am wa ...

Generating dynamic links in HTML

I've been stuck on this problem for a while now. What I'm trying to do is create a Django website that pulls in Twitch livestreams and displays them on different pages. It's a project I'm working on to learn how to use APIs in web appli ...