Aligning the unordered list in the center to ensure the columns are also centered

I am having trouble figuring out how to make the pictures on my page move into another row when the page is resized past their width. I want each picture to have its own row without needing media queries. However, I can't seem to center them no matter what I try. I've experimented with different positioning options and even tried using HTML align="center", but nothing seems to work. You can view the website here. Additionally, when the page is in mobile state, there is no 10px padding at the bottom and the title "Singapore" is not floating as intended. Below is my current code:

    <html>
<head>
<title> Singapore - Home </title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<meta name="viewport" content="width=device-width, initial scale=1.0">

<style>
*  
{
  margin: 0;
  padding: 0;

}
body
{
  background: url('woodbackground.jpg');
  background-size: cover;
  min-height: 100%;
  min-width: 100%;
  position: relative;
  top: 0; bottom: 0; left: 0; right: 0;

}

#container 
{
  width: 90%; 
  margin: 0 auto;

}

h1 
{
  font: bold 65px Helvetica, Arial, Sans-serif;
  text-align: center; 
  color: #eee;
  position: relative;
  top: 60px;
}

h3
{
  font: 25px Helvetica, Arial, Sans-serif; 
  text-align: center; 
  color: #eee;
  position: relative;
  top: 80px;

}

ul#gallery
{
  list-style: none;
  display: inline;
  margin: 0 auto;
  position: relative;
  top: 175px;
  width: 1300px;
}

ul#gallery li a
{
  float: left;
  padding: 10px 10px 25px 10px;
  background-color: #eee;
  border: 1px solid #fff;
  -moz-box-shadow: 0px 2px 15px #333;
  position: relative;
  margin: 10px;
  text-decoration: none;

}

ul#gallery li a:hover
{
  position: relative;
  top: -15px;

}

ul#gallery li a img
{
  height: 150px;
  width: 250px;
  max-width: 100%;

}

ul#gallery li a p
{
  margin-top: 25px;
  text-align: center;
  color: #000;
  font: Helvetica, Arial, Sans-serif;
  text-decoration: none;
  font-size: 20px;

}
@media screen and (max-width: 640px)
  
{

ul#gallery
{
left: 2.2%;
width: 600px;
}
ul#gallery li a:hover
{
top: 0px;
}
}


</style>
<body>

<div id="container">

   <h1> Singapore </h1>

     <h3><i> Singapore is the worlds first machine that works </i>- Lee Kuan Yew </h3>

<ul id="gallery">

  <li><a href="#"> <img src="gallery.jpg" alt="gallery" /> <p> Gallery </p> </a></li>


  <li><a href="#"> <img src="facts.jpg" alt="facts" /> <p> Facts </p></a></li>


  <li><a href="#"> <img src="tour.jpg" alt="tour" /> <p> Tour </p></a></li>


  <li><a href="#"> <img src="author.jpg" alt="author" /> <p> Author </p> </a></li>

</ul>
<br/>
</div><!-- Container -->


</body>
<html>

If you have any suggestions or solutions, please let me know.

Answer №1

I've reviewed the link you provided and by just including text-align:center; in your container, you can center the uls since they are displayed as inline elements.

#container 
{
width: 90%;
margin: 0 auto;
text-align: center;
}

Answer №2

Instead of using the float property for those items, it is recommended to set them to display: inline-block. Then, you can apply text-align: center on the parent container.

Check out this example to see the difference: http://example.com/test/centered-items/

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

Interacting with server through HTML form submissions (GET and POST methods)

After reading a variety of resources and examples, I still feel like I'm missing a deeper understanding of the fundamental concepts behind server-side functions and their interaction with HTML. Recently, I was able to successfully manipulate an array ...

The functionality of reordering columns, virtual scrolling, and resizing the grid in jqgrid are not functioning properly

Implementing jqgrid with Symfony to display a datagrid has been a challenging task for me. Thanks to Oleg's insightful response, many of the major issues have been resolved. Below is a snippet of my code: <link rel="stylesheet" type="text/css" ...

What steps can be taken to increase the size of a div element?

Check out this Plunker for more information: http://plnkr.co/edit/wA6s1jgE1QuacGxhOeoP?p=preview I attempted to increase the size of the following code: <div class="pure-u-1 header"> <div class="header-buttons"> <b ...

The Vue component should trigger the display of data in a Bootstrap modal based on the row of the button that was

Here is a sample code snippet demonstrating how data is fetched from the database: <table class="table table-bordered"> <thead> <tr><th>User ID</th><th>Account Number</th><th>Accou ...

Display a checkbox reflecting the value stored in the database

I've been struggling with a section of my code where I want the checkbox in the last column to be checked if the corresponding value in the database is 1. However, something seems to be amiss with my code. Can anyone pinpoint what's wrong? It see ...

Utilizing HTML5 elements within CSS selector chains

Check out a live example here Modernizr has been successfully implemented; article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; } However, the styles are not rendering in IE8 and below even though t ...

React component rendering twice due to width awareness

In a React component that I've developed, I have utilized ResizeObserver to track its own width. Within this component, two divs are rendered with each having a "flex: 1" property to ensure equal width distribution. Under certain conditions, such as w ...

Prevent certain elements in Bootstrap navbar from collapsing

I am currently working on designing a Bootstrap navbar that features the navigation items on the left side and the social/contact icons on the right. My goal is to have the nav items collapse when needed, but have the social/contact items remain visible fo ...

Works well with Bootstrap but not compatible with other frameworks

Looking for assistance with a code within Bootstrap (HTML and CSS). I have been trying to create a dropdown menu (burger menu) following the Bootstrap Documentation, but I am unable to expand the burger menu (Dropdown). I have tested it on both Firefox an ...

Can one simply use Ctrl+C to copy an image in JavaScript?

I am experienced in obtaining selected text using JavaScript However, I am interested in exploring the option of retrieving the HTML of the selected node I have tried using something like document.getSelection().getRangeAt(0).commonAncestorContainer ...

Unusual behavior of leaflet maps in terms of size and tiling arrangements

Currently, I am in the process of integrating a leaflet map into my meteor-based website that utilizes blaze as its templating engine. I have encountered some peculiar issues regarding the map size and its behavior when dragging and zooming. The map init ...

Iterating through data to showcase vertical columns for a specific time span of 3 years, highlighting only the months with available data

If data has been available for every month over the past 3 years, I need it to be displayed in a specific format. You can refer to this example fiddle for reference: https://jsfiddle.net/bthorn/ncqn0jwy/ However, there are times when certain months may no ...

Ways to avoid the CSS on the page impacting my widget?

Currently working on a widget using JavaScript and avoiding the use of iframes. Seeking assistance on how to prevent the styles of the page from affecting my widget. Initially attempted building it with shadow DOM, but ran into compatibility issues with ...

Can bootstrap and all of its dependencies be imported in just one file?

Is it possible to utilize <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93f1fcfce7e0e7e1f2e3d3a6bda3bda2">[email protected]</a>/dist/js/bootstrap.bundle.min.js&qu ...

Utilizing JavaScript in Protractor, explore a list to identify the selected checkboxes and those that remain unchecked

Currently, I am working on developing an end-to-end test using Protractor. My main objective is to extract the names from a list and then determine which checkboxes have been selected and which ones haven't. To check the state of the checkbox, I pla ...

Adjusting visuals with the combination of mouse scrolling and a timer

Is there a way to automatically change images if the user doesn't scroll within 7 seconds? I currently have a code that changes images based on mouse scroll. <script> const imageContainer = document.querySelector('.image-container'); c ...

Encountering an issue in Angular 8 where a class is not being added after the page loads, resulting in an

Looking to dynamically add a class to a div element using Angular? I have a condition isTrue, and am utilizing the angular function ngAfterViewInit() to add the class hideOnLoad after the page loads when isTrue becomes true. Instead of traditional javascri ...

Tips for ensuring a webpage loads at a specific resolution

I recently created a website on my computer with a screen resolution of 1920x1020. However, when I view it on other machines with a 1366x768 resolution, the website appears distorted. Is there a way to set a fixed resolution for my website to ensure it l ...

JavaScript can be used to manipulate buttons and interact with them on a webpage

In my search for examples for my webpage, I stumbled upon a strange JQuery selector. Could someone please explain how this works and if I can use it to target unique indexed IDs in HTML? //The mysterious selector that puzzles me //What does "^" actually ...

Tips for aligning an icon vertically alongside text in Bootstrap 3

I've been attempting to center a Bootstrap glyphicon vertically in one column while aligning the text in another column. I've experimented with using tables and ghost cells (referencing Centering in the unknown). I'm hoping there's a so ...