Creating a clickable menu button with CSS

Currently, I am working on the menu for a mobile website. Instead of using an image, I have decided to create the menu button using CSS. However, I am facing an issue where only the first horizontal line of the menu icon is clickable, and I want the entire button along with a 10px padding around it to be clickable. Here is what I have tried so far:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Test website</title>
<style>
*,
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing:    border-box;
box-sizing:         border-box;
}
body,html {
margin:0;
padding:0;
}
.red-container{
    position:fixed;
right: 0;
top: 0;
left: 0;
width:100%;
background-color:#cc0000;
padding:0.5em 1em 0.5em 1em;
font-family: Arial, Helvetica, sans-serif;
color: #FFFFFF;
font-size: 1.8em;
font-weight:700;
}
.red-container:before {
    content: 'Page';
display: inline-block;
vertical-align: middle;
}
.right-menu-btn-wrapper{
    display: inline-block;
position: relative;
float:right;
padding: 0.1em;
vertical-align: middle;
background-color: #0000ee;
}

.white-menu-btn {
display: inline-block;
position: relative;
float: right;
vertical-align: middle;
padding-right: 0.5em;
cursor: pointer;
}
.white-menu-btn:before {
content: "";
position: absolute;
left: 0;
top: 0.25em;
width: 1em;
height: 0.15em;
background: white;
box-shadow: 
    0 0.25em 0 0 white,
    0 0.5em 0 0 white;
}
</style>
</head>
<body>
<!-- Red Header -->
<div class="red-container">
<a href="#" class="right-menu-btn-wrapper">
<div class="white-menu-btn">
</div></a>
</div>
<!-- END Red Header -->
</body>
</html>

Answer №1

Check out this link on CodePen

To make it work, simply include the link within a div element and specify its width and height.

.white-menu-btn {
display: block;
position: relative;
float: right;
height: 30px;
width: 30px;
vertical-align: middle;
padding-right: 0.5em;
cursor: pointer;
}

<div class="white-menu-btn">
      <a href="#" class="right-menu-btn-wrapper">
      </a>
  </div>

Answer №2

Make sure to include some content or a   in the empty div, and add padding for better spacing. It's also important to note that the border may go to the next line because of improper nesting. Consider switching to an unordered list with li's for a more organized structure.

.right-menu-btn-wrapper{border:1px solid red;}
.second-right-menu-btn-wrapper{border:1px solid green;}
<a href="#" class="right-menu-btn-wrapper>
<div class="white-menu-btn">
</div></a>
<a href="#" class="second-right-menu-btn-wrapper>second button
<div class="white-menu-btn">
</div></a>

Answer №3

Your HTML and CSS could use some clarity. You don't need to write so much code for the task you described. Here's a simpler solution for your problem.

Simply add this CSS style to your stylesheet:

.buttonNew{
width:100px;
height:50px;
padding:10px;
background-color:#fff;
color:blue;
}

Then, include this line of code in your HTML file:

<div class="red-container">
<a href="#" class="buttonNew">Button</a>
</div>

I believe this is the solution you were looking for.

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 table headers in the second table do not match the queryAllSelector

I've encountered an issue with my JavaScript snippet that displays a responsive table. When I use the snippet for a second table with the same class, the formatting gets messed up on mobile devices (try resizing your screen to see). It seems like the ...

Unable to automate the selection of a dropdown menu using Selenium WebDriver

I am currently utilizing http://www.makemytrip.com/ This is the HTML code. <div class="mrgnBot30 clearFix"> <span class="watch_icn flL"></span> <div class="widget_inner clearFix suggest_me padBot15 flL"> <h3 class="clearFix has ...

Design of list items using card elements

Struggling with creating a card list design. I want to use MDB5 (utilizing Angular and the MDB5 package - ) but here's the concept: Imagine a white page where within a grey background, there is a list of item cards. Each card consists of an image on ...

How to create a slideToggle effect for nested ul and li elements

Initially, everything was working fine until I put it through the W3C validator. After fixing the errors, now it's not functioning as expected. I have created a jsfiddle The setup involves nested ul elements being used as dropdowns, with headers tha ...

Tips for dynamically adding rows to an HTML table using Bootstrap, utilizing values from a dropdown list in .NET 5.0

1. Description: I am currently working on a project related to creating an invoice page. In order to fill the row data, I have implemented a dropdown selection (as I couldn't find a better alternative). However, I am facing an issue where selecting ...

How to access a particular tab in Bootstrap 5 using an external link

Is there a way to direct users to a specific tab upon clicking a link on another page? Check out the example below: <div class="products-btn"> <a href="products.html#pills-profile">view all</a> </div> On Pro ...

What is the process for modifying CSS in Laravel?

New to Laravel over here, currently working in Homestead. When I need to make changes to my CSS, I typically edit the app.scss file located in resources/assets/sass and then recompile the css with Mix using the command npm run dev. I'm not entirely ...

"Using Javascript to retrieve an element by its ID in the .action attribute is resulting

In my javascript file, I have an HTML document where I narrow down to the specific element I need using var element = html.getElementById(inputForm);. This successfully retrieves the following part: <form class="add" id="inputForm" action="/submit-form ...

Is it feasible to activate the calendar widget by simply clicking anywhere within the input field?

I've been working on a custom React component for a date picker, and I'm facing an issue. I want the calendar widget to open whenever a user clicks anywhere inside the input field, not just on the arrow icon. However, no matter what I try, the ca ...

Mirror the image horizontally prior to saving

I'm working on a camera web app that has filters similar to Snapchat. I'm currently facing an issue where the image is mirrored because I'm using the front camera. Is there a way to flip the image before downloading it? Thank you for your re ...

In the context of resizing elements within a scrolled div, CSS divs with margin auto may not always be perfectly centered

I am encountering an issue with centering divs within another div with overflow:auto; initially, all divs are centered using margin: 0 auto; however, when I use jQuery to resize the last div, a scrollbar appears (as expected) but the other divs remain in t ...

Stretching background images on iOS mobile devices

My background is causing issues on iOS devices by stretching only when there is content added to a page like this. However, it loads correctly on empty pages like this. I have tried adding background-attachment:scroll instead of background-size: cover to ...

Achieving full coverage of space with divs in a layout of 3 columns, with fixed widths and varying heights

Understanding this concept is best demonstrated through the image provided below. Notably, there are 3 divs aligned next to each other with a fixed width but varying heights. In the event that I introduce a 4th div, my preference would be for it to fit un ...

Requesting the user to repeatedly input their birth year until it is less than the current year

Can anyone help me figure out how to display a prompt until the user enters a birth year that is less than the current year? I've tried using a loop in my code, but I'm having trouble getting it right. Any assistance would be greatly appreciated. ...

I desire to showcase an image in place of using the input type = "file" option

I need assistance with a code I wrote, but I am unable to retrieve the value of the file field. <div class="image-upload" style="position: absolute; margin-top: -39px; margin-left: 376px;"> <label for="file-input"> <img width=" ...

Arrangement of bootstrap and CSS library in header has an impact on the styling of h3 Tag

After rearranging the order of the online Bootstrap and offline CSS library, I noticed an impact on the h3 element in my HTML document. To further clarify this conflict, let me provide more details. <link rel="stylesheet" href="https://maxcdn.boot ...

Obtaining <script> and <div> elements from Plotly with Python

Seeking advice on the best way to extract <script> and <div> tags from the HTML output generated by Plotly's offline client. Ideally looking for a built-in method, but open to creating a custom solution if needed. I have experience with B ...

Disabling the scrollbar within responsive media queries

After adding a vertical scrollbar to a text box in my main CSS due to long text, everything seemed to be working perfectly... overflow: -moz-scrollbars-vertical; overflow-y: scroll; ...until I encountered my media queries. Scrolling on a smartphone can ...

Filtering elements upon loading

I have successfully implemented data filtering on my website using data-filter. While everything is working great, I am interested in displaying items with specific attributes upon loading. For instance, I want to load only green objects by default inste ...

The active class consistently adds new menu options without removing the previous ones

I am facing an issue with my menu where the active class does not get added to the new menu item when clicked, despite being removed from the previous item. Below is the code snippet: <div class="row text-center" id="side-menu"> <nav> ...