Tips for creating a div element with a header and scrollable section

Greetings! I am currently developing a code to manage a sprinkler system interface with a modern and visually appealing design. At the moment, I have two columns on the page, each containing boxes. Unfortunately, the alignment of these boxes is not as desired. The bottom box in the left column should be positioned 5px below the top one, instead of being aligned with the box on the right. Additionally, I require the "Run History" boxes to have a scrolling segment, with the "Run History" label and the top of the table fixed while the data inside scrolls within the div. You can view the full code on this CodePen: https://codepen.io/masonhorder/pen/gyQmBG

Here is part of the HTML code snippet:

<div class="body">
  <div class="boxes">
    <div class="water box box-left">
      <h1>Water Saved</h1>
      <p>You Have Saved:<br><span class="huge">15</span><br> gallons of water</p>
    </div>
    <div class="water box box-right">
      <div class="fixed">
      ...

...

Some CSS styling included in the code:

#blue{
color: rgb(38, 99, 242);
}

.huge{
  font-size:90px;
  font-weight: 900;
}

#name-link:hover{
  text-decoration: none;
}

.body {
  /* margin-left: 25%; */
...

Answer №1

Just to clarify, you are looking for the following adjustments, right?

  • Vertical alignment of column content so that it stacks underneath each other without aligning with content from the opposite column
  • Implement scrolling overflow on tables within the "Run History" boxes, with a fixed header during scrolling.

Alignment

It seems like there may be some confusion between rows and columns. Rows run horizontally while columns are vertical. Is there any connection between the two "Water Saved" boxes and the adjacent "Run History" tab? If not, I recommend placing the "Water Saved" boxes in one column and the "Run History" boxes in another column. This way, they will be grouped together and aligned as desired.

The structure could look something like this:

<div class="boxes">

    <div class="column column-left">
        <div class="water box">
            <h1>Water Saved</h1>
            <p>You Have Saved:
                <br><span class="huge">15</span>
                <br> gallons of water
            </p>
        </div>
        <div class="water box">
            <h1>Water Saved</h1>
            <p>You Have Saved:
                <br><span class="huge">15</span>
                <br> gallons of water
            </p>
        </div>
    </div>

    <div class="column column-right">
        <div class="water box">
            <div class="fixed">
                <h1>Run History</h1>
                <table>
                    ...
                </table>
            </div>
        </div>
        <div class="water box">
            <div class="fixed">
                <h1>Run History</h1>
                <table>
                    ...
                </table>
            </div>
        </div>
    </div>

</div>

To display the columns side by side, CSS adjustments are needed. The following CSS styling can be applied:

.boxes {
    display: flex;
    justify-content: space-evenly;
    width: 100%;
    padding: 0;
}

.column {
    flex: 0 0 auto;
    width: 35%; /* To maintain original width */
}

.box {
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    border: 1px solid rgb(229, 229, 229);
    padding:1%;
    margin-bottom: 5px;
    border-radius: 25px;
    box-shadow: 8px 8px 4px rgb(247, 247, 247);
}

I have utilized flexbox (display: flex;) for arranging elements side by side. It provides a convenient approach for layout design.

In regards to box scrolling, adjust the scroll class by adding a height-related property such as height or max-height to limit the overflow. Additionally, change the overflow property to overflow-y to prevent unintended horizontal scrolling.

.scroll {
    max-height: 200px;
    overflow-y: auto;
}

Apply the scroll class to the table element within the "Run History" box to enable scrolling:

<div class="water box">
    <h1>Run History</h1>
    <div class="scroll">
        <table>
            ...
        </table>
    </div>
</div>

For reference, here is a codepen example based on these modifications: https://codepen.io/Phoenix1355/full/PgxmaX

I hope this explanation aids your process.

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 animation came to a halt after a brief period

Here is the code I wrote. When the button is clicked, the 3 containers should start flashing indefinitely, but they stop after a while. I can't figure out why. Any ideas? <!DOCTYPE html> <html> <head> <title></title> & ...

What is the correct way to utilize Microdata fields?

I'm finding the process of creating a list of events on a page to be a bit perplexing. Does the URL in this example represent the current page or another page you are mentioning? <div itemscope itemtype="http://data-vocabulary.org/Person"> H ...

TinyMCE version 5.x - Stand out with a specific selection in a personalized drop-down navigation bar

In my customized TinyMCE 5.x dropdown menu, there are 3 options that adjust the width of the editor. I am looking for a way to indicate the currently selected option, but I am unable to interact with the menu items once they are initialized. It seems like ...

Add the following code snippet below every second set of two paragraphs that are enclosed within h

I am looking to add Advertisements following the 2nd paragraph in every h2 tag. Here is an example of what I want: <h2>Sub title</h2> <p>1st paragraph</p> <p>2nd paragraph</p> <div>INSERTED AD</div> functio ...

Comparison between Mobile Phone's innerWidth and innerHeight Versus Resolution

My test phone, the Galaxy S3 Mini, has a resolution of 800x480 according to its specs. Strangely, when I run the following code in my HTML game: window.innerWidth window.innerHeight The width appears as 533 and the height as 295. I recently discovered ...

Removing an Element in a List Using Jquery

In my JQuery, there is a list named additionalInfo which gets populated using the function below: $('#append').on('click', function () { //validate the area first before proceeding to add information var text = $('#new-email&a ...

What is the correct way to format the headings for sub-level pages, like chapters within a novel or sections within a lengthy article?

At times, the text and image content becomes too expansive to fit on a single page. However, preserving the context of the content is crucial, making it necessary to display it explicitly from a user experience perspective. This could include chapters of a ...

Revising text for real-time editing

Most of us are familiar with the functionality on StackOverFlow that allows you to preview your text before posting a question. I'm interested in implementing a similar feature on my website and am looking for some guidance on how to get started. I ...

Positioning an element in the center of another using JQuery

Greetings! I am currently working with some elements that look like this: <div id="one">content</div> <div id="two">content</div> These elements are followed by another set of elements (without any parent, placed directly after th ...

Is it possible to utilize jQuery for dynamically generating a file along with its content?

Here is the HTML snippet I am working on: <ul> <li> Download <a href="#">file1</a> </li> <li> Download <a href="#">file2</a> </li> <li> Download <a href="#">file3</a> </li> ...

Modifying the array structure will deselect all individual <Input> elements that have been iterated

Hoping to create a system for adding/removing sub-items with buttons that increment/decrement slots in an array, where input fields are automatically added and removed: <div *ngFor="let item of itemsInNewOrder; let i = index"> <input [(ngModel) ...

Creating an HTML element using jQuery isn't just about designing; it

When creating HTML elements using an Ajax call from the server-side, it can be challenging to align them properly on a responsive web page. Below is an example of how elements are generated with an Ajax call: var html = ""; $.ajax({ type: " ...

Ways to achieve perfect alignment for SVG text within its container, as opposed to stretching across the entire webpage

Recently, I've been working on a customizable photo frame designer using SVG. One of the key features allows users to add their own text to the frame. To achieve this, I'm utilizing jQuery's .keyup function. However, the issue I'm facin ...

Can you use "or" or "not" syntax with CSS input type selectors?

In the world of programming, if they actually exist, Suppose I have created an HTML form with the following input fields: <input type="text" /> <input type="password" /> <input type="checkbox" /> I wish to style all input fields that a ...

Empty the password field

<input name="e_password" id="e_password" type="password" autocomplete="off" /> The password field above is causing some trouble as it gets automatically filled in Mozilla, but not in Chrome and IE11. This seems to be retaining values from previous a ...

Tips for customizing the color of pagination in bootstrap

I'm currently in the process of designing a website and I've chosen to implement Bootstrap's pagination for navigating between pages. Due to time constraints, I was wondering if anyone knows how I can utilize classes like "bg-dark", "bg-prim ...

What is the secret behind Facebook's ability to keep the chat bar fixed at the bottom of the browser window?

I am curious to learn about the method Facebook uses to keep the chat bar at the bottom of the browser window even when we scroll through the page. ...

pictures showcased in a grid that dance and sway

Hey everyone, I wanted to ask about images on a website that have a unique effect when you hover over them. On the site follow your feet website, there is a grid section of destinations and when you move your mouse over a destination, it suddenly expands a ...

Tips on placing a white background behind fa-3x (Font-awesome) icons

I am facing challenges while trying to customize the background behind my font-awesome icons. My goal is to create a white background that does not extend beyond the actual icon itself. Currently, the result looks like the image below: https://i.sstatic. ...

Transition smoothly between sections using fullPage.js with clipping path effects

I am looking to create a unique clipping animation utilizing SVG clipping path. The animation should hide the first section while revealing the second section in a smooth transition using fullPage.js. This idea is somewhat similar to the question discusse ...