organize multiple blocks in the middle of the page (html)

This code is unique and belongs to me.

<html>

<head><title>HOME||~All About EDM~</title>


</head>

<body >
<center><img src="edm1.jpg" alt="edm" width="950" height="250"></body></center>

<center>
<style type="text/css" >
ul
{
list-style-type:none;

margin:0;
padding:0;
overflow:hidden;
}
li
{
position:relative;
left:18%;
float:left;
}
a:link,a:visited
{


display:block;
width:200px;
font-weight:bold;
color:#272525;
background-color:#DF01A5;
text-align:center;
padding:10px;
text-decoration:none;
text-transform:uppercase;
}
a:hover,a:active
{
background-color:#272525;
font-weight:bold;
color:#DF01A5;
text-align:center;
}

</style>
</center>

<center>
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="genres.html">Genres</a></li>
<li><a href="photos.html">Photos</a></li>
<li><a href="info.html">Info</a></li>

</center>

</body>
</html>

I am struggling to center 5 blocks in a row, instead they align as columns. I have tried multiple methods but can't seem to achieve the desired layout. Any suggestions?

Answer №1

Have you checked out this coding example

The regular layout looks like this:

<head>
<title>HOME||~All About EDM~</title>

<style type="text/css"></style>
</head>

<body>
<img src="edm1.jpg" alt="edm" width="950" height="250">


<ul>
<li><a href="home.html">Home</a></li>
<li><a href="genres.html">Genres</a></li>
<li><a href="photos.html">Photos</a></li>
<li><a href="info.html">Info</a></li>
</ul>


</body>
</html>

Don't forget to include a doctype declaration as well.

Answer №2

The use of the center tag is not recommended in HTML5. It is better to utilize CSS for centering by using text-align: center;.

<div class = 'imgClass'>
    <img src="edm1.jpg" alt="edm" width="950" height="250">
</div>

...

.imgClass {
    text-align: center;
}

Answer №3

Centering images using text-align is not the best practice (refer to this post on center image alignment)

To properly center an image, it is recommended to either specify a specific width for the container div or set its display type to "block" (which you have done), and then set margin-left and margin-right to "auto", as explained in the referenced answer.

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

How can I use CSS to ensure that both cards and images are equal in size?

I am currently utilizing react, with Material-ui being used for the Cards. For the layout, I have implemented CSS Grid Layout for the Grid system. Presently, the structure looks like this: https://i.stack.imgur.com/0FDyY.png However, my desired outcome i ...

How to create a stunning pixel pattern overlay on a website section

I've been exploring how to add a pixel pattern overlay onto a website section similar to what's done on this site: (over the background video image at the top and the image in the bottom section). I'm sure it's a simple process, I jus ...

Using Angular and Typescript to Submit a Post Request

I am working on a basic Angular and Typescript page that consists of just one button and one text field. My goal is to send a POST request to a specific link containing the input from the text field. Here is my button HTML: <a class="button-size"> ...

Customize Link Appearance Depending on Current Section

Looking for a way to dynamically change the color of navigation links based on which section of the page a user is currently viewing? Here's an example setup: <div id="topNav"> <ul> <li><a href="#contact">Contac ...

Integrate CSS and JavaScript files into Node Express

I am facing an issue including my CSS file and JavaScript file in a node-express application, as I keep getting a 404 not found error. Here is the code snippet that I am using: 1. In server.js var http = require('http'); var app = require(' ...

Is there a way to extract the text from the inner div of an element using nightwatch.js?

I'm attempting to retrieve the content of a cell within a table, with the following CSS structure: <div data-testid="cellvalue_row-1_col-0" class="Table-cellContent" xpath="1"><span data-testid="tableCellCon ...

Having trouble deleting files in PHP?

I am presenting an HTML form below: <form action='delete.php' method='POST'> <table> <div class = '.table'> <?php $dir = '../uploads/store/'; $new ...

Quiz application utilizing MySQL and JSP technology

I've been developing a Web Application using JSP to host MCQ quizzes. The questions are stored in a MySql Database table called 'qna', with each question having 10 choices. My goal is to design the quiz so that each question appears on a new ...

What is the process for utilizing npm/yarn installations within a .Net Framework WebAPI project?

In my project, I utilize SCSS and would like to incorporate Bootstrap.scss in order to create a single class that inherits multiple Bootstrap classes. For instance: .myButtonClass { @col-xs-12; @col-sm-6 } This way, I can replace class="col-xs-12 col-sm- ...

Instructions for implementing this script in HTML and JavaScript: utilize the clone() function

I came across this code snippet here function displaytickets(){ var $panel = $('<div/>').addClass('col-xs-3 panel panel-default') $panel.append($('<div><h3 class="panel-title">Title</h3></div>&a ...

Having trouble getting CSS "::Before" to work in my HTML code - any solutions?

I've been struggling to make use of the ::before pseudo-element in CSS for a hover effect. Despite going through various tutorials on YouTube, I can't seem to get it to work properly. I'm not sure why this isn't working as expected. ...

Finding web page links from competition rankings using pattern matching

Challenge I am currently delving into the realm of natural language processing projects. Before diving in, I intend to explore existing works on datasets, particularly those organized on a leaderboard (refer to the "Three-way Classification" section). Ho ...

Create a simple carousel using only vanilla JavaScript, without relying on any external plugins

Currently, I am working on implementing a carousel using plain JavaScript without the use of any plugins. My goal is to have previous and next buttons that will control the sliding images. var firstval = 0; function ...

Some characters are not compatible with the CSS writing-mode feature

There seems to be an issue with the CSS writing mode not applying correctly to the symbol '№'. Here is an example: <html> <head></head> <body> <p style="writing-mode: vertical-lr;"> Номер № ...

What is the best way to send messages between different sections on the same page?

Basically, in the following code: <?php $hostname = ''; $username = ''; $password = ''; $dbn = ''; try { $dbh = mysqli_connect($hostname , $username, $password ,$dbn); //echo 'Connected to database'; } ...

Steps to open specifically the WhatsApp application upon clicking a hyperlink, image, or button

I need a code for my HTML website that will open the WhatsApp application when a user clicks on a link, image, or button while viewing the site on a mobile device. Only the WhatsApp application should be opened when a user interacts with a link on my webs ...

Text that appears automatically in an input field

I've searched high and low, but I just can't seem to find a solution that works for me. What I need is a way to automatically populate a HTML text field with default text when the page loads. This default text should ideally be a PHP variable and ...

Encountering a ModuleBuildError while setting up Tailwind CSS in Laravel 8

I am currently learning Laravel version 8 and encountered an issue while trying to install Tailwind CSS using the npm command. npm install tailwindcss@npm:@tailwindcss/postcss7-compat @tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9 Here is a detai ...

Header media query in CSS3 not functioning as expected

Currently, I have two separate style sheets for mobile and desktop versions. My intention is to default to the mobile style sheet. Upon examining my header, I have included the following: <link rel='stylesheet' media='all' href=&ap ...

Angular 17 | Angular Material 17.3.1: Problem encountered with Angular Material form field focus and blur event handling

I attempted to apply (blur) and (focus) effects to my mat-form-field input field, but it seems like they are not working properly on my system. Here is a code snippet that resembles what I am using: html file <form class="example-form"> ...