Using Flexbox to style an h2 heading and a button

I'm diving into React.js and flexbox, trying to center an h2 and a button in a flexbox layout. Despite using justify-content: center, margin: auto, and text-align center, I can't get the formatting right. I know I must be missing something, but I'm not sure what it is. Any tips would be greatly appreciated.

<header className={styles.header}>
<div className={styles.spacing}></div>
<div className={styles.logoaccount}>
  <img></img>
</div>
<div className={styles.spacing}></div>
<div className={styles.searchsearch}>
  <h2>Japanese</h2>
  <button>Search</button>
</div>
<div className={styles.spacing}></div>
<div className={styles.spacing}></div>
<div className={styles.spacing}></div>
<div className={styles.spacing}></div>
<div className={styles.filters}>
  <button className="location">Location</button>
  <button className="food-type">Food-type</button>
  <button className="rate">Rate</button>
  <button className="apply-filters">Apply-Filters</button>
</div>

*{
margin: 0;
padding: 0;
}

.header{
text-align: center;
}
.logoaccount{
width: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: auto;
}

.logoaccount > button{
border-radius: 5px;
}

.filters{
width: 75%;
display: flex;
margin: auto;
justify-content: space-between;
}

.filters > button{
width: 15%;
}

.searchsearch{
width: 50%;
display: flex;
align-items: center;
justify-content: space-between;
margin: auto;
}

.spacing{
height: 20px;
}

Here's what I'm seeing:https://i.sstatic.net/YHfWM.png https://i.sstatic.net/4RZwj.png

But I really want that second line with "Japanese" and "Search" to be perfectly centered. I've searched everywhere for a solution, but no luck so far. Thanks a lot!

Update: I added background color for clarity.

Answer №1

Have you attempted inspecting the webpage and using the Select Page Item tool (Ctrl+Shift+C) to check if the issue is visible? If not, like you previously did with .filters > button, experiment with adding the style width: 15% (or try other percentages such as 50%) to the .searchsearch > button. Alternatively, consider utilizing the filters style instead of the searchsearch one in the div's className as it may affect the functionality.

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

How to resolve a TypeError saying "Object(...) is not a function"?

I've been attempting to display material-ui tabs as a component on another page, but I'm encountering an error that causes the code to break when loading the page with this component. I've tried two different methods of rendering this compo ...

Retrieving the title property with the power of JavaScript

https://i.sstatic.net/cp7qK.png My journey into JavaScript is just beginning, and I'm currently immersed in a project that involves using facial recognition technology to detect emotions. While the software successfully detects emotions, I am struggl ...

Is the state set before handling other events?

When the asynchronous nature of setState() is in play, can we be certain that this.state accurately reflects the most recent value during subsequent events? For example, consider a simple counter with two buttons. One button increments the counter while ...

The Redux state is mysteriously showing as undefined within the component, despite the redux-logger confirming a successful dispatch with the expected values in the

As a newcomer to Redux, I am facing issues with accessing values from component props after fetching data from a backend service. Oddly enough, the correct values are visible in redux-logger under the payload and I can see a successful dispatch. Below is ...

Unable to eliminate hover underline on link

Struggling to remove the underline from all links globally in my NextJS project has been quite a challenge. I've attempted various methods, including CSS (by importing the globals.css file into _app.tsx) and through ChakraUI. The only solution that ...

Navigating through pages in a server component using Next.js

I am currently working on a project that involves implementing pagination using the NextJS 13 server component without relying on the use client. The goal is to ensure that when a button is clicked, new entries are added to the screen in a sequential order ...

What is the best way to incorporate a PHP file into an HTML file?

Below is the code snippet from my index.php: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Voting Page</title> <script type="text/javascript" src="js/jquer ...

Accessing JSON data from the Public folder in a create-react-app

I have a JSON file called ipAddress.json with the following content: { "ipAddress": "11.111.111.111" } To access this file, I placed it in an "ipAddress" folder within the public directory. So now the path is "public/ipAddress/ipAddress.json". However, ...

Utilize the power of PIXI.js to effortlessly convert your canvas into a high-quality image without encountering

I'm currently working on exporting the entire canvas as a PNG using PIXI.js within a React app that incorporates react-pixi. My version is 6.5 and I've been trying out the following code: // MyComponent.tsx <button onClick={exportImage} /> ...

Instructions for accessing and printing text from a nested ul tag with Selenium in Java

Hello everyone, I am currently learning about Selenium Automation and have created a website as shown below. Here is the HTML code: <!DOCTYPE html> <html> <head><title>Shop</title></head> <body> <ul> < ...

Matching utility types and themes in Tailwind CSS

I encountered an issue while trying to implement the Tailwind plugin in my project. It seems that a TypeScript error has occurred. I'm curious about the data types of matchUtilities and themes. Can someone provide some insight? const plugin = require( ...

Enhance the functionality of the Bootstrap navbar by enabling the slideUp and slideDown effects

I can't get jQuery's slideUp and slideDown methods to smoothly animate the Bootstrap navbar. When I tried using the slideUp method, the navbar only slid up a little before disappearing completely, and the same issue occurred with the slideDown me ...

oversized user interface selection container

When using semantic-ui for my search form with large input fields, I am facing an issue where the select option field does not adjust its size. I have followed the documentation but it seems like I might be missing something. Can someone help me figure out ...

Designing hover-activated submenus and ensuring they appear at the forefront

I am currently utilizing jquery to implement a dropdown submenu on hover action. Here is the structure of the code: <div id="menucontainer"> <ul id = "topmenu"> <li><a onmouseover="javascript:show('div_1');">menu_1 ...

What is the best way to pass a URL as a prop in Next.js without encountering the issue of it being undefined

Within my file (handlers.ts), I have a function designed to post data to a dynamic API route while utilizing the app router. This function requires values and a URL for fetching. However, when I pass the URL as a prop like this: http://localhost:3000/unde ...

Calculating the combined cost of items in the shopping cart

I encountered a small problem while working on my project. I'm trying to calculate the total price of all items in the cart by summing them up, but my mind is drawing a blank at the moment. Below is the code snippet I am currently using: const { ca ...

Tips for sending numerous forms simultaneously

There is an issue with my two forms that are submitting data. When I submit items to the cart, it only updates or inserts the quantity of the first item, not the selected item's quantity. Here is the Javascript code for multiple form submission: < ...

The required version of browserslist (^4.19.1) could not be located

Whenever I attempt to run create-react-app, I am encountering this error message. This issue occurs both in the VSC terminal and Command Prompt, and I have not made any changes to my computer settings. Subsequently, I received the following error message, ...

Formatting Outlook HTML Signatures

I'm currently designing an HTML email signature for Outlook, but I'm having trouble with formatting and ensuring it looks consistent across different devices. When I preview the HTML in my browser, it appears exactly as I intended. However, I am ...

Elusive Appearance of the Flask Flash Message

I have developed a web application using Flask that allows users to upload files to an S3 storage. However, I would like to enhance the user experience by showing them the progress of their file uploads in real-time. To achieve this, I am utilizing Flash t ...