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

Dimensions in Material UI

As I embark on my journey with Material UI components for React, I am facing the challenge of integrating pre-styled components into my project. I have noticed that some components appear too large in my layout due to excessive padding and margins. Curren ...

Bootstrap datepicker embedded within a modal will scroll along with the parent page, rather than the modal itself

I recently encountered an issue with a bootstrap template where I needed to incorporate a datepicker within a modal. The modal contains scrollable content, but when I clicked on the datepicker field and scrolled the page, the datepicker moved with the pa ...

What is the reasoning behind utilizing the "&" selector in CSS?

.navigation { position: fixed; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: translation: all ease 0.25s; &.expand { transform: translateX(0); } } JavaScript file: $(document).ready(func ...

After my data rows are filled, I add jQuery and CSS striping animations to enhance their appearance

Before any click, they have this appearance: Clicking on Sales in the business section reveals a drop-down select box. If I click on "Sales" and modify the text area, it will transition to grey. While the grey rows change accordingly, the black rows shoul ...

Implementation of multiple angular guards causing a crash on the page

I have been attempting to implement separate guards for distinct pages. Essentially, I am checking a boolean parameter to determine if a user is logged in or not. Below are the two guard.ts codes that I am using: export class IsAuthenticatedGuard implemen ...

Struggling to align an element in HTML when used in columns?

<div class="row"> <div class="col-lg-3 " style="border: groove;"> <p class="circle col-xs-1 center-block">01</p> <h3>trending courses</h3> ...

Is it possible to apply a tailwind class that fades or transitions into something else after a specific duration?

How can I achieve a transition effect from the bg-red-300 class to bg-transparent, or a different background class, over a 2-second duration? Do I need to use javascript for this effect? I would like an element to be highlighted and then return to its no ...

Step-by-step guide on achieving a radiant glow effect using React Native

I am looking to add a glowing animation effect to both my button and image elements in React Native. Is there a specific animation technique or library that can help achieve this effect? While I have this CSS style for the glow effect, I am uncertain if ...

Position the flex item adjacent to the initial flex item using wrap mode only if there is extra space

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <titl ...

What are the steps to modify the text color in WKWebView?

I've customized my ViewController to include a WKWebView, where I load my content from both .html and .css files. The result resembles a controller for reading books within the Apple Books app. do { guard let filePath = Bundle.main.path(fo ...

Is it possible to convert (HTML and CSS3 generated content for paged media) into a PDF format?

Would it be possible to convert a HTML document styled with CSS3 Generated Content for Paged Media into a PDF format? If such an application does not exist, what alternatives can I consider as the foundation for developing a converter? Thank you ...

Can anyone figure out why this code is not functioning properly? It seems to be targeting the body element and all of

Currently, I am utilizing jqtouch to create a mobile website. In addition to this, I am incorporating a gallery image slider into the website. However, I have encountered an issue where the images do not display when placed between <div id="project_name ...

Issues detected with Foundation Block Grid in small size setting

I created a React component to display a series of div elements on a page using the Foundation Block Grid system to control the number of divs per row. However, I am facing an issue where the number of divs does not change when switching to a small-sized s ...

Nested Divs in CSS

I'm really struggling to get a div to display under another div in the way they usually do. Currently, I am using MaterializeCSS for my layout setup: <div class="container valign-wrapper"> <div class="customClass"></div> &l ...

Switch between Light and Dark Modes effortlessly with just one button

I've created a code that effortlessly switches between light mode and dark mode with the press of buttons. However, I'm looking to combine these two functionalities into a single toggle button for ease of use. If anyone can provide insight on how ...

What is the method for inserting form control values into a QueryString within HTML code?

Struggling with passing HTML form control values into a QueryString for page redirection. While I can easily input static values into a QueryString and retrieve them using PHP's GET method, I am encountering difficulties when it comes to dynamic valu ...

The Google reCaptcha reply was "Uncaught (in promise) null"

When using reCaptcha v2, I encountered an issue in the developer console showing Uncaught (in promise) null message regardless of moving the .reset() function. Here is the console output: https://i.stack.imgur.com/l24dC.png This is my code for reCaptcha ...

The two items are not situated side by side

Trying to make my page responsive, but when I inspect and look into mobile view, the elements do not align next to each other like they do on desktop. https://i.sstatic.net/8WhxD.png I want the shopping cart icon and button to be positioned next to each o ...

Setting up a checkbox to accept either a 0 or 1 value from a database

I am trying to integrate an HTML table where each table data cell contains a drop-down menu and a checkbox. These elements are connected to a database table named "checkbox" which contains values of 1s and 0s. I want to dynamically display the check box as ...

When a selection element has a CSS box-shadow animation applied to it, it reverts to its default settings when expanded or clicked

A user notified me of an issue with a select element that has an animated box-shadow on it. I confirmed the problem on my work Windows computer, but unfortunately, I don't have access to a Windows setup at home for debugging. The select element in qu ...