Adjust the size of a menu by modifying its width

Hey everyone, I recently joined this website and I'm still learning how to code. My current project involves creating an off-canvas menu, but I've come across a few challenges. Firstly, does anyone know how to adjust the width of the menu when it's expanded? Secondly, is there a way to move the three-lined menu button to the right side of the screen instead of the left? Lastly, what's the best approach to adding sub-menus to the expandable off-canvas menu that appear on hover?

If you'd like to take a look at the HTML and CSS code, I have shared it on Jsfiddle: https://jsfiddle.net/ghbx6fmn

/*=====  SLIDE MENU  ======*/

/*----------  HIDE SELECT CHECKBOX  ----------*/

.toggle, 
.full-screen-close
{
display: none;
}

.full-screen-close
{
width: 100%;
height: 100%;
position: absolute;
cursor: pointer;
top:0;
left:0;
}

/*----------  TOGGLE OFF-CANVAS MENU  ----------*/

.toggle:checked + .container > .menu-container 
{
  margin-left: 70%;
}

.toggle:checked + .container > .content .full-screen-close
{
  display: block;
  background: rgba(0,0,0,.5);
}

.menu
{
padding-top: 24px;
}

.toggle-btn,
.close-btn
{
cursor: pointer;
}

.toggle-btn
{
font-size: 2.25rem;
}


.close-btn
{
float: right;
font-size: 1.5rem;
padding: 1.5rem;
color: #ededed;
}

.menu-container, 
.content
{
transition: margin 0.5s ease-in-out;
}

.menu-container
{
background: #2c3e50;
width: 40%;
margin-left: 100%;

float: right;
height: 100%;
position: absolute;

z-index:99;
}

.slide-menu i
{
margin-right: 1rem;
font-size: 1.5rem;

vertical-align: middle;
}
.slide-menu li a
{
color: #fff;
padding: 1.5rem;

font-size: 1.125rem;

text-transform: uppercase;
font-weight: 600;

display: block;

transition: background-color .5s ease-in-out;
}

.slide-menu li a:hover
{
background-color: #34495e;
}

/*=====  MEDIA QUERIES  ======*/
@media (max-width: 460px) {
.slide-menu li a
{
font-size: 0.875rem;
padding-left: 12px;
}

.slide-menu li i
{
font-size: 16px;
}
}

@media (max-width: 320px){
.slide-menu li i
{
display: none;
}
}
<html lang="en">

  <meta charset="utf-8" />
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <meta name="viewport" content="width=device-width, initial-scale=1" />
      <meta name="description" content="Off-canvas navigation menu Tutorial" />
<meta name="keywords" content="slide-menu, sidebar, off-canvas, menu, navigation" />
      <meta name="author" content="AcasA Programming" />
      <link rel="icon" href="../../favicon.ico" />


<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/right-slide.css" />

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />


  <body>

  <input type="checkbox" id="offcanvas-menu" class="toggle" />

  <div class="container">

  <aside class="menu-container">

  <div class="menu-heading clearfix">
  <label for="offcanvas-menu" class="close-btn">
  <i class="fa fa-times"></i>
  </label>
  </div><!--end menu-heading-->

<nav class="slide-menu">
<ul>
<li><a href="#"><i class="fa fa-home"></i>Testing 1</a></li>
<li><a href="#"><i class="fa fa-star"></i>Testing 2</a></li>
<li><a href="#"><i class="fa fa-folder-open"></i>Testing 3</a></li>
<li><a href="#"><i class="fa fa-cogs"></i>Testing 4</a></li>
<li><a href="#"><i class="fa fa-star"></i>Testing 5</a></li>
<li><a href="#"><i class="fa fa-folder-open"></i>Testing 6</a></li>
<li><a href="#"><i class="fa fa-cogs"></i>Testing 7</a></li>
</ul>
</nav><!--end slide-menu -->

</aside><!--end menu-container-->

<section class="content">

<label for="offcanvas-menu" class="full-screen-close"></label>

<div class="menu right">
<label for="offcanvas-menu" class="toggle-btn">
        <i class="fa fa-bars"></i>
        </label>
    </div><!--end menu-->  

  <div class="menu-options clearfix">

<div class="right">
  
  </div>
  </div>

  <div class="content-body">
  </div><!--end content body-->

  </section><!--end content-->
  
  </div> <!--end container -->
  </body>
</html>

Answer №1

Responding to:

I have a question about the three lined menu button. How can I move it from the left side of the screen to the right side?

Simply add this code snippet:

.toggle-btn {
    font-size: 2.25rem;
    position: absolute;
    right: 0;
}

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 hover effect seems to be disabled in the third-level submenu

I need help creating a dropdown menu that shows an image when hovering over a specific item. I have checked my CSS code and HTML structure, but the image is not appearing as expected when I hover over the "Afyon White" list item. Any ideas on how to fix th ...

Troubleshooting the problem of fast rotation and scrolling of text in the middle but slow movement at the end with

Currently, I am utilizing the jquery animate function for animating text while also aiming to rotate the text if a specific degree is passed. In order to achieve this, I have implemented the following code snippet: var leftCss = "-"+$('#mydiv'). ...

CSS hover effects are malfunctioning

Having an issue with hover in CSS. Attempting to create a menu bar using saved PNG files, each file within its own div. When applying a class name and hover modifier, it only works on the first element. As the pointer moves to subsequent elements, they are ...

Can a piece of code be created that generates the XPath for a specific element?

I'm interested in finding out if there is a way to automatically generate an XPath by simply selecting an element, eliminating the need for manual updates when changes occur in HTML files on websites. I welcome any suggestions or alternatives that can ...

Unable to precisely reach the very bottom of the scrollbar

When trying to move to the bottom of the scrollbar, I seem to reach a bit higher than the actual bottom. https://i.stack.imgur.com/Vt83t.png Here is my code: ws.onmessage = function (event) { var log = document.getElementById('log') ...

Guide on invoking a JavaScript function within a jQuery upon a specific event, such as clicking a hyperlink

I have a website page where I display some important information. However, I want to make this text hidden initially and only visible when a user clicks on a specific link or button. I attempted to achieve this functionality using the following code snippe ...

The PHP index is not being identified when accessed through the post method

I am delving into the world of PHP as a beginner and still learning the ropes. I tried to replicate a small script exactly from one language to another, but encountered an issue where the index from my HTML file is not being recognized in PHP. The tutorial ...

Customizing browser titles for various article pages on Joomla 3.2 for improved SEO performance

Is there a way to incorporate unique browser titles for various article pages? Additionally, I am seeking guidance on how to integrate distinct meta tags for different pages within a Joomla website... ...

``How can I prevent browser popups/tooltips from appearing when a user exceeds the maximum value in a number

Is there a way to prevent the tooltip from appearing on the image when a user manually enters a quantity that exceeds the maximum allowed? The tooltip pops up when the form is submitted, and I need to find a way to turn it off. It seems like this tooltip ...

Utilizing HTML snippets for AJAX integration

Let's dive in, I may be completely off track here. I am currently working with Wordpress. On a page I am creating an HTML select menu (Main Menu) with options that correspond to each page on the site. This menu is visible on the page. In addition, ...

Unexpected Error with Background Position Variable

Hello, I am attempting to create an animated background effect that moves up and down using the .animate() and .hover() methods in jQuery. Within my DOM, there is a div with id="#menu" containing a UL list where each item has a background positioned at dif ...

Alternating CSS Designs for Displaying Multiple Mysql Query Results

I have a website where users can search for a specific product in their location, and the site will display a list of results. if(isset($_POST['zip'])){ $qry="SELECT business_id FROM ".TBL_BUSINESS." WHERE zip LIKE '%".$_POST['zip&apos ...

Moving the sidebar from the app component to a separate component in Angular results in a situation where the sidebar does not maintain full height when the page is scrolled down

Within my Angular application, I have implemented a sidebar as a separate component. Previously, the content of the sidebar was housed within the main app component's HTML page, and it functioned properly by taking up the full height of the page when ...

I want to utilize a select drop-down menu for navigating between pages in my pagination, breaking away from the traditional method of using <a> tags

I have a select dropdown that is dynamically generated for navigation to other pages within the script. It lists the number of pages available for navigation. However, after selecting a page and loading it, the dropdown does not stay selected. I've tr ...

Can someone help me troubleshoot this issue with my code so that my website can open in a blank page using about:blank?

I'm currently facing an issue while trying to make one of the pages on my website open with an about:blank URL upon loading. Despite embedding the code in my index.html file, it doesn't seem to be functioning properly. Here's the code I&apos ...

The capability to scroll within a stationary container

Whenever you click a button, a div slides out from the left by 100%. This div contains the menu for my website. The problem I'm encountering is that on smaller browser sizes, some of the links are hidden because they get covered up. The #slidingMenu ...

What is the best way to utilize jQuery for deleting the final <li> within a <ul> element?

One of my web pages contains an unorganized list similar to this: <ul id="myList"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4</li> </ul> How can I target the last ...

The Nivo Slider is stealthily concealing my CSS Menu

Although this question has been previously asked, I am still unable to make it work with the solutions provided; The website in question is I have tried changing the z-index on all menu items to 99999, but they are still appearing below. <div id="sli ...

The width of a CSS border determines its height, not its width

When I try to use border-width: 100px; to set the horizontal width to 100px, it ends up setting the height to 100px instead. Any help would be greatly appreciated. .border-top-green { border-top: 1px solid #4C9962; border-width: 100px; padding-t ...

Optimizing CSS for printing with margins and overflow

After stumbling upon a helpful solution here, I wanted to print small cage cards in a neat format with some tweaks of my own. Currently, this is how it appears for me (Fiddle): /* CSS styles */ (styles modified here) * { -moz-box-sizing: border-b ...