Looking for a solution to align the header properly in your React app?

Struggling with aligning a header? The CSS property of the header is inherited from the app's CSS file. For example, in the image below, "Our Mission" is the header that needs to be left-aligned. Looking for some assistance here. You can find the app.js and app.css files in this CodeSandbox link: https://codesandbox.io/s/summer-hooks-527rx9?file=/src/App.js

https://codesandbox.io/s/summer-hooks-527rx9?file=/src/App.js

app.js:

import "./styles.css";

export default function App() {
  return (
    <div id="app">
      <img id="home-background-image" />
      <div id="project-header">
        <p id="project-exp">Test Site Name</p>
      </div>

      <div id="project-mission-header">
        <h2>Our Mission</h2>
      </div>
    </div>
  );
}

styles.css

#app {
  font-family: sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#home-background-image {
  width: 100%;
  height: 350px;
  background: url("https://png.pngtree.com/thumb_back/fh260/background/20201026/pngtree-futuristic-shape-abstract-background-chemistry-technology-concept-for-website-image_438818.jpg");
  background-size: cover;
}

#project-header {
  position: absolute;
  top: 100px;
  color: white;
}
#project-exp {
  font-size: 3rem;
  font-weight: 600;
  margin: 0;
}

#project-mission-header {
  width: 810px;
  justify-content: left;
}

Answer №1

Simply adjust the width to 100%

#project-mission-header {
  width: 100%;
  justify-content: left;
}

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

Adjust the size of H1, H2... tags based on their own specifications, rather than the surrounding element

I have run into a bit of a conundrum with my code and cannot seem to find the right solution. Here is what I currently have: <div id="bloquetexto4" class="bloquetexto"> <H2><b>TITULO</b></H2> <p>Texto bla bla bla.</p ...

Issues with Bootstrap offsetting columns within a fluid row

I am currently working on a fluid design layout, where I need to place form group elements inside the row-fluid with one specific condition - they must be aligned to the right side. <div class="row-fluid" style="background-color: #332619; color: #fff ! ...

Building a matrix of checkboxes

I am looking to design a grid of checkboxes that are displayed in columns, with 5 checkboxes in each column. <ul class="checkbox-grid"> <li><input type="checkbox" name="text1" value="value1" /><label for="text1">Text 1</lab ...

Styling the elements that are next to each other using CSS

Hey there, what if I have HTML elements structured like this: <div> <div>Name</div> <div><input type="text" class="check"> <div>Age</div> <div><input type="number" class="check"></div> ...

Error: Unable to access properties of an undefined value (trying to read 'type') within Redux Toolkit

Looking for help with this error message. When trying to push the book object into the state array, I encounter an error. Folder structure https://i.stack.imgur.com/9RbEJ.png Snippet from BookSlice import { createSlice } from "@reduxjs/toolkit" const ...

Setting values and options in Material UI AutoComplete and then assigning the selected value to an object when onChange event occurs - how can it be

I am working on a project where I have a brand object with the field cat_id. When the page loads, categories are loaded into an autocomplete select. My goal now is to set the value of category id as the value for a category option in the autocomplete, an ...

Guide on how to retrieve a clicked element

When I click on the <ul> inside this div, I want to retrieve the id="nm". <div id="suggestionTags"> <ul> <li class="nm">Commonwealth</li> <span class="cty"> x GB</span> <li class="hse">C ...

A guide on elegantly pausing for the completion of .map() function and generating fresh keys within the array[index]

I am currently working on generating an array with the following values: { name: 'John', age: 35, employer: 'ABC', paycheck: 5,000, last_paycheck: 4,900, change: 100 } // new array and initializing the array with these initial values: ...

Creating a CSS background that adjusts to fit any screen resolution

Hey there, I'm a beginner to all of this. I want my background image to adjust to fit any web browser resolution, regardless of the size. So far, I've come across this nifty little trick: html { background: url(images/bg.jpg) no-repeat center ...

Error encountered in React: Unable to read property 'preventDefault' of an undefined value

Within my React application, I have an onClick event that is triggered: onClick={this.selectedComponent} The function being called by the onClick event is as follows: selectedComponent = (e) => { e.preventDefault(); this.setState({ ...

Adjust the size of the Google custom search bar to suit your preferences

I am looking to adjust the height of the Google custom search bar, and while there are various styling options available through the Google custom search editor, none specifically cater to changing the height. Currently, the search bar includes top and bo ...

Implementing a custom focus effect for MuiLink

I am looking to customize the appearance of the focusVisible property for all the (material ui) Links in my application. I am aware that I can achieve this by: const useStyles = makeStyles(() => ({ focus: { backgroundColor: 'yellow', ...

it results in an error when attempting to deconstruct an object

Using a style object in a component <Temp styles={{fontWeight: 'bold', fontSize: '1.6'}} ...otherprops /> Encountering an error while deconstructing the style object Cannot read property 'fontSize' of undefined. The d ...

Selections made from the dropdown menu will automatically generate additional fields in the

The code I'm working with is too lengthy to post in its entirety, so here is the JSFiddle link instead: https://jsfiddle.net/c0ffee/pew9f0oc/1/ My specific issue pertains to this screenshot: Upon clicking on the dropdown menu, the options are visib ...

HTML: Dealing with issues in resizing and resolution with floating elements on the left and right using

Encountering some issues with the HTML code below when resizing the window: 1: The right bar suddenly drops down if the width is made too small. 2: The spacing between the content and the right bar expands as the window width increases. <style ty ...

Fluid design: prevent alteration in body width caused by vertical scrollbar

I have successfully implemented a liquid layout for my website by setting the body tag width to 100%. <html> <head> </head> <body> <div id="container"> some content </div> </body> body { mar ...

Error: Property 'blogCategory' is unreadable because it is undefined

Having trouble rendering blog posts from a json file in React const BlogPost = (props) => { const [post, setPost] = useState({ id: "", blogCategory:"", blogTitle:"", postedOn:"", ...

JavaScript animation is not functioning as expected

I created a div with the id of "cen" and gave it a height and width of 50px. $(document).ready(function() { $("#cen").animate({ height: 500px, width: "500px", }, 5000, function() { // Animation complete. }); }); Unfort ...

Having trouble getting my Leaflet map to display even after meticulously following the quick-start guide

I am experiencing an issue where the map is not displaying at all, leaving a blank space where it should be. Despite following Leaflet's quick-start guide, I have been unable to determine the cause of this problem. Here is the code that I currently h ...

Swap the content of one div with another div using client-side code only

Currently, I am in the process of developing my personal website. To enhance user experience, I have implemented a vertical navigation bar on the left side of the page. My goal is to replace the content of a specific div with content from other HTML files ...