Ways to align list items in the middle of a webpage with CSS

Currently, I am working on a website and looking to create a customized list where the pictures act as clickable links. You can check out the website here.

My goal is to have the links adjust to align left based on the browser size, and also have the images resize accordingly. While I've managed to make it responsive to browser size changes, I'm struggling with centering the layout on mobile devices and certain browsers.

Below are the HTML/CSS snippets I am using for this task.

Thank you in advance for any assistance provided.

HTML:

<div class="home-page">
<ul class="tile">
<li id="one"><a href="http://google.com"><img src="http://www.skyvueranchalpacas.com/wp-content/uploads/2015/03/Alpaca-Test.jpg" alt="" /></a></li>
<li id="two"><a href="http://google.com"><img src="http://www.skyvueranchalpacas.com/wp-content/uploads/2015/03/Alpaca-Test.jpg" alt="" /></a></li>
<li id="three"><a href="http://google.com"><img src="http://www.skyvueranchalpacas.com/wp-content/uploads/2015/03/Alpaca-Test.jpg" alt="" /></a></li>
<li id="four"><a href="http://google.com"><img src="http://www.skyvueranchalpacas.com/wp-content/uploads/2015/03/Alpaca-Test.jpg" alt="" /></a></li>

CSS:

/* Home page Tiles
*/

/* styling for tiles */

.post-475 page type-page status-publish entry{
}

div.home-page{
margin: 0 auto;
padding: 0;
text-align:center;
}

.tile{
    float: left;
position: relative;
display: block;
text-align: center;
background: none;
font-size: 20px;
border-right: 1px solid #fff;
margin-top: 8px;
margin-left: -40px;
line-height: 1em;
padding-left: 10px;

}
/* individual tile */
.tile li{
position: relative;
display: inline-block;
text-align: center;
background: none;
font-size: 20px;
line-height: 60px;
padding:0 10px;

}
/* Image within List (before clicking) */
.tile li img {
max-width: 22em;
width: 100%;
height: auto;

}

Answer ā„–1

To align the <li> elements in the center, you only need to make a simple adjustment in your CSS for the .entry-content ul selector. Update it with the following code snippet.

.entry-content ul {
  display: flex;
  justify-content: center;
}

Answer ā„–2

Give this a shot:

.tile{
   /* float: left;*/
position: relative;
display: block;
text-align: center;
background: none;
font-size: 20px;
border-right: 1px solid #fff;
margin-top: 8px;
margin-left: -40px;
line-height: 1em;
padding-left: 10px;

}
/* individual list */
li{
position: relative;
display: inline-block;
text-align: center;
background: none;
font-size: 20px;
line-height: 60px;
padding:0 10px;

Try using li instead of .title li. Also, the float:left; declaration may conflict with the text-align:center; one.

Answer ā„–3

If your website's main <div class="home-page"> has a margin-left of 20%, it might be causing alignment issues with the rest of your content. To resolve this, you can implement a media query:

@media screen and (max-width: 40em){
    div.home-page{
    margin-left: 0;
    }
}

This solution may not have been extensively tested, but it should help center your elements effectively. Best of luck with your project!

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

Error: 'require is not defined' pops up while trying to import into App.js for a React App built with CDN links

My latest project involves a React App that showcases an h1 tag saying "Hello World" on the browser. Rather than utilizing npm, I have opted for CDN links to set up the application. The structure of the App consists of three key files: An index.html file ...

The alignment is off

<script> var myVar = setInterval(myTimer, 1000); function myTimer() { var d = new Date(); document.getElementById("demo").innerHTML = d.toLocaleTimeString(); } </script> <p text-align="right" id="demo" style="font-family:Comic Sans ...

Turn off the background color box with a single click

Whenever I click on a header menu item, the background changes along with it. Is there a way to prevent this from happening? https://i.stack.imgur.com/p6bJ9.png Take a look here ...

How can Bootstrap 5 vertical pills be utilized to showcase tab content in close proximity to the navigation link on mobile devices?

I am looking for a vertical pills layout that works perfectly on desktop devices, but I need it to be more compact for smaller screens. Specifically, I want the tab-pane text to display under each individual nav-link, not below the entire group of nav-pill ...

Guide on replacing the character "&" in PHP with ease

I am encountering an issue where some output on the page contains a space character written as "&nbsp;". I need to replace it back with a regular space. I attempted using str_replace("&nbsp"," ",$mystr) and even preg_replace("/(&nbsp;)/", " ", ...

React Icons and Browser Tab Alerts

Is there a way to incorporate notifications into my website's favicon when the browser tab is not in focus? My tech stack includes React, Material UI, and TypeScript. I assume this is a frequent requirement, yet I haven't come across a simple so ...

Extracting null data from web scraping using Python and Beautiful Soup

I'm currently facing challenges with extracting the correct values from a website that provides prices for Silver, Gold, Palladium, and Platinum. You can find the website here. Below is the HTML structure of the website: <div id="header-tab ...

My CSS code is not successfully positioning the items to the right, despite my best efforts

I'm currently working on a website project and facing an issue with aligning the text 'Axxon' to the left of the div-header-gradient class, and the a href positioned to the right of the header. However, my code doesn't seem to be workin ...

Ways to ensure that the height of a div remains consistent across all scenarios

Below is the code snippet, which utilizes bootstrap. I need to set a fixed height for a div that is populated dynamically from a database. The goal is to maintain the height of the div regardless of the content length. If the book title and description e ...

Text field auto-saving within an iFrame using localStorage is not functioning as expected

My goal is to create a rich text editor with an autosave feature using an iframe. Although each code part works individually, I am struggling to combine them effectively. View LIVEDEMO This graphic illustrates what I aim to accomplish: The editable iFram ...

Why is applying CSS on an li element using .css() in JQuery not functioning?

Hey there! Could you please review my code? I'm attempting to add a top position to the <li> element using a variable in jQuery, but I'm not sure how to do it. Here's the code: <script> $(document).ready(function(){ ...

Unable to use jQuery to delete class from an element

Here is the markup I am working with: <div class="row"> <img src="image.png" class="download-image regular-image" /> <div class="options"> <p>download</p> </div> <img src="image.png" class="download-image r ...

Transferring a unique Python object back and forth between Jinja2 and Flask

As a newcomer to Flask, Jinja2, and HTML templates, I am working on understanding how to transfer data between the controller and views. Currently, I have a calendar of events where each event is a hyperlink that uses url_for to navigate to a view with add ...

Updating the source content of an iframe in real time

Currently, I am working on a search result page. The scenario involves a login page redirecting to a homepage that consists of a dropdown menu, a textbox, a button, and an iframe displaying a table with user data (firstname, lastname, middlename). Upon sel ...

A numerical input field that removes non-numeric characters without removing existing numbers?

Currently, I have implemented the following code: <input type="text" onkeyup="this.value = this.value.replace(/\D/g, '')"> This code restricts users from entering anything other than numbers into a field on my webpage. However, I hav ...

The Angular checked functionality is not working as expected due to the presence of ngModel

Just getting started with Angular here. Iā€™m working on a checkbox table that compares to another table and automatically checks if it exists. The functionality is all good, but as soon as I add ngModel to save the changes, the initial check seems to be ...

What could be causing the issue with absolute positioning not functioning correctly?

I'm having trouble keeping my footer at the bottom of the page: body, html{position:relative;} footer{position:absolute;} Even when I use bottom: 0;, the footer doesn't seem to go all the way to the bottom. Is there anyone who can help me troub ...

Unable to access localStorage

I created a Plunker to store a value in localStorage: <!DOCTYPE html> <html> <script> localStorage.setItem('test', "hadddddha"); </script> </html> Then, I built a test page to retrieve the value from local ...

Tips for removing a row from a table

I've been working on a responsive data table where each time I click an add button at the end of a row, a new row is added with the add button turning into a delete button. Below is the code I've implemented: The Table: <table id="invoice_ta ...

Leveraging an external Typescript function within Angular's HTML markup

I have a TypeScript utility class called myUtils.ts in the following format: export class MyUtils { static doSomething(input: string) { // perform some action } } To utilize this method in my component's HTML, I have imported the class into m ...