Creating a scrollable div in Electron

I'm currently developing a basic Markdown application using Electron. At the moment, all I have is a textarea, a div, and some Javascript code that retrieves the text from the textarea, processes it with Marked (an NPM module), and updates the content of the div using JQuery.

Despite setting overflow: auto; in my CSS file and trying various solutions, I haven't been able to make the div scroll properly. While the textarea scrolls fine, the text in the div gets cut off at the bottom.

If you want to take a look at my code: https://codepen.io/anon/pen/jZprNL

HTML:

<div class="row fullHeight" id="container">
  <div class="column fullHeight " id="markdown">

    <textarea class="padding markdown-body nodrag" id="editor" placeholder="Write something brilliant..."></textarea>
  </div>
  <div class="column fullHeight" id="preview">
    <div class="padding markdown-body nodrag" id="output">
    </div>
  </div>
</div>

CSS:

 /* Some responsive grid arrangement styles for .row and .column not included here */

#container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding-bottom: 30px;
}
#editor {
    background-color: #f4f6f7;
    border-width: 0px;
    resize: none;
    width: 100%;
    height: 100%;
    padding: 5px;
    padding-top: 15px;
    margin-right: 5px;
    overflow-y: auto;
    overflow-x: hidden;
}
#output {
    overflow: scroll;
    padding: 5px;
    padding-top: 15px;
}

/* Other styles related to electron are mentioned here */

JS:

$editor.on('input propertychange', function () {
  var outputHtml = marked($('#editor').val());
  $output.html(outputHtml);
  console.log($('#editor').val());
});

// Note: This part may not work due to Node installation issues, but it's just a small section of the JS code.

// Added CodePen link for reference

Answer №1

In the given example code, ensure that a scrollbar appears with the following CSS:

#output {
  overflow: scroll;
  padding: 5px;
  padding-top: 15px;
  width: 90%;
  height: 100px;
}

If one parent element has a fixed height, you can use a height of 100%. The provided code only uses relative heights, which may not always display the scrollbar when setting the width to 100%. However, the div element remains scrollable.

It's important to note that if you are utilizing markdown, there may be a clash between your stylesheets and any markdown-related stylesheets being used.

Answer №2

To successfully display long text that exceeds 500px in height, it is essential to enclose it within a wrapping div element.

For instance:

<div class="panel">
   <div class="content-scrollable">
     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p>
   </div>
</div>

.panel {
   height: 500px;
   width: 500px;
   overflow: hidden;
}

.content-scrollable {
  overflow: scroll;
  height: 100%;
}

You can view an example on CodePen here: https://codepen.io/anon/pen/yvqLOK

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

What is the best way to adjust the autoplay volume to a set level?

I have a page with an audio element that autoplays, but I want to ensure the volume is set to a specific level in case a user has their volume turned up to 100%. Any suggestions on how to accomplish this? Here's the HTML code: <audio autoplay> ...

Error VM1673:1 SyntaxError was raised due to an unexpected token '<' appearing in the code

I am facing an issue with the following JS code for AJAX form submission using PHP 8. When I check the chrome browser console, I encounter the error message: "Uncaught SyntaxError: Unexpected token '<', " <fo"... is not valid JSON." What ...

Issue with Safari div not exhibiting proper overflow functionality

I'm looking to set up a webpage with a single sidebar and content area. Here's how I envision it: <div id="mainWrapper"> <!-- Sidebar --> <div id="sidebar"> <p>Sidebar</p> <p>Sidebar< ...

sophisticated method for sorting through data within an array of arrays

How can data be filtered from an array of arrays? Below is an example to help explain the process. To filter the data, use startnumber and endnumber in the query. const data = [ { "name": "x", "points": [ [100, 50, 1], //[number, value ...

Repairing the base navigation interface and correcting the hyperlink to redirect to a different webpage

Can anyone assist with aligning my bottom navigation bar and fixing a link issue on both navigation bars? I've been struggling to center it. Do you think using padding could solve the problem? I've tried guessing the pixel count, but to no avail ...

Combining the functionality of a click event

Is it possible to combine these two functions in a way that ensures when '#css-menu' is shown, '.menu' becomes active, and vice versa? $('.menu').click(function() { $('#css-menu').toggleClass('shown hidden& ...

NodeJS - Headers cannot be modified once they have already been sent to the client

I've recently discovered a solution to the issue I was facing, which involves adding a return statement after sending a response. However, despite implementing the return statement, the error persists. const dbEditCourse = (req, res, db, logger) => ...

What is the best way in React to handle large operations, such as filtering and mapping a 10000-row array, asynchronously in order to prevent the UI from being blocked?

Currently, my table contains a large amount of data. Whenever I apply a filter, the data needs to be filtered and remapped, causing a delay of approximately 1-2 seconds. However, during this processing time, the UI becomes unresponsive. Is there a method ...

Utilize jQuery to populate checkbox and label attributes with elements from an array

I am looking to populate attributes for 4 checkboxes and their labels from specific arrays without appending the entire markup. I have everything set up in the markup and just need to fill in the attributes based on the selection from a select menu. var ...

Alignment of menu blocks

I'm struggling to line up all the menu items at the bottom - products, activity feed, and learn store should be on the same row, with test below products. Currently, products is being pushed up and text is aligning to the right of it. Despite trying ...

AngularJS: ng-model not reflecting changes in entire object, only specific field within the object is being updated

I came across an issue while working on my AngularJS project. Here is the scenario: form.html: <form> <input ng-model="someVariable" type="text"/> </form> details.html: <div ng-include="'form.html'"></div> {{ s ...

Each div will display the same image twice when loading the image

I have a grid where images are dynamically loaded with a link to a lightbox. Currently, this is how I am achieving it: $(".selection_thumb").each( function(i) { $(this).append("<a data-lightbox='image-1' href='img/folder/folder/"+(++ ...

Unable to change the name of the file using ngx-awesome-uploader

Currently, I am utilizing https://www.npmjs.com/package/@sleiss/ngx-awesome-uploader and facing an issue regarding renaming files before uploading them. Upon reviewing the available methods, it appears that there is no option for file renaming. While I c ...

The form features a "Select all" button alongside a series of checkboxes for multiple-choice options

I am facing difficulties trying to get the "Select all" and "Remove all" buttons to function properly within my form. Whenever I remove the "[]" (array) from the name attribute of the checkboxes, the JavaScript code works perfectly fine. However, since I n ...

"CSS Troubleshooting: Why Isn't My Background Image

Could someone assist me in understanding why this code is not functioning properly? I have experimented with both background-image and background properties, as well as adjusting the height and width attributes. <html> <head> <link ...

Initiating a AJAX upload upon selection of a specific option from a select menu

Recently, I have been exploring ways to enhance my layout page by implementing an option for users to upload new logos on the spot. Currently, users are able to choose their desired image through a drop-down selection feature. I am interested in adding a f ...

JavaScript: Choosing between explicit imports and the * sign

Why do this in one way: import * as copy from 'copy-to-clipboard'; instead of the other way: import { someMethod } from 'copy-to-clipboard'; Does it impact performance or bundle size? Personally, I find the second option cleaner. ...

Troubleshooting a minor JavaScript loop problem

I am facing an issue with my script that retrieves data from a database. Currently, when the search() function is called by clicking a button, only one result is displayed in a new div. How can I ensure that a new div is created for each result found, rath ...

The UseEffect function ceases to function properly upon refreshing the website

I'm currently using ReactJS for a project. I have a form that is intended to serve as the configuration for another form. The structure of this specific form is as follows: const [startingDate, setStartingDate] = useState(); const [endingDate, set ...

What is the best approach to achieve the old THREE.SpriteAlignment effect in the latest version of three.js?

After adapting an old three.js code for my application that includes a 3D function with axes grids, I encountered an issue when trying to update it to the latest revision, r74: https://jsfiddle.net/cjfwg2c4/ Without THREE.SpriteAlignment.topLeft, sprites ...