Use HTML5 and CSS3 to align text in the center of the page below the header

I am currently in the process of transitioning from using old HTML tables for styling to utilizing HTML5 with CSS. However, I am encountering some difficulties:

Check out my Codepen Demo

The issue I am facing is that the text aligns itself to the edge of the page instead of the header banner, which is where I want it aligned.

I have been unable to find a solution without resorting back to using tables.

Additionally, I noticed that the .article:nth-child(odd) CSS selector seems to be aligning odd elements to the left instead of the right, and I'm not sure why this is happening.

Any help or insights would be greatly appreciated. Thank you!

Answer №1

If you're looking to create a website with a fixed width, the best approach is to enclose your existing code within a containing div:

Simply wrap all of your current code within a fixed width div like so:

#Wrap{width:1024px;}

.

<body>
  <div id="Wrap">
    ...
    /* remaining content of the website */
    ...
  </div>
</body>

View Demo on CodePen


CLEAN EXAMPLE

HTML

<div id="Wrap">
  <div id="Head"></div>
  <div id="Body"></div>
  <div id="Foot"></div>
</div>

CSS

#Wrap{
  width:1024px; /*Specify your desired page width*/
  margin:0 auto; /*Center the wrapper horizontally on the page*/
}
#Head{
  width:100%; /*Take up the full width of the wrapper*/
}
#Body{
  width:100%; /*Take up the full width of the wrapper*/
}
#Foot{
  width:100%; /*Take up the full width of the wrapper*/
}

Answer №2

As an illustration

Check out this CodePen demo

.content {
     width: 800px;
}

In order to horizontally center the .content, you should specify a width. Additionally, consider removing

<div align="center">

since it is no longer supported in HTML5.

Answer №3

Your text occupies the same width as a header, but it contains an image that is slightly narrower than 100% of the site. To address this, you can adjust the width of the article by adding some styling like so:

.article {
   display: block;
   margin: auto;
   width: 900px;
}

See codepen Demo

Answer №4

To ensure the page looks visually appealing, it is essential to implement CSS for styling:

Check out the CodePen demo here


div {
  text-align: center;
}

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

Troubleshooting the sidebar pin-unpin problem using Jquery and CSS

I have created a single side panel that allows me to toggle between opening and closing the sidebar by hovering on it. I can also pin and unpin the sidebar by clicking on the pin image. Now, I want to open the sidebar onClick instead of onHover and remove ...

What is the best way to ensure that the button's left margin matches the left margin of the table at all times?

https://i.sstatic.net/qJwvE.png Hello there, I am currently working with HTML/CSS and I have managed to center a table on my page using the CSS class .tablecenter { margin-left:auto; margin-right:auto; } Following the table, I have placed a button: ...

passing commands from a chrome extension to a content script

I want to set up a hotkey that will activate a function in my content script. The content script (main.js) is run when the page loads from my popup.js file. I've included the command in my manifest.json and I can see in the console log that it is tri ...

Comparison of jQuery, AngularJS, and Node.js

I'm a beginner in web development and I have some basic knowledge: HTML - structure of websites CSS - design aspect JavaScript - for adding interactivity Now, what exactly is jQuery, AngularJS, and Node.js? Upon researching, I discovered that jQue ...

What steps should I follow to save an image from a URL onto my device?

Can anyone help me with an issue I am having while trying to download an image from Firebase? Whenever I click on the button, the image opens in the browser instead of downloading. The link to the image is from Firebase. Does anyone know what I am doing wr ...

Navigating a Bootstrap modal using arrow keys for scrolling - up and down

I attempted to address this issue by using the following code: // here, 'this' represents the modal $(this).focus(); Despite trying the above solution and even attempting to trigger a click event on it, I was unable to get it to work! UPDATE ...

Is it possible to display one division on top of another with a transparent opacity effect in HTML?

I'm struggling with designing web pages and currently working on a page on codepen.io using code from this link. <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1 ...

Unraveling XML with XSLT 2.0 to Remove Normalization

I need help with denormalizing XML using XSLT 2.0. Here is an example of the XML and the desired output. I am looking for assistance in creating the XSLT code to achieve this. Denormalization should only apply to tags that start with "Change" and leave ot ...

Tips for customizing the appearance of an HTML dropdown menu

Here is the code snippet: <select name="xyz" id="abc"> <option value="x">10/Page</option> <option value="y">20/Page</option> <option value="z">30/Pa ...

Include an arrow in a personalized horizontal scroll bar using Angular and HTML

After styling a horizontal scrollbar for my chartjs graph, I attempted to add arrows using material icons like <mat-icon>keyboard_arrow_left</mat-icon>. However, I am struggling to align them next to the left and right of the scrollbar. Can any ...

Applying jQuery .animate() to elements without specifying position: absolute

My goal is to create a website where clicking on an image triggers a dropdown menu. The jQuery method I'm using is as follows: function main() { $('#arrow').click(function() { $('.hidden').animate({ top: &a ...

The issue with the left border color not functioning in JavaScript

Attempting to alter the border-left-color property using this script is resulting in a Uncaught SyntaxError: Unexpected token -. Is border-left-color actually supported? Javascript function logoChange() { var description = new Array (); description[0] ...

Angular 8 can sometimes cause CSS to become disorganized upon page load

In the process of developing my angular project, I've integrated pre-designed HTML templates. Implementing lazy loading for page loading has led to an issue where the CSS appears distorted, as shown in the attached gif image. https://i.sstatic.net/7UZ ...

The overflow-x property causes the left side of the component to be cut off when scrolling

When the screen width is insufficient to display a component properly, I need it to be horizontally scrollable. However, when scrolling to the left after making it scrollable due to a smaller screen size, the left side of the component gets cut off and can ...

- Challenges with internal systems

I have a dialog window where I want to display a confirm dialog when clicking Cancel. To achieve this, I am creating a div element with some text that should be shown in the confirm dialog. However, the issue I'm facing is that the text intended for t ...

Is it possible to create a button on my website that, when clicked, sends data to my Python script?

I need some help with my project - I'm trying to figure out how to create a button on my website that, when clicked, will display a string in my Python terminal. Can anyone offer some guidance on how to achieve this? Thanks in advance! ...

Why does CSS work on Localhost but not on the server in IE?

I recently faced a bizarre issue. After designing a website using CSS3, I uploaded it to the server only to discover that most of the features are not supported by IE8, making the site layout unrecognizable. Even more strange was the fact that IE8 display ...

Python Automation with Selenium Web Scraping

I attempted to scrape the content of Crédit Suisse's page as an exercise. After creating this script, I encountered difficulties in retrieving the data. Initially, I suspected it may be due to an iframe issue or an AngularJS website structure, but u ...

What is the process for inserting a hyperlink onto an image within a query slider?

I am experiencing difficulties when attempting to add hyperlinks to the images in my slider. I have come to understand that images cannot be clickable in jQuery sliders, so I have tried the following in the HTML: <div class="wrapper"> <div class= ...