Having trouble aligning navigation bar elements accurately in my ReactJS project

I am just getting started with react and I'm in the process of creating my own personal website. The current design of the navbar is shown below.

https://i.sstatic.net/2vPhy.png

I would like to update it to have a similar appearance to this:

https://i.sstatic.net/nbD62.png

Here is the code snippet from my index.js:

const Navbar = () => {
    return (
        <>
            <Nav>
                <NavbarContainer>
                    <NavLogo to='/'>Devang Mukherjee</NavLogo>
                    <MobileIcon>
                        <FaBars />
                    </MobileIcon>
                    <NavMenu>
                        <NavItem>
                            <NavLinks to='about'>About</NavLinks>
                        </NavItem>
                        <NavItem>
                            <NavLinks to='experience'>Experience</NavLinks>
                        </NavItem>
                        <NavItem>
                            <NavLinks to='skills'>Skills</NavLinks>
                        </NavItem>
                        <NavItem>
                            <NavLinks to='blog'>Blog</NavLinks>
                        </NavItem>
                        <NavBtn>
                            <NavBtnLink to="/contactme"> Contact Me</NavBtnLink>
                        </NavBtn>
                    </NavMenu>
                </NavbarContainer>
            </Nav>
        </>
    )
}

I am utilizing react styled components such as Nav,NavbarContainer,NavBtnLink,NavItem,NavBtn,NavLinks

export const Nav = styled.nav`
  background: #000;
  height: 80px;
  /* margin-top: -80px;*/
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;

  @media screen and (max-width: 960px) {
    transition: 0.8s all ease;
  }
`;

export const NavbarContainer = styled.div`
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 80px;
  z-index: 1;
  width: 100%;
  padding: 0 24px;
  max-width: 1100px;
`;

export const NavItem = styled.li`
  height: 80px;
`;

export const NavBtn = styled.nav`
  display: flex;
  align-items: center;

  @media screen and (max-width: 768px) {
    display: none;
  }
`;

export const NavLinks = styled(LinkS)`
  color: #fff;
  display: flex;
  align-items: center;
  text-decoration: none;
  padding: 0 1rem;
  height: 100%;
  cursor: pointer;

  &.active {
    border-bottom: 3px solid #01bf71;
  }
`;

export const NavBtnLink = styled(LinkR)`
  border-radius: 50px;
  background: #01bf71;
  white-space: nowrap;
  padding: 10px 22px;
  //margin-left: 222px;
  color: #010606;
  font-size: 16px;
  outline: none;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  text-decoration: none;

  &:hover {
    transition: all 0.2s ease-in-out;
    background: #fff;
    color: #010606;
  }
`;

Is there a way for me to adjust the spacing between "Blog" and "Contact Me" to match the second image, while keeping it responsive?

Answer №1

Implement flexbox in the NavbarContainer.

You can achieve this by using the following code:

export const NavbarContainer = styled.div`
  display: flex;
  justify-content: space-between;
  align-items: center;
`;

Answer №2

  1. Enclose NavLogo and MobileIcon within a wrapping div.
  2. Remove NavBtn from the NavMenu.
  3. Apply justify-content: space-between;

To view the outcome using .html & .css (excluding ReactJS), click on the following link:

postion-navigation-bar-element

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

Reasons Child Components in React Native & Redux Are Not Re-rendered with Every State Update

Within my React Native and Redux setup, I have a <NavigationCardStack/> component serving as the root. Whenever the state is updated, the redux-logger correctly displays the new state. However, after a state change, the child component fails to log ...

What is the process by which a create-react app functions without the presence of an index.html file

I am currently working on a React app that I believe is based on create-react-app, although I did not initialize it myself. Something interesting about this app is that instead of having an index.html file, it contains multiple index.js files. When I run ...

PHP and HTML form: The ultimate guide to sending emails through your website

Currently, I am in the process of learning PHP and attempting to send an email to myself using an HTML form. However, I am experiencing some difficulties. <form action="index.php" role="form" method="post" name="emailform"> ...

Detecting collisions between multiple moving objects in Three.js

Currently, I have several objects that are moving forward randomly using the following code: model.lookAt(position_x, 0, position_z); setInterval(function(){ model.translateZ(0.015); }, 10); However, I am facing an issue where these objects might cras ...

Encountering an error while trying to execute `$(document).ready(function() {}

Recently, I delved into the world of JavaScript, particularly Jquery. As I encountered the $(document).ready(function() {}); statement and added it to my code, I faced an issue when placing it within the header tag of my HTML. The script tag would display ...

Drawing SVG in ReactJS onto a non-existent canvas: A step-by-step guide!

In my React component, I have a render() function that renders the component. I want to include a <canvas> element with some SVG rendered onto it, similar to this example. However, including JavaScript directly in the render function's return is ...

How is it possible for the igx-expansion-panel to close when there is a nested angular accordion present?

Currently, I am faced with the challenge of closing the igx-expansion-panel within my Angular project. While everything functions smoothly with a standard panel, things get a bit tricky when dealing with nested angular accordion structures using igx-accord ...

Issue with declaring an interface in Angular 2/4

When working with Angular, it is common to declare an interface before parsing JSON data retrieved from a server. While this approach works well with small JSON structures, it becomes challenging when dealing with large files containing hundreds of key-val ...

small screen right-side navigation with Bootstrap 4

My goal is to have the logo image on the left and the navigation on the right for xs devices, and the logo in the center with navigation on the left for sm devices. However, I am facing an issue where the navigation does not align to the right on xs device ...

My script for retrieving the playlist is experiencing difficulties in calling upon the "btoa" and "item.slice" methods

Having trouble using the "btoa" method to encode the client id and client secret in base64, which are retrieved from the ".env" file. I've also attempted using the Buffer method but encountered an "invalid form" error with Buffer. Any assistance woul ...

Implementing template loading on page load with state in AngularJS

When my application loads, I want the nested view list-patents.htm to be displayed. The main navigation is on my index.htm, featuring two nav items: transactions and patents. If you click on patents, two sub-menu items will appear: list patents and add p ...

What is the best way to generate conditional test scenarios with Protractor for testing?

Currently, there are certain test cases that I need to run only under specific conditions. it ('user can successfully log in', function() { if(siteAllowsLogin) { ..... } The problem with the above approach is that even when sitesNo ...

Top button on my website fails to function

I followed a tutorial to add a "back-to-top" button, and it works on my JSFiddle but not on my live page. The button shows up in Safari but doesn't scroll up. Any ideas why? // Contact Form $(document).ready(function() { $("#contactfrm").submit(f ...

Identifying the user's location within the application and dynamically loading various Angular scripts

Currently, I am working on a large-scale web application using Laravel and Angular. In this project, I have integrated various angular modules that come with their own controllers, directives, and views. One challenge I am facing is the need to load diffe ...

Implement a feature in Vue.js where clicking a button changes the background color

I'm working on an app using VUE JS and incorporating various components. Within one of the components, I have a button that I want to change color when clicked. This button is responsible for selecting different items from a table, so I'd like i ...

The compatibility between Node JS and Vue JS front-end seems to be glitchy and

I am currently developing a Node JS backend application and Vue JS front-end. In order to authenticate users, I need to implement sessions in the API. For my backend server, I am using the following components: express (4.18.2) express-session (1.17.3) c ...

Resolved issue with fixed div flickering upon clicking link on Phonegap platform, leveraging Bootstrap

Upon attempting to click a link positioned at the bottom of the screen within a colored div using position:fixed;, I notice that the page momentarily flashes white before displaying the "new" page. Removing the fixed positioning allows the new page to load ...

javascript popup window with redirection functionality

Hello everyone, I need assistance with the code snippet below: echo ("<SCRIPT LANGUAGE='JavaScript'> window.alert('Successfully Updated') </SCRIPT>"); I am trying to redirect the page to my edit.php after c ...

Sinon - the ultimate guide to intercepting the save() function in a mongoose schema

Currently, I am in the process of writing unit tests for an API that utilizes MongoDB in conjunction with mongoose for database access. Within my codebase, there exists a model file that defines and exports a mongoose model as shown below: const { Schema, ...

Avoiding node_modules in Webpack 2 with babel-loader

After updating to Webpack 2, I've run into an issue with the "exclude" property in my "rules". It seems I can no longer pass "exclude" into "options". What is the correct approach to handling this now? Previously: { test: /\.js$/, loader: ...