Avoid unintentional scrolling beyond the padding area

Here is an example code where the overflowing content that is scrolled, scrolls into the top/bottom padding area.

Is there a way to prevent this while still keeping the scrollbar right next to the right edge?

.parent {
  height: 200px;
  width: 200px;
  border: 1px solid red;
  overflow: auto;
}

.child {
  word-wrap: break-word;
  border: 1px solid blue;
  padding: 1rem;
}
<div class="parent">
  <div class="child>
    FofofofofofofFofofofofofofFofofofofofofFofofofofofofFofofofofofofFofofofofofof...
  </div>
</div>

Here's a more advanced CodePen example (same issue though): You can check it out at this link

Answer №1

Here's a demonstration that utilizes the margin property rather than padding.

Please take note of the following issues in your code:

  • You have duplicate IDs (id="imgUNcover") on the image tags.
  • There are two sets of classes applied to the image tags.

I've also included the img-fluid class to ensure the images fill the available space. Finally, remember to utilize the calc() function in your CSS to accurately calculate the height of the card's body considering the margin's height is added to the content box's height.

.card {
  height: 400px;
  overflow: hidden;
}

.img-container {
  flex: 1 0 30% !important;
  max-height: 30% !important;
  overflow: visible;
  border: none !important;
  text-align: center;
}

.card-body {
  flex: 1 0 70% !important;
  max-height: calc(70% - 2.5rem) !important;
  overflow: auto;
  margin-top: 1.25rem;
  margin-bottom: 1.25rem;
  padding-top: 0!important;
  padding-bottom: 0!important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div class="container">
  <div class="row">
    <div class="col-12 col-md-6 col-lg-3 mb-3 mb-md-3">
      <div class="card">
        <div class="img-container">
          <a href="#">
            <img src="https://qph.fs.quoracdn.net/main-qimg-fdaa32b9bffc30131e56956e4bc1e9e4.webp" alt="blabla" class="card-img-top img-fluid">
          </a>
        </div>
        <div class="card-body">
          <a href="#" class="card-title cardTitleLink">
            <h1 class="cardTitleUN">
              Some title
            </h1>
          </a>
          <p class="card-text text-muted">blabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalbla
          </p>
          <a href="#">Continue Lendo</a>
        </div>
      </div>
    </div>

    <div class="col-12 col-md-6 col-lg-3 mb-3 mb-md-3">
      <div class="card">
        <div class="img-container">
          <a href="#">
            <img src="https://www.dailydot.com/wp-content/uploads/2018/05/crush.jpg" alt="blabla" class="card-img-top img-fluid">
          </a>
        </div>
        <div class="card-body">
          <a href="#" class="card-title cardTitleLink">
            <h1 class="cardTitleUN">
              Some title
            </h1>
          </a>
          <p class="card-text text-muted">blabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalblablabalbla
          </p>
          <a href="#">Continue Lendo</a>
        </div>
      </div>
    </div>
  </div>
</div>

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

How can I showcase an image from the search results using the Giphy API?

Find the GitHub link to the Giphy API here: https://github.com/Giphy/GiphyAPI. As a newcomer, I'm facing a roadblock. Currently, I am receiving random gifs from the Giphy API instead of the specific search result requested by the user. Is there a wa ...

Designing a custom CSS for enhancing the look of the orchard menu

Right now, I am in the process of implementing a layout that is already established in an MVC4 project. I am facing challenges in figuring out how to create a custom menu in the latest version of Orchard (using the source version so it runs in Visual Stud ...

I am utilizing Python Django to display a message from a Python file in HTML. While the current code is functional, I would like the message to be showcased as a pop-up or alert notification

Using Python Django. The message is coming from a Python file and I would like to display it in HTML. The current code is functioning, but I would like the message to appear as a pop-up or alert. Register {% if messages %} {% for result in messages %} < ...

What is the process for activating a script file once I have replaced HTML content using a backend method?

After receiving HTML content from the backend, including the <script> tags, I noticed that the scripts.js file does not seem to be activated. While the HTML content displays fine, changing the path to style.css successfully alters the appearance of ...

The expected behavior of first-child is not impacting the initial element as anticipated

What is the reason behind the rule not impacting the first div containing the "update 1" text? .update div { width:100%; height:25%; border-top:1px dashed {color:background title}; padding: 5px; color:{color:links nav}; cursor:po ...

Methods for scaling the size of CSS background images

Can anyone assist me with scaling background image size properly? code: http://codepen.io/AnilSimon123/pen/JRBRZa Below is the code snippet: .bgimage{ background:url('http://www.thedesignlove.com/wp-content/uploads/2012/08/free-blue-abstract-vec ...

Exploring the world of XML parsing with iText

I am curious to learn whether it is feasible to modify the font, color, and size while converting HTML to PDF using xmlWorker.parser. Thus far, I have successfully parsed the input as is, but now I am seeking ways to customize the font, size, color, and ...

The image on Bootstrap isn't showing up

Can someone please help me troubleshoot why my logo image is not showing up? I can't figure out why the min and max width/height parameters are not working as intended. Here is my HTML: <div class="container-fluid"> <div class="head"> ...

What is the best way to create separate positions for items within a single div?

https://i.sstatic.net/FQRY4.jpgAfter looping through various names and accessing them from a single div using {{item}}, I encountered an issue. All the names are within one parent element. This is the code snippet: <div :style="image" cl ...

What causes the behavior of <body> backgrounds to differ from that of other HTML elements?

After examining the HTML code provided: <p style="margin:100px;border:1px solid red;background-color:#dff"> Hello </p> We can observe that when rendered by the browser, it looks like this: https://i.sstatic.net/rADHC.png If we were to mod ...

How can I retrieve the $index value of an ng-repeat element within a uib-dropdown?

I am currently working on implementing an ng-repeat loop that includes a dropdown menu for each element. I want the dropdown menu to contain functions that operate on the specific element, requiring access to the index of that element. Below is the code sn ...

hiding the search box by clicking away from it

Can someone help me with modifying this search box design? @import url(http://weloveiconfonts.com/api/?family=entypo); /* entypo */ [class*="entypo-"]:before { font-family: 'entypo', sans-serif; color: #C0C0C0; } * { margin: 0px; pad ...

Eliminating bottom section in HTML/CSS

I've got this code snippet: new WOW().init(); /* AUTHOR LINK */ $('.about-me-img img, .authorWindowWrapper').hover(function() { $('.authorWindowWrapper').stop().fadeIn('fast').find('p').addClass('tr ...

Can the layout of my page be modified for mobile in a specific manner using the Bootstrap 4 grid system?

At the moment, I have my bootstrap grid structured like this <div class="container"> <div class="row"> <div class="col-4"> <div class="A"> A </div> </div ...

What are the reasons that execCommand does not function correctly when attempting to justify text?

Why isn't justify with execCommand working properly? Take a look at the code below: $('#JustifyLeft').click(function(){ document.execCommand("JustifyLeft", false, ""); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2 ...

Create a container-fluid design in Bootstrap with various colors

I am aiming to create a design with a fluid container featuring different background colors on each side, separated by two columns within the container. I have visualized it in this image - do you think it is feasible? https://i.stack.imgur.com/KRc2Q.pn ...

What is the process for refreshing HTML elements that have been generated using information from a CSV document?

My elements are dynamically generated from a live CSV file that updates every 1 minute. I'm aiming to manage these elements in the following way: Remove items no longer present in the CSV file Add new items that have appeared in the CSV file Maintai ...

Transform CSS into React.js styling techniques

My current setup involves using Elementor as a REST Api, which is providing me with a collection of strings in React that are formatted like this: selector a { width: 189px; line-height: 29px; } Is there a tool or library available that can conver ...

Using jQuery to create an interactive form with PHP integration

I've set up a PHP form to post to a database successfully. However, after including it in a jQuery web page, the form is no longer posting to the database. Check out the code for both the webpage and the PHP file below. Interestingly, the form works f ...

What is the best way to display all HTML content using PHP?

I have an HTML page with a multitude of CSS and JavaScript tags in its head section. My goal is to print them as they are on a PHP page. I've attempted using PHP echo file_get_contents("html_url"); and the fread function. The PHP page successfully loa ...