Creating a Horizontal Scrollbar in HTML

Recently, I came across a family treeview design like the one showcased here. However, the layout seems to fall apart when there are numerous children and doesn't fit on the screen properly. Is there a way to implement a horizontal scrollbar to address this issue? Your assistance is greatly appreciated. Below is the CSS code:

/*CSS Styling*/
* {margin: 0; padding: 0;}

.tree ul {
    padding-top: 20px; position: relative;

    transition: all 0.5s;
    -webkit-transition: all 0.5s;
    -moz-transition: all 0.5s;
}

.tree li {
    float: left; text-align: center;
    list-style-type: none;
    position: relative;
    padding: 20px 5px 0 5px;

    transition: all 0.5s;
    -webkit-transition: all 0.5s;
    -moz-transition: all 0.5s;
}

... (CSS Code continues)

/*That's everything from my side. Hope you found it helpful.
Thank you :)*/

Furthermore, here is the HTML structure used for such webpages. The branches expand quite significantly.

<div class="tree">
    <ul>
        ... (Nested list elements continue)
    </ul>
</div>

I tried adding

<div class="tree" style ="overflow-x:scroll">
, but the scrollbar isn't functioning correctly. Whenever I resize the window, the tree gets distorted and the scrollbar remains fixed, failing to scroll as intended. Any suggestions or guidance would be highly appreciated. Thank you in advance!

Answer №1

At long last, the solution has been discovered!

To resolve the issue, simply update the .tree li class as shown below.

.tree li {
display: inline-block;
white-space: nowrap;
vertical-align: top;
margin: 0 -2px 0 -2px;
text-align: center;
list-style-type: none;
position: relative;
padding: 20px 5px 0 5px;

transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}

A working jsfiddle showcasing this solution can be found below.

http://jsfiddle.net/LQ4yQ/

Answer №2

I'm not entirely sure what you're asking, but it sounds like you want a scroll feature that can adjust to changes in window resolution. If you want the scroll to always be present, you can use media queries like this:

@media screen and (max-width: 650px) {
  .tree {
    display: block;
    overflow-x: scroll;
  }

Answer №3

Set the overall width to 100% by applying this style to the main container in the CSS

Answer №4

For instance, imagine you have a box housing the family tree labeled as "Tree box." To control its maximum width, add a CSS style rule like width: 1200px;. Next, nest another 'div' within this box:

<div id="treebox">
<div id="treecontent">
[insert your HTML content here]
</div>
</div>

Here's how to style it using CSS:

#treebox{
height:100%;
width:1200px;
}

#treecontent{
width:100%;
or
width:1600px;
}

By following these instructions, a scrollbar should appear when needed.

To ensure proper containment, enclose the content within a 'div' with the ID of 'treebox,' and then place that div inside another one for additional space.

Answer №5

Successfully implemented the solution for you here: http://jsfiddle.net/A3yh9/5/. The layout may appear a bit messy because I added a lot of children without arranging them properly. This CSS code should resolve the issue, unless there is something specific on your end causing the problem. Simply copy and paste the following into your CSS:

.tree {  
    height:100%;
    width:960px;
}

.treecontent2{
    width:100%;
}

/* Adjust the width in the .tree as needed */

Additionally, insert a div right below the existing .tree div, ensuring it is closed at the bottom underneath all content but above the closing </div> tag of your .tree div.

Answer №6

Personally, I always prefer using CSS directly rather than inline styling in the HTML "style=""" element. Have you experimented with putting it in the CSS file? Maybe give this a shot:

.tree{
   overflow-x: scroll;
 }

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

Remove a Row from a Table by Clicking a Button with Ajax

I currently have an HTML table with 4 columns: SKU Group, Group_ID, Edit button, and Delete button. My focus at the moment is on implementing the delete functionality. I want it so that when the delete button is clicked, a confirmation box appears. If "OK" ...

Incorporate a fontawesome icon into a dynamically created button using ajax

Is it possible to insert fontawesome icons into a button created using this code snippet? $.each(response, function (i, item) { trHTML += '<tr><td>' + item.name + '</td><td>' + "<input type='button&apo ...

Determine the total cost based on the quantity purchased

I created a webpage for employees to select an item from a dropdown menu, and it will automatically display the price of that item. Check out my code below: <script> $(document).ready(function() { $('#price_input').on('change' ...

The issue of the v-list-item-title text color remaining static in v-navigation-drawer when active has been noted

I'm currently working on developing an application using the Vuetify framework. I've encountered an issue while trying to modify the CSS properties of v-list-item. The main problem arises when an item is active, as everything seems to work fine ...

What is the best way to incorporate tooltips in SVG?

My teacher wants me to display a tooltip on an SVG circle with links and information when we hover over it. They suggested using jQuery UI, but I've done extensive research and nothing has been able to assist me so far. ...

What is the best way to align two divs next to each other while keeping the second one centered with flexbox?

Here are my two div elements: <div class='container'> <div class='left'></div> <div class='centered'></div> </div> I am looking to center the second inner div and have the first inner ...

What is the best way to ensure an element reaches its full height limit without triggering the need for page scrolling?

Can you help me with a dialog box issue I am facing? $(document).ready(function() { $('.ui.modal').modal('show'); }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link hr ...

I have not made any changes to the <div> tag with my CSS or JavaScript coding

Click here to see the problem I am facing on JSFiddle. I am trying to create a loading screen that will slide up after a few seconds using jQuery. Although I am familiar with HTML, JavaScript, and CSS, I am still new to jQuery. I have a feeling that the so ...

Creating Stylish Checkboxes with Bootstrap

I'm attempting to customize a checkbox to have a specific appearance. example of desired checkbox design Here is what I have tried so far: <div class="col-2"> <label for="WitholdingTax">Charge</label> <div class="input-g ...

Customize the initial color of the text field in Material UI

I am currently working with the mui TextField component and facing an issue. I am able to change the color when it is focused using the theme, but I cannot find a way to adjust its color (label and border) in its initial state when it's not focused. I ...

Toggle between mouse-over and clicked effects on menu items using HTML and CSS

Is it feasible to eliminate the "active" class from menu items when hovering over a different menu item? If you're interested, there is a functional demonstration here. By default, the home button is assigned the "active" class. I want this class to ...

Tips for resizing images to fit the parent container dimensions

After uploading an image, I needed to adjust its dimensions. The original image was 450x700, while the parent container was 400x400. Using 'object-fit' helped fit the image to its parent container while maintaining its aspect ratio. However, I r ...

Manipulate CSS Properties with Javascript Based on Dropdown Selection

I am currently working on implementing a feature that involves changing the CSS property visibility: of an <input> element using a JavaScript function triggered by user selection in a <select> dropdown. Here's what I have so far in my cod ...

Having trouble displaying images in my 360-degree rotation slider

I am completely new to java script, so I have been copying and pasting code. However, it seems like the images are not loading properly. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" type="text/css" ...

PHP - The form page freezes up every time I try to submit the form

Hey there! I've encountered an issue with my form submission. Everything works perfectly fine, except when the Title field is left blank. Here's a snippet of my HTML code: Title: <input type="text" name="title"><br /> Description:&l ...

Styling CSS for Grouped Rows in Tables

I need help with styling a table that contains variable data, grouped by columns (Month and Year). My goal is to alternate row colors for each group of data. For example, all rows under Feb 2016 would have class=a, the next set of data would have class=b, ...

When flex items are stacked in a column, the bottom portion may be truncated

(Edit) Check out the codepen example here. I am working on creating a stack of cards using Vue.js and flexbox to showcase different apps on my website. Each card is represented by a component and I utilize Vue's `for` function to display cards with t ...

management in the same row or in the following row fashion

Looking to achieve a specific behavior for a label and control: If the screen width is less than X, the label and control should be on different rows with the control expanding to full width. If the width is equal to or greater than X, the label and cont ...

The Safari browser is having trouble rendering the website's CSS and HTML properly

Check out this example of how the website should look on Chrome for Android: https://i.stack.imgur.com/RzUSp.jpg And here is an example from Safari on iPad Mini 2: https://i.stack.imgur.com/PAj2i.jpg The Safari version doesn't display the proper fon ...

Unable to eliminate top padding without using universal selector

Trying to remove the top padding on a webpage, but encountering some difficulty. Here's the HTML code: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="style.css"> <title&g ...