What steps can be taken to restore scrollbars in a web component?

Looking for some help with a web component I'm creating called my-thing. My struggle lies in getting the scrollbars to work as intended.

I have provided a sample (link to codepen). How can I make the scrollbars appear without modifying the elements marked as "can't change"?

<html>
<body>
    <style>
        .my-thing {
            white-space: pre;
            overflow: auto;
            border: 1px red solid;
            /*width:100%;*/
        }
    </style>

    <br />
    <div style="display:flex"> <!-- can't change -->
        <div>                  <!-- can't change -->
            <div class="my-thing">
        This has NO scrollbars!!
        This is a loooooooong and boring piece of text that really doesn't deserve to be read at all.
        This is another loooooooong and boring piece of text that really doesn't deserve to be read at all.
            </div>
        </div>
    </div>

    <br />
    <div class="my-thing">
        This auto scrolls correctly.
        This is a loooooooong and boring piece of text that really doesn't deserve to be read at all.
        This is another loooooooong and boring piece of text that really doesn't deserve to be read at all.
    </div>

</body>
</html>

Edit: In addition, please note that adjusting the width of my-thing manually is not allowed. The ideal scenario would involve keeping "width:100%".

Answer №1

To adjust the size of the my-thing element, simply assign a specific width and height to its class. Setting the width will trigger a horizontal scrollbar to appear, while setting the height will display a vertical scrollbar.

 .my-thing { white-space: pre; overflow: auto; border: 1px red solid; width: 100px; }

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

Tips for preventing the direct copying and pasting of JavaScript functions

Repeating the process of copying and pasting functions such as loadInitialValue(), loadInitialValue2(), loadInitialValue3(), is quite monotonous. This is the repetitive code snippet that I have been working on (when you click on "Mark as Read," the title o ...

What is the reason why the `text-overflow: ellipsis` is not functioning properly?

I can't get this overflow ellipsis to work properly. The documentation examples all seem correct, so what am I missing? Check out the fiddle p { width: 100px; height: 100px; word-break: break-all; border: 1px solid blue; overflow: hidden ...

Tips for displaying multiple results from a MySQL query in a single .ejs file using Node.js and Express

Currently diving into Node.js and working on a web application, I am faced with the challenge of rendering twice in the same .ejs file. Consider the scenario presented in the following .ejs file: <table> <% rows.forEach(function(ind){ %> /* m ...

What is the best way to manage horizontal scrolling using buttons?

I was hoping that when the button is clicked, the scroll would move in the direction of the click while holding down the button. Initially, it worked flawlessly, but suddenly it stopped functioning. export default function initCarousel() { const carous ...

What causes the breakdown of flexbox when set to column and wrap?

Here is the code I am working with: <div id="parent"> <div class="produit_sup"> <p>Aubergine</p> <p>Betterave</p> <p>Courgette</p> <p>Oignon</p> <p>Poir ...

The issue with Jquery .html() function causing spaces to disappear between words

When utilizing jQuery's .html() property to populate a select box, I encountered an issue where the spaces between words were being trimmed down to just one space. Despite including multiple spaces in the option, it would always resolve to a single sp ...

Determine the exact moment at which the value shifts within the table

Looking for assistance in automating the grade calculation process whenever there is a change in table values. Any suggestions on how to achieve this? I am new to events and AJAX, so any help would be appreciated as I am still learning. Please see the ima ...

Applying Regex Patterns to Material UI Text Fields

I am looking for two TextField components from MaterialUI. The first one should only allow alphabets (including small, capital letters, and spaces like "Risha Raj"). The second one should also only accept alphabets (small or capital) but with a maximum len ...

Convert JQuery to a click event

I have a code snippet that is currently functioning properly $(window).load(function(){ $(document).ready(function(){ $("input[name ='_sft_product_cat[]']").parent().next(".children").css("background", "yellow"); }) }); My goal is to convert th ...

Utilizing an array variable within CanvasJS to enhance chart functionality

I am currently in the process of developing a website for a family member that requires a simple calculator and graph integration. I have implemented a JavaScript function to handle 3 input variables: total, Interest Rate, and Months. The calculation is fu ...

Ways to extract data from a specific part of the HTML code

Greetings, this is my initial foray into coding and I am attempting to create a scraper that can gather all the relevant information about my school and district. \[<p class="flex-icon"> \<svg aria-hidden="true" clas ...

When using the JQuery click() function, the condition inside the if statement will only trigger after 2 clicks, while any code outside the if block will execute after

As I delve into learning JQuery, I've encountered a strange issue while trying to implement an if condition within the click() function. It seems that when I include an alert statement right before the if condition, the alert pops up on the first clic ...

Vertical centering menu adjustment

Can anyone help me with centering an image on my website? I've tried the following code: top: 50%; -webkit-transform: translateY(-50%); -ms-transform: translateY(-50%); transform: translateY(-50%); You can see what's happening on my site here: ...

"Utilizing Bootstrap to add borders to div elements is a

https://i.sstatic.net/yPt46.png Hey there! I am working on a project using bootstrap 4. I encountered an issue that I can't seem to solve. I placed an image inside a div, set the div's height and width to 200px with overflow hidden. The image w ...

Having trouble centering SVGs on the screen

My goal is to shift elements of the SVG to the center of the screen upon clicking, but I haven't been successful so far. It's puzzling because it worked flawlessly with a different SVG. I've tried following the advice given in this post, an ...

Importing fonts using CSS

Currently, I have 4 different fonts that I need to incorporate into a website, and their files are saved within my website folder. Baskerville.ttc BellGothicstd-Black.otf BellGothicstd-Bold.otf JennaSue.ttf I attempted to import the fonts using @Import, ...

Guide to setting up a Datetime picker in Bootstrap 5 user interface

I've been struggling to implement a datetime picker for Bootstrap 5 (my front end is using Bootstrap 5.1.0). While I came across a solution for Bootstrap 3, unfortunately it doesn't seem to work with Bootstrap 5. ...

What is the method for retrieving the font size of elements in the native view using appium?

Can the font size of text in the native view be retrieved using appium? I am aware of using driver.findElement(By.id("by-id")).getCssValue("font-size"); for web views. Is there a similar method for native views? ...

Sending items from a dynamically created list to a different webpage

In my JavaScript file, I have an appended list that looks like this: $("#ultag").append($("<li onclick=\"next(this.id);\" id=\"litag\"><div id=\"litagdiv\"><div id=\"imgdiv\"><img id=\"list ...

Designing a website layout for android devices

Could this inquiry receive positive feedback rather than being downvoted? I have conducted thorough research before posting. I've been experimenting with developing a responsive website for practice. It worked well on my computer; every time I adjust ...