How come the text is not centered when I use text-align:center; on my class "text5"?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Homepage</title>
    <link href="style.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <div class="logo"><h2>Header Logo</h2></div>
        <div class="navbar">
            <ul> 
                <li><a href="index.html">header link one</a></li>
                <li><a href="index.html">header link two</a></li>
                <li><a href="index.html">header link three</a></li>
            </ul>
        </div>
        <div class="text1"><h2>This website is awesome</h2></div>
        <div class="text2">This website has some subtext that goes here under the main title.It's a smaller font and the color is lower contrast
            <div class="button1">
                <div class="text4">Sign up</div>
            </div>
        </div>      
        <div class="placeholder">
          <div class="text3">this is  a placeholder for an image</div>
      </div>
    </div>
    <div class="container2">
        <div ID="text5"class="text5">
          Some random information.
        </div>
          <div class="box1" id="box1"></div>
          <div class="box2" id="box2"></div>
          <div class="box3" id="box3"></div>
          <div class="box4" id="box4"></div>
      </div>
    <div class="footer">
    Copyright © The Odin Project 2023
    </div>
    
</body>
</html>

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  .container {
    width: 100%;
    height: 45vh;
    background-color: #1f2937;
    position: static;
    display: flex;  
  }

 
  
  .footer {
    position: absolute;
    bottom: 0px;
    width: 100%;
    height: 10vh;
    background-color: #1f2937;
    color: white;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  .logo {
    font-size: 24px;
    font-family: 'Times New Roman', Times, serif;
    color: white;
    justify-content: space-between;
    padding-top: 15px;
    font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    padding-left: 200px;
    position: absolute; 
    top: 0;
  }
  
  .navbar {
    color:white;
    font-size: 18px;
    position: fixed;
    width: 85%;
    top: 0;
    right: 0;
    margin: auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-direction: row;
    padding-top: 15px;
    padding-right: 330px;
  }
  
  .navbar ul li {
    list-style: none;
    display: inline-block;
    margin: 0 20px; 
    text-decoration: none;
  }
  
  .text1 {
    position: relative;
    color: white;
    padding-left: 200px;
    font-size: 48px;
    font-weight: bold;
    width: 720px;
    top: 100px;
  }

  .text2 {
    position: relative;
    color: white;
    font-size: 18px;
    width: 400px;
    height: 200px;
    top: 300px;
    right: 520px;
  }


  .placeholder{
  position: relative;
  width: 500px;
  height:250px;
  background-color: grey;
  border: 2px solid grey;
  display:flex;
  top: 100px;
  right: 120px;
  align-items: center;
  justify-content: center;
  color: white;
  } 

  .button1{
    border-radius: 5px;
      position: relative;
    display: flex;
    font-weight: bold;
    border: 2px solid #3882F6;
    background-color:#3882F6;
    height:40px;
    width: 120px;
    justify-content: center;
    align-items: center;
  } 

  .container2{
    height: 45vh;
    background-color: white;
    position: relative;
    padding-top: 30px;
    display: flex;
    flex-direction: row;
    justify-content: space-evenly;
  } 
 
   #text5{
    font-size: 36px;
    font-weight:800;
    text-align: center;
  } 


  #box1, #box2, #box3, #box4{
    position:relative;
    border: 2px solid #3882F6;
    height: 100px;
    width: 100px;
    bottom: -100px;
    right: 250px;
    border-radius: 25px;  
    flex: 0 0 100px;
  }

  

I'm facing an issue with class="text5" in my HTML code which doesn't seem to move the text towards the center when I use text-align=center. I believe this is related to Cascading as I've tried setting a width and using margin: 0 auto but the text didn't align correctly and affected the spacing of other elements like boxes. Any suggestions on how to fix this?

Answer №1

Text5 is situated within Container2, a flexbox that determines the horizontal alignment of its elements.

Are you considering relocating Text5 from Container2? Maybe positioning it elsewhere?

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

Can a search engine algorithm be developed to display an iframe based on the keywords entered in the search query?

Is it possible to create a search engine algorithm in HTML, CSS, and JavaScript that takes keywords from a search bar input and displays the best solution (or solutions) through iframes? html, css, javascript Below is the code for the iframes and search ...

Implementing a class change to anchor elements when rearranging them

I have 4 divs and their corresponding anchor tags. The active class is dynamically added to anchors on scroll unless the order of the display elements changes. In that case, active classes are only applied to the sorted elements. I also sorted the nav anch ...

Visual Latency when Quickly Toggling Between Images in Succession

I have a series of 50 images that need to be displayed sequentially inside a div. The time interval between displaying each image is initially set at 750 milliseconds and decreases with each subsequent image. To ensure all images are loaded before the an ...

What is the reason for jQuery displaying undefined when attempting to retrieve a custom data attribute using .prop()?

In my dynamic HTML generated by JavaScript, the following code snippet is included: $(".task-status").live("click", function () { alert("data-id using prop: " + $(this).prop("data-id")) alert("data-id using data: " + $(this).data("id")) ...

Snap to the top of the table with merged columns using scroll feature

I am currently attempting to create a table with horizontal scrolling and snapping behavior for the yellow header columns that span multiple columns. These headers should snap to the end of the red column, while always maintaining alignment at the beginnin ...

Unable to use .click function to choose image within container

Apologies for the lengthy post, but I believe providing all details is essential to understanding the issue at hand. The following code snippet is intended to display the first image in a pop-up box when a user clicks on any of the images shown: <div ...

Sliding through HTML content

Unfortunately, I lack expertise in advanced HTML and CSS. After some investigation, I attempted to create a "content slider" similar to the one on the Redlight Traffic website (an anti-human trafficking organization). However, my efforts have been unsucces ...

Creating a interactive navigation bar with External JSON data in HTML and JavaScript

Is there a way to create a dynamic MenuBar by using an external JSON file? How can I write HTML code to fetch and display JSON data dynamically? What is the process for reading a JSON file? //JSON File = Menu.Json {"data": [{"id": "1", "text": "F ...

Revolutionizing Zen Cart with slimMenu

Is there a smarter person out there who can help me understand why the slimMenu is breaking when I add these files to the bottom of the page? <link href="includes/templates/westminster_new/css/age-verification.css" rel="stylesheet"> <script src=" ...

Transfer data from a div to JavaScript

Within a php file, there is a div in which an id and some data are returned. Take a look at the code: <div id="dom-target" style="display: none;" data-stuff="2017, 8, 20, 0, 0"></div> So, I am trying to retrieve the value of data-stuff and pa ...

Adjust image placement when resizing the window or rotating a mobile device

When the window is maximized or the phone is in portrait position, the magnifying glass stays in its place. However, when I resize the window or rotate the mobile phone, the position of the magnifying glass changes. I've tried using different units ...

Utilizing JSON and Javascript to dynamically generate and populate interactive tables

Here's how I've structured my JSON data to define a table: var arrTable = [{"table": "tblConfig", "def": [{"column": "Property", "type": "TEXT NOT NULL"}, {"column": "Value", "type": "TEXT NOT NULL"}], "data": [{"Property ...

Guide to generating a dropdown menu and linking it with data received from a server

I am completely new to Angular and recently received a project involving it. My task is to create a nested dropdown list for Json data retrieved from a server using Rest Api calls. The data contains a Level attribute that indicates the hierarchy level of ...

If you press Ctrl + F, the browser will disable the form search function

How can I prevent the form find browser functionality when pressing Ctrl+F, and instead focus on the element html? <div id='demo'> <form class="id5-text-find-form" id="id5-text-find-form"> <input class="search" placeho ...

The Bootstrap row snag causing text display issues

There seems to be a glitch when the first column has more text than the one next to it. Check out the screenshot provided for reference. Any suggestions on how to fix this issue in Bootstrap? Live Demo: https://jsfiddle.net/oLderkuo/ /* Latest compil ...

Faulty toggle functionality within a JavaScript-created accordion panel

HTML I'm looking to add a FAQ question within the div with the class "section-center" <body> <section class="questions"> <div class="title"> <h2>FAQ SECTION</h2> < ...

What is the best way to adjust the dimensions of a textfield in Vuetify by altering its width and height?

Is there a way to adjust both the width and height of the <v-text-field>tag? I attempted to modify it using .css, but it seems to only affect certain parameters, leaving large white spaces on my page. This is the method I have tried so far: <te ...

Tips for properly handling special characters in DOM elements

I'm encountering an issue while trying to set CSS based on a condition inside quotes. This is causing a syntax error for me. Can anyone provide assistance in finding a solution? <div> <span ng-class='{\' rdng-error-rate&bsol ...

immediate removal upon pressing the button

Struggling to remove data from a datatable when clicking the delete button for quick admin side action. My code isn't functioning properly, even after attempted fixes. Here's my code: <div class="table-responsive"> <table id="datas" cl ...

Using the CSS property 'clear' creates a significant gap in the layout

Using a div like this to clear space after floats: .clear { clear:both; } However, the formatting is getting messed up with extra space. Any ideas on how to fix it? Appreciate your help! ...