Using the jquery plugin Sidr in Rails: A complete guide

I've been attempting to integrate the jQuery sidr plugin into my Rails project on Codecademy, but unfortunately, it's not functioning as expected.

To view the page, simply click here:

If you notice, the menu icon at the top left takes some time to load, and when clicked, the menu doesn't display correctly.

What's odd is that the menu appears correctly in the Codecademy browser (although the icon still loads slowly).

The expected appearance should resemble this:

Here are a few key files:

application.html.erb layout:

    <!DOCTYPE html>
<html>
<head>
  <title>Stories</title>
  <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
  <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link href="https://fonts.googleapis.com/css?family=Roboto:400,100,300" rel="stylesheet" type="text/css">
</head>
<body>


<%= yield %>

  <div class="footer">
    <div class="container">
        Developed by Satchel French
    </div>
  </div> 

<!-- javascript --> 
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
</body>
</html>

The menu stylesheet (sidr-dark.css):

    .sidr{display:none;position:absolute;position:fixed;top:0;height:100%;z-index:999999;width:260px;overflow-x:none;overflow-y:auto;font-family:"Roboto",tahoma,verdana,arial,sans-serif;font-size:19px;background:#000;color:#fff; font-weight:100;}
.sidr .sidr-inner{padding:0 0 15px}
.sidr .sidr-inner>p{margin-left:15px;margin-right:15px}
.sidr.right{left:auto;right:-260px}
.sidr.left{left:-260px;right:auto}
.sidr p{font-size:15px;margin:0 0 12px}
.sidr p a{color:rgba(255,255,255,0.9)}.sidr>p{margin-left:15px;margin-right:15px}
.sidr ul{display:block;margin:0 0 15px;padding:0;}
.sidr ul li{display:block;margin:10px;line-height:48px}
.sidr ul li:hover {background:#191919; margin: 10px;}
.sidr ul li a,.sidr ul li span{padding:0 40px;display:block;text-decoration:none;color:#fff}

And the home.html.erb file:

    <!DOCTYPE html>
<html>
    <!-- menu -->
    <div id="sidr">
  <!-- Your content -->
  <ul>
    <li class="active"><a href="#">Welcome</a></li>
    <li><a href="#">Blog</a></li>
    <li><a href="#">About</a></li>
  </ul>
  </div>
  <!-- start page -->
   <div class="window main">
     <div class="container">
       <!-- menu button -->
       <a id="simple-menu" href="#sidr"><%= image_tag('https://s3.amazonaws.com/codecademy-content/projects/z2d/stories/menu-white.svg',class:'icon-menu', alt:'open', width:'24px') %></a>
       <!-- content -->
       <div class="row">
        <div class="content col-md-6 col-md-offset-6"> 
            <h1 class="headline"> Satchel and Travel </h1>
                <p><a class="btn btn-primary sharp btn-lg" href="#" role="button"> Learn more </a> </p>
         </div>
       </div>
     </div>
   </div>
  <!-- home -supporting -->
  <div class="window-support">
    <div class="container">
      <h2 class="headline">Lets write about the moments.</h2>
    </div>
  </div>
  <!-- home secondary -->
  <div class="secondary">
    <div class="container">

    </div>
  </div>
  <!-- secondary support -->
  <div class="window-support">
    <div class="container">
      <h2 class="headline">Interested?</h2>
      <p><a class="btn btn-primary sharp btn-lg" href="#" role="button">Adventure</a></p>
    </div>
  </div>
</html>

Any assistance you can provide would be greatly appreciated! Thank you!

Satchel

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

Answer №1

Upon reviewing your page and comparing it with , it appears that certain css configurations and/or class definitions are missing:

To style the div sidr and have the menu appear attached to the left side, you should consider adding the following styles:

  • position:fixed
  • background-color:#ccc
  • width: 240px

The list items lack layout configurations, which is why they appear unstyled.

Take a look at the following classes from your reference website (as a starting point):

  • .menu
  • .menu ul
  • ol, ul
  • .menu li a

The class menu appears to be missing from your div definitions and css files. It's possible that you forgot to include a css file from the sidr plugin (assuming you are using sidr).

Answer №2

The CSS code references the class .sidr, but it seems like you forgot to include the class in your HTML. To fix this issue, replace <div id="sidr"> with <div class="sidr">.

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 SEMrush API is not displaying an 'Access-Control-Allow-Origin' header on the requested resource

When attempting to utilize the SEMrush API, I made a request using jQuery as shown below: $(document).ready(function() { $.get( 'https://api.semrush.com', { type: 'phrase_this', key: ' ...

Unable to add a string to a http get request in Angular

When a specific ID is typed into the input field, it will be saved as searchText: <form class="input-group" ng-submit="getMainData()"> <input type="text" class="form-control" ng-model="searchText" placeholder=" Type KvK-nummer and Press Enter" ...

What is the option for receiving automatic suggestions while formatting components in a react.js file?

When styling elements in our app using app.css or styles.css, VS Code provides auto-suggestions. For example, if we type just "back" for background color, it will suggest completions. However, this feature does not work in react.js or index.js. Why is that ...

Shift the Search bar to the last position on the navigation bar

I'm looking to relocate the search icon and input field to the end of the navbar. I'm currently using Bootstrap 5.0.2, but I am still new to Bootstrap, HTML, and CSS, so I'm not sure how to accomplish this. I want the width of the search box ...

Swapping out the document.createElement() method for React.createElement()

In a JavaScript library, I utilize document.createElement() to create an HTMLElement. Now, I am looking to develop a React library with the same functionality. My initial thought was to substitute document.createElement() with React.createElement(). There ...

The Lifecycle of an HTML Page

Trying to grasp the life cycle of an HTML page has been a challenge for me. Unable to find comprehensive resources online, I took matters into my own hands by experimenting with the f12 tool in Internet Explorer. Through these experiments, I have formulate ...

Embedding SVG or image code within the </style> tags is a common practice in web development

Can anyone assist me in placing this code within </style>? I am unsure of how to proceed with this. I believe the best approach would be to start by moving most of it into </style>, and then I can decide what should remain there. I would grea ...

What occurs when Render() is called during animation in React?

Curious about how React handles rendering during a component's animation? Let's explore an example where a component is re-rendered due to a state change triggered during its animation. Imagine a scenario where a component's animation lasts ...

Struggling to make textarea cooperate with rails and angular, need assistance

I'm currently working on implementing a feedback form in my rails/angular application. I have set up the form in a template, %form %input{"ng-model" => "feedbackForm.name", :type => "text", :placeholder => "Name"} %textarea{"ng-model" = ...

Error: anticipated expression, received keyword 'if'

I'm facing an issue that I could really use some assistance with. I am trying to hide the "changeOrderUp" button when it's in the first row, and similarly, I want to hide the "changeOrderDown" button when it's in the last row. However, FireB ...

Performing a jQuery ajax request by passing data obtained from iterating through elements

Is it possible to iterate through elements and send the element value within the data: {} parameter of $.ajax()? For example: $result = pg_query($connection, "select * from tbl_salary_deductions"); while($row = pg_fetch_assoc($result)) { ...

My Angular JS http.get request is failing to reach the specified URL

While working with AngularJS to integrate RESTful web services into my website, I am encountering an issue where I am consistently receiving errors instead of successful responses. I have been stuck on this for the past three days and any assistance would ...

Looking to create an anchor tag that navigates to a specific ID on the page while accommodating a fixed header placement

In my application, the homepage's carousel displays multiple images with dynamically generated anchor tags that link to different routes. When clicking on the anchor tag, the page scrolls to the linked image but is obstructed by a fixed header. I want ...

The userName data is not being displayed in the console.log when using socket.io

I'm currently in the process of developing a chat application using socket.io. My goal is to log the user's name when they join the chat. I have set up a prompt on the client side to capture the user's input and emit it to the server. Howeve ...

Utilizing deployJava.runApplet for precise element targeting

After years of successfully maintaining an applet that utilizes the traditional: <script src="foo.js"></script> method for embedding a Java applet, we can no longer ignore the need for change. It's time to switch to: deployJava.runAppl ...

Tips for dynamically inserting a new column into a table at any position other than the beginning or end

I have created a dynamic table where rows and columns can be added dynamically. However, I am facing an issue where I am unable to add a new column between the first and last column of the table. Currently, new columns are only being added at the end. $ ...

Serializing intricate objects using JavaScript

I'm curious if there are any options outside of npm for serializing complex JavaScript objects into a string, including functions and regex. I've found a few libraries that can do this, but they all seem to depend on npm. Are there any good seri ...

Is there a way to activate a Vue.js method when clicking a link within a data table?

I'm currently in the process of developing a Vue.js application using the Vue Webpack template. In one of my components, I'm setting up a Datatable like so: <script> export default { name: 'DataTable', mounted() { $(& ...

Navigation panel positioned on one side filling up the entire content container

I am currently developing a fresh website design. I envision a layout with the header positioned at the top, content in the middle, and a footer that will either stay at the bottom of the window if the content is minimal, or go to the bottom of the content ...

Leveraging HTML5 file uploads alongside AJAX and jQuery

While there are questions with similar themes on Stack Overflow, none seem to quite fit the bill for what I am looking for. Here's my goal: Upload an entire form of data, including a single file Utilize Codeigniter's file upload library So fa ...