Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
Uanble to click elements - React

I'm trying to make a top nav bar, but for some reason I can't click any of the buttons inside my website.

import '../css/TopBarStyle.css'
import Logo from './Logo'
import { Outlet, Link } from "react-router-dom";


function TopNavBar() {
    
    return (
        <div className="container">
            <div className='logo-div'>
                <Logo />
            </div>
            <div className='navigation-buttons'>
                <button type="submit" onClick={() => {alert("Hello")}}>Home</button>
                <button>My Projects</button>
                <button>About me</button>
                <button>Contact</button>
            </div>
        </div>
    );
}

export default TopNavBar;

Update (css file added)

My css file:

.container {
    margin-top: 2%;
    height: 10vh;
    background-color: transparent;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.navigation-buttons {
    position: absolute;
    text-align: end;
    align-self: flex-end;
}

button {
    background: rgba(255, 255, 255, 0.315);
    font-size: 18px;
    font-family:Verdana, Geneva, Tahoma, sans-serif;
    color: white;
    padding: 15px;
    margin-right: 30px;
    border-radius: 12px;
    border: none;
}

button:hover {
    cursor: pointer;
} 

I can't see where is the problem with this. I'm using safari so I can't inspect my page to see the elements

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

most probably logo-div is on top of .navigation-buttons, you can press Ctrl + Shift + C in chrome to see what you're clicking on

remove position: absolute from ".navigation-buttons" if you don't need it or add z-index: 100 to it

about 4 years ago · Juan Pablo Isaza Report

0

I've tried your code and it is actually working (whenever I click the "Home" button, an alert box appears that says "Hello").

If it is not working for you, you may want to share the CSS file, so we all can check if there is a problem with styling (which can make the navbar behave differently).

AFTER EDIT

The main problem is that the buttons have a background: rgba(255, 255, 255, 0.315) which is basically white (so you can't see them if the background of the page is white too). Note that color:white will make text white as well.

You might want to change them to background-color: rgba(202, 227, 209) for example and to color:black. This way you'll have your navigation buttons with black text and light grey background.

Hope that helps!

about 4 years ago · Juan Pablo Isaza Report

0

import '../css/TopBarStyle.css'
import Logo from './Logo'
import { Outlet, Link } from "react-router-dom";


function TopNavBar() {
    
    return (
        <div className="container">
            <div className='logo-div'>
                <Logo />
            </div>
            <div className='navigation-buttons'>
                <button type="submit" onClick={(event) => {
                  event.preventDefault();
                  alert("button clicked");
                }}>Home</button>
                <button>My Projects</button>
                <button>About me</button>
                <button>Contact</button>
            </div>
        </div>
    );
}

export default TopNavBar;

You can avoid page reload by using preventDefault() function .

<button type="submit" onClick={(event) => {
                  event.preventDefault();
                  alert("button clicked");
}}>
Home </button>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!