Having difficulty creating a simple HTML menu, where one button is visible but the other is unresponsive despite having identical CSS styling

Looking to enhance my HTML skills as a beginner, I've begun building a simple website and am currently focusing on the menu. I created a "home" button (which is visually there but not functional), and then attempted to create another button next to it using different classes but applying the same CSS code. Why is the CSS class not being applied to the second button like it is to the first?

Snippet of HTML Code:

<div class="menu">
    <div class="HOME_menuButton">
        <p id="menuItem">Home</p>
    </div>
    <div class="LEWIS_menuButton">
        <p id="menuItem">Lewis</p>
    </div>
</div>

CSS:

.menu {
    background-color: #6699ff;
    width: 845px;
    height: 80px;
    margin-left: 305px;
    margin-top: 10px;
    position: absolute;
}

.HOME_menuButton {
    background-color: #ccb3ff;
    width: 160px;
    height: 78px;
    border: 1px solid black;
    border-radius: 5px;
    margin-left: 5px;
    position: absolute;
}

#menuItem {
    font-family: Verdana;
    font-size: 20px;
    font-weight: Bold;
    text-align: center;
    vertical-align: middle;
}

.LEWIS_menuButton {
    background-color: #ccb3ff;
    width: 160px;
    height: 78px;
    border: 1px solid black;
    border-radius: 5px;
    margin-left: 5px;
    position: absolute;
}

Answer №1

In HTML and CSS, an ID is intended to be unique. It should only be used once in order to maintain proper code structure.

It appears that your browser is having trouble with the duplicate ID #menuItem (which would be better suited as a class). Consider converting #menuItem into a class to resolve this issue.

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

Show a loading image after clicking on an image or button using JavaScript

I recently created an App using PhoneGap and JqueryMobile. Transitioning between multiple HTML pages by clicking on images seems to be causing slow loading times, leaving end users unaware of what's happening in the background. I am looking for a way ...

What is the best way to retain changes made to a checkbox that is used for email notifications?

Users on my website receive email notifications when someone comments on their profile or blog. To give users control over these notifications, I have created an email settings page with checkboxes that allow them to choose whether or not they want to rece ...

Passing a PHP variable through a URL using the GET method

I need to pass a value using the get method. The code snippet is as follows: <td><a href="cart-remove.php?id={$row['id']}" class="remove_item_link"> Remove</a></td> The value I want to send is stored in $row['id&a ...

The public link created by Github only displays the name of the repository

Hello, I am a newbie in the world of web development. After dedicating a week to practicing HTML, I decided to create a project based on my CV. However, when I attempted to host the HTML files on GitHub, I encountered an issue. Whenever I clicked on the ...

How can I extract information from an HTML table using AngleSharp?

Seeking a way to extract song data from a playlist on a music streaming website This table contains song information: <tr class="song-row " data-id="ef713e30-ea6c-377d-a1a6-bc55ef61169c" data-song-type="7" data-subscription-links="true" data-index="0" ...

Improper Placement of CSS in Google Chrome

I'm facing an issue with my login form that displays perfectly fine in all browsers except Google Chrome. In Chrome, it tends to get distorted more often than not. CSS * { margin: 0; padding: 0; width: auto; } body { background: #E8 ...

How can I resolve the issue with the HTML/CSS footer not functioning properly on Safari for iPhone in my mobile site?

Struggling with a mobile website issue here. The client wants text-based buttons/links at the bottom, so I added them in, but my skills with size percentages are a bit rusty. I need these buttons to line up horizontally and adjust their width accordingly ...

Tips for placing input fields beside one another in Bootstrap 3

How do I resize and align these 3 input fields in a small size within the modal window: <div class="form-group"> <label for="name" class="col-sm-2 control-label">Name</label> <div class="col-sm-10 inline-fields"> < ...

Is there a way to create a header that fades out or disappears when scrolling down and reappears when scrolling up?

After spending some time researching and following tutorials, I have not made much progress with my goal. The task at hand is to hide the top header of my website when the user scrolls down and then make it reappear when they scroll back up to the top of t ...

Embedding a CSS class within the primary class selector

Can someone help me with this HTML challenge? <div class="span3"> <div class="abc">code for first div</div> <div class="abc">code for second div</div> </div> I'm trying to hide the first "abc" division within th ...

Struggling to display the Three.js LightMap?

I'm having trouble getting the lightMap to show on my mesh. Here's the code I'm using: loader.load('model.ctm', function (geometry) { var lm = THREE.ImageUtils.loadTexture('lm.jpg'); var m = THREE.ImageUtils.loadT ...

Having trouble modifying a value in a form and submitting it to the following jsp page

I'm encountering an issue with changing the value in a hidden input element before submitting data to another JSP file (db.jsp) for processing. The value should be different depending on which button is clicked, but it always remains as the default va ...

Utilizing ElementRef in Angular 4 to close dropdown when clicking outside of it

I recently came across this helpful tutorial, but I'm having trouble grasping how it actually functions. Here's the code snippet I've incorporated into my TypeScript file: @Component({ host: { '(document:click)': 'onOuts ...

PHP HTML Decoding Unveiled

Dealing with HTML that appears like this can be challenging: <font color=3D=22=236EAED2=22 style=3D=22font-siz= e:13px;font-family:arial;=22><B>Some Info Here</B></font></= A></td></tr><tr><td><font ...

Improving efficiency of basic image carousel in Angular 8

In my Angular 8 app, I am developing a basic carousel without relying on external libraries like jQuery or NgB. Instead, I opted to use pure JS for the task. However, the code seems quite cumbersome and I believe there must be a more efficient way to achie ...

Arrange three div elements to create a layout that is optimized for different screen sizes

Is there a way to align these 3 divs as follows: pickup on the left, phone in the middle, and delivery on the right? I've browsed through similar alignment issues on Stack Overflow, but none of the solutions seem to work for my specific code. It' ...

Troubleshooting the issue of the background of element A not changing when hovering over element B, despite mouseleave not

Currently, I am attempting to modify the background of element A when mouseover event occurs on element B, and then revert it back to its original state upon mouseleave. It's worth noting that B is nested within A. Strangely, while the background colo ...

<p> The box is massive, and its size is a mystery to me

https://i.sstatic.net/xPoDz.png Why is the box around my paragraph tag so large? I suspect this could be why I am unable to move the <p> tag down with margin-top: 50px; .train p { margin: 0; font-size: 2.5vw; } <div class="train"> < ...

Retrieving selected options from a jQuery mobile multiselect for database storage

I'm currently working on extracting values from a select list in a jQuery mobile application. Here's the markup for my select element: <div data-role="fieldcontain"> <label for="stuff" class="select">Stuff:</label ...

Experiencing the AngularJS [$injector:modulerr] error message despite having flawless code

Despite having code that appears to be correct, I am consistently receiving an [$injector:modulerr] error when working with AngularJS. Check out the updated Fiddle here. I can't seem to figure out what the issue is. Could I be missing something obvi ...