Confusion with CSS properties for text alignment and vertical alignment

Recently, I started working on a basic webpage to experiment with CSS since I struggle with it.

One issue I'm facing is with the navigation bar. Specifically, the text-align: center property in the .Item class and the vertical-align: bottom property don't seem to be functioning properly. When I try adding or removing these lines, I don't see any changes reflected on the page.

Can anyone provide insights into why these two parts are not working as intended? Thank you in advance.

Here is a snippet of my JSX:

<React.Fragment>
<div className ={classes.Logo}></div>
<div className = {classes.Bar}>
    <div className ={classes.Nav}>

        <ul className={classes.Item}>
            About
        </ul>
        <ul className={classes.Item}>
            Shop
        </ul>

    </div>
</div>
</React.Fragment> 

And here is a snippet of my CSS:

.Logo {
    width: 100vw;
    background-color: white;
    border-bottom: 1px solid black;
    height: 15vh;
  }

.Bar {
    width: 100vw;
    background-color: white;
    border-bottom: 1px solid #81d8d0;
    height: 5vh;
  }

  .Nav {
    width: 50%;
    height: 100%;
    margin: auto;
    border: 1px solid  red;
    text-align: center;
    vertical-align: bottom;

  }

  .Item {
    text-align:center;
    margin:10px;
    display: inline;
    border: 2px solid  black;

  }

Answer №1

.Logo {
    width: 100vw;
    background-color: white;
    border-bottom: 1px solid black;
    height: 15vh;
  }

.Bar {
    width: 100vw;
    background-color: white;
    border-bottom: 1px solid #81d8d0;
    height: 5vh;
  }
   .Nav {
    width: 100%;
    height: 100%;
    margin: auto;
    border: 1px solid  red;
    text-align: center;
    vertical-align: bottom;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
 .Nav ul{ 
    
    margin: 0px;
    padding: 0px;
}
.Nav li{
    display: inline-block;
    margin: 0 10px;
    padding: 0px;
    border: 1px solid red;
    text-align: center;
}
<React.Fragment>
<div className ={classes.Logo}></div>
<div className = {classes.Bar}>
    <div className ={classes.Nav}> 
        <ul className={classes.Item}>
           <li> About</li>
</ul>
  <ul className={classes.Item}>
           <li> Shop</li>
        </ul>  
    </div>
</div>
</React.Fragment>

Answer №2

Following your valuable suggestions, I managed to implement the following:

.Logo {
    width: 100vw;
    background-color: white;
    border-bottom: 1px solid black;
    height: 15vh;
  }

.Bar {
    width: 100vw;
    background-color: white;
    border-bottom: 1px solid #81d8d0;
    height: 5vh;
  }

  .Nav {
    width: 50%;
    height: 100%;
    margin: auto;
    border: 1px solid  red;
    text-align: center;
  }

  .Item {
    position: relative;
    text-align: center;
    margin: 0px 50px;
    display: inline;
    border: 2px solid  black;
    top: calc(100% - 30px);
  }

Additionally,

  <React.Fragment>
<div className ={classes.Logo}></div>
<div className = {classes.Bar}>
    <div className ={classes.Nav}>

        <div className={classes.Item}>About</div>
        <div className={classes.Item}>Shop</div>

    </div>
</div>
</React.Fragment>

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 React form data was sent to the Express backend, but upon receipt, it was

Currently, I am working on image uploading in my MERN app. I am utilizing the express-fileupload package for this purpose. The issue I am facing is that while sending an image from the frontend in FormData, the backend is receiving null values. Frontend c ...

Is there a way to retrieve the total count of the selected options using Autocomplete in material-ui?

Is there a way to show the total count of chosen options using the Autocomplete feature from material-ui? If so, how can I achieve this? Simply follow these steps: click on Open menu dropdown, open the Autocomplete, select your desired options, and you w ...

The enchanting world of CSS background scrolling animations

I am currently developing a website where I have split the hero/header into two sections - one on the left with information and the other on the right with a graphic. I wanted to add a simple parallax effect to the image on the right side, so I used backgr ...

What is the best way to vertically align my image for perfect centering?

On one of my pages at , there is a section titled "FREE PICK UP AND RECYCLING OF LARGE QUANTITIES OF ELECTRONICS" with a picture of a truck. The image is perfectly centered vertically between the pictures on its left and right. Another page I have at fea ...

Tips for decreasing volume in react.js and node.js

React.js Challenge: I am facing difficulty reducing the quantity in my React code. What I want is for the quantity to decrease by 1 when a button is clicked. Here is a snippet of my React code: const [quantity, setQuantity] = useState(0) const handleDeliv ...

How can you turn off CSS3 animations for browsers that don't support them

Upon page load, a fade-in animation is applied to the main container. Although it functions properly in most browsers, it seems to have an issue in IE(9). Is there a method to identify if the user's browser does not support CSS3 animations and disabl ...

Navigating through a custom drop-down using Selenium WebDriver: Identifying elements within DIV, UL, and LI

I need assistance automating a custom drop-down field that consists of DIV, UL, and LI elements. Select class or CSSSelector are not viable options due to the dynamic nature of the field. <div id="boundlist-1092" class="x-boundlist x-boundlist-floa ...

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 ! ...

What steps should I take to resolve the issue when axios in React returns the error message "Unhandled Rejection (error): Network error"?

I've been developing a React Application that's running on localhost:3000. I'm attempting to fetch data from a .NET Core Application hosted at localhost:5001 using the axios library for making HTTP requests. Here's the function I' ...

Arranging HTML elements with jQuery - the existing script flips back and forth

I have created a code snippet on CodePen that showcases a feature of the website I am currently developing: http://codepen.io/barrychapman/pen/BzJGbg?editors=1010 Upon loading the page, you will notice 6 boxes. The first box is active, while the remaining ...

The CSS zigzag border functionality seems to be malfunctioning on Internet Explorer

On my clients website, I decided to use a zigzag css border instead of an image for speed purposes. I wanted to have different colors and variations, but I encountered a problem. While my version displayed correctly on Chrome and Firefox using Windows, it ...

the text input remains fixed in size and does not resize

Visit the page and scroll down to find a section located next to the "Directions" button that contains an input field. This input field allows you to enter an address and utilize Google Maps for navigation. One puzzling aspect is that regardless of what ...

Oops! Could not compile due to a syntax error: Invalid assignment expression on the left-hand side

I am currently developing an application that requires me to retrieve data from the backend containing a userdetail object. In my code, I need to set a current accessToken for the userdetail object: useEffect(() => { if (session?.user && ...

Customizing Paths in Express Handlebars

I have a query regarding setting up custom folders in Express.js Here's my situation: I need to implement logic where if a specific name is present in my database, the paths for CSS and JS files should be altered before rendering. By default, my pat ...

Sidebar collapse using Bootstrap

I have been working on creating a collapsible sidebar that pushes the content on the right, but I'm facing issues with responsiveness. When I display the sidebar, the content is getting compressed instead of pushed. I tried adding flex-shrink-0 to the ...

Show and hide a div with the click of a button

As I embark on rebuilding a website from the ground up, I find myself pondering how to achieve a specific functionality: My goal is for another view to appear when one of two buttons is clicked. How can this be accomplished? I attempted the following app ...

The fill layout in Next.JS Image isn't working properly

According to the Next.js image component documentation, it states: "When fill, the image will stretch both width and height to the dimensions of the parent element, usually paired with object-fit." However, in reality, the image fills the entire ...

Modifying the CSS will not be reflected in the appearance

Currently, I am facing an issue on a website where I cannot make any changes to the CSS stylesheet. Whenever I attempt to modify a style, it appears to work temporarily but then reverts back to its original state once I release the mouse. It seems like the ...

What could be causing the lack of functionality in crossmint integration?

Brand new to this platform and attempted to integrate crossmint into my website, but unfortunately, I encountered issues. Can anyone point out where I may have gone wrong? My contract is deployed on the rinkeby network. I am currently utilizing the rinkeb ...

Using Jest spyOn to test a helper method in ReactJS

Here is a helper method that I have implemented - import { FormFieldError, FormValidationRules } from "../../../types/form.type"; const isString = (value: any, fieldId: string, fieldName: string): FormFieldError | null => { // Check if field value i ...