The presentation of CSS and JavaScript

I'm having trouble pinpointing the error within my .css file. Currently, my JavaScript content is displaying on the far left of the page instead of centered as I desire. Specifically, I want the address and contact information to be centered below the photo. As I am currently enrolled in a JavaScript course, I am limited to using only JavaScript for this task.

Where do you think the error lies - in the .css or .js file?

HTML:

<!doctype html>    
<html lang="en">    
    <head> 

        <meta charset="utf-8"> 

        <link href="css/armchair.css" rel="stylesheet"> 

    </head>

    <body>
        <!-- wrapper  section starts -->
        <div id="wrapper">            

            <!-- header  section starts -->
            <div id="header">
                <img src="images/header.jpg" alt="Armchair Logo" width="975" height="230" class="floatcenter">
            </div>
            <!-- header  section ends -->


            <!-- menu  section starts -->       
            <div id="menu">
                <ul>
                    <li><a href="index.html">Home</a></li>
                    <li><a href="newrelease.html">New Releases</a></li>
                    <li><a href="placeholder.html" >Special Selection</a></li>
                    <li><a href="contact.html" id="current" class="first">Contact</a></li>
                    <li><a href="placeholder.html">On Sale</a></li>
                </ul>
            </div>
            <!-- menu  section ends -->


            <!-- text section starts -->
            <div id="content"></div>
            &nbsp;<img src="images/viewcart.jpg" alt="" width="130" height="59" class="floatright" /> 

            <br><br>

            <img src="images/store.jpg" alt="Armchair Store" width="520" height="347" class="floatcenterb">

            <br><br>


            <div id="contact_details"></div>

            <script type="text/javascript" src="js/contact.js"></script>

            <br/>
        </div>

        <!-- footer section starts -->
        <div id="footer">
            <p class="bottom">Copyright &copy; 2012 JC Design | All Rights Reserved | <a href="#">Terms and Conditions</a></p>
        </div>
        <!-- foot section ends -->  

    <!-- wrapper section starts -->


    </body>
</html>

My .css file:

/*--------------Body-----------------*/

html {background-color: #e2e2e2}

body {
   color: #000; background: #fff;
   font-family: "Helvetica Neue",helvetica,arial, sans-serif; 
   font-size: 90%;
   text-align: left;
   width: 975px;
   margin-left: auto;
   margin-right: auto;
}


p {
   margin-left: 25px;
   margin-right: 5px;
   text-align: left;
   font-size: 110%;
}

// Add your unique changes here

...

My .js file:

//contact.js - custom script written by [Your Name]//

var Addre = new Array("7945", "Town Plaza", "Vancouver", "E5T 4J9","Canada");
var phoneNo = new Array("1-604-568-4938", "Toll free: 1-888-987-4738");
var eMail = new Array("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9df4f3fbf2ddfceff0fef5fcf4effff2f2f6b3fef2f0">[email protected]</a>");

// custom JavaScript modifications by [Your Name]

...

Answer №1

To center your contact information in the element with the ID of #contact_details, simply add the CSS rule text-align: center;:

#contact_details {
  text-align: center;
}

For a live demonstration using your code, check out this JS Bin.

According to Mozilla's Developer Network page on the 'text-align' CSS property:

The text-align CSS property specifies the alignment of inline content like text within its parent block element. It does not control the alignment of block elements themselves, only their inline content.

Initial value: start which acts as left if direction is ltr, or right if direction is rtl when not supported by the browser.

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

The Drop-down menu with carousel in Bootstrap is experiencing difficulties displaying its sub-menu items

I am currently facing an issue where the sub-menu items are hidden behind the content in a bootstrap carousel. Despite everything else working fine, this particular problem is causing a headache. JSFiddle: https://jsfiddle.net/Saneesh/pwmyvsw6/65/ Is th ...

Utilizing a custom handler for Jquery Oembed functionality

I always preferred using my own function instead of using $(document).ready() to dynamically load an embed from a URL. This is what I have tried: function insertVideo(target,url) { $("#"+target).oembed(url); return false; } Here is an example of ...

"Material-Table does not have the ability to insert a new row

Just started learning JS and React. I'm attempting to integrate Material-table with an add row button, but encountering issues where the added row is not reflecting. Every time I refresh the page, the rows are reset. I suspect there's a problem w ...

Converting MultiSelect Array from JavaScript to MySQL

I recently implemented a multiselect feature on the client side: <select name="country" data-placeholder="Choose a Country..." tabindex="2"> <option name="country" value="United States">United States</option> & ...

How to Access Values from Nested Arrays in JavaScript Without Using Specific Keys

I am currently working on a function that will return an object with certain keys omitted from a potentially nested structure within an array. While I came across a similar solution in another thread, it didn't quite fit my requirements. Below is the ...

Tips for changing the value of a TextField in React Material

I am faced with a challenge regarding a form that is populated with data from a specific country. This data is fetched from a GraphQL API using Apollo Client. By default, the data in the form is read-only. To make changes, the user needs to click on the e ...

Discovering the method for retrieving post parameters in Node.js

I am currently utilizing Node.js with Express and the httpAsyncClient library in Android. I have sent a request to Express using Post, including parameters. The request goes through successfully, but I am unable to retrieve the parameter in Post. I have ...

Guide to exporting HTML files within the build directory in next.js

Is there a way to export HTML files within the build folder in next.js? After exporting it, I noticed that it generated .js extension files instead of .html files. https://i.sstatic.net/VWG7N.png ...

Installing global confusion with NPM

npm install css-sprite --save npm install css-sprite -g I'm curious about the significance of these two commands. I understand that "-g" makes it global, but why is that important? And what does "--save" do exactly? ...

What is the technique for applying an image or texture to a specific section of a geometry in three.js?

In my three.js project, I successfully generated a sphere using SphereGeometry and applied a static color using MeshPhongMaterial. Now, I am looking to overlay an image onto the sphere in a specific area rather than wrapping it entirely around the object ...

Different approaches to transforming jQuery code into functional AngularJS code

I am a beginner in AngularJS and I'm looking to implement functionality for a login page similar to the one you see when you click the 'Forgot Password' link: Would it be more appropriate to use a directive instead of a controller for this ...

How can you transform the outcome of a TYPO3 repository search into a JSON format?

Is it possible to convert the outcome of a "findAll()" function on a Repository into a JSON object, make changes to specific properties in JavaScript, and then send it back to the Action, converting it again for use by the Action to persist it in the datab ...

Enabling or disabling a button dynamically in Ionic based on a conditional statement

I am looking to dynamically enable or disable buttons based on specific conditions. The data is retrieved from Firebase, and depending on the data, I will either enable or disable the button. For example, if a user passes the First Quiz, I want to enable ...

Find the element that contains a specific substring in its value using JavaScript

I am trying to find a way to count how many input fields with the class name "text" contain a specific value. document.getElementById('c_files').getElementsByClassName('text').length; Currently, this code counts all textboxes with the ...

Using a CSS style to modify a class based on another class at the same level in the hierarchy

I am working with a jQuery carousel that is adding an 'active' class to images within a div. Within the same div, there is also a span with a 'fade' class that has a CSS style of opacity: 0. Is there a way to change the CSS style of the ...

The absence of the iframe in ie8 is causing problems that cannot be fixed with relative positioning

On a website, I am integrating an external 2-factor authentication solution called Duo Web using their PHP and Javascript. It works smoothly on all browsers except for IE8. When the user passes the initial login screen, the 2FA login page loads, but the if ...

Executing a jQuery ajax request within a then callback

Trying to retrieve all the data through two ajax calls. Utilizing jQuery's ajax call for this purpose, but encountering confusion regarding execution order. Below is the problematic code snippet: $.ajax({ type: "GET", url: "/api/data", dataType: "jso ...

Issue with ng-repeat not rendering JSON data properly

Can someone help me understand why ng-repeat is behaving differently in my case? When I use ng-repeat with the jsonFile, it prints to the table as expected, but when I try using it with problems, it doesn't print anything. The JSON data is usually loa ...

Ways to avoid submitting based on the outcome of AJAX requests

When working on an ASP.NET MVC Project, I encountered an issue where I wanted to prevent a button from submitting if the result returned from an AJAX call was false. However, no matter what I tried, the button always triggered the submission. Below is th ...

Update CSS using onChange event with an array of values

I'm currently working on an app that allows users to select a color scheme from a dropdown form. The hexidecimal values associated with the selected color scheme successfully populate specific text fields as intended. However, I am facing difficulty i ...