How can I stop the text from expanding with Div Tile? I've already tried using overflow:hidden, but it doesn't

Is there a way to prevent the div from expanding when there is a lot of text, such as copy text paste? I'd like the height of the div to remain constant regardless of the amount of content inside. CSS usually precedes HTML, but I included it here for clarity on finding a solution.

#containerTiles .tilesText {
  color: #FFFFFF;
  font-weight: bold;
  text-align: center;
  position: relative;
  font-size: 20px;
}

#tiles {
  height: 33.34%;
  width: 33.34%;
  position: absolute;
  top: 66.68%;
  left: 50.01%;
  background: #3366CC;
  box-shadow: 5px 7px 0px 0px grey;
  transition: all ease .35s;
  border: solid 2px white;
  display: table;
  overflow: hidden;
  padding: 20px;
}

#tiles:hover {
  top: 65.12%;
  left: 48.9%;
  box-shadow: 5px 7px 0px 0px #003c85;
  transition: all ease .35s;
  border-top: 1px solid white;
  border-left: 1px solid white;
  border-right: none;
  border-bottom: none;
}
<div id="containerTiles">
  <a href='test.php'>
    <div id="tiles">
      <div style="display: table-cell; vertical-align: middle;">
        <div class='tilesText'>copy text pastecopy text pastecopy text pastecopy text pastecopy text pastecopy text pastecopy text pastecopy text paste</div>
      </div>
    </div>
  </a>
</div>

Answer №1

To make the content within the container scrollable when the text exceeds its height, I made a simple CSS adjustment by changing display: table to display: block and adding

max-height: 33.34%; overflow-y: auto;
.

#containerTiles .tilesText {
  color: #FFFFFF;
  font-weight: bold;
  text-align: center;
  position: relative;
  font-size: 20px;
}

#tiles {
  height: 33.34%;
  max-height: 33.34%;
  width: 33.34%;
  position: absolute;
  top: 66.68%;
  left: 50.01%;
  background: #3366CC;
  box-shadow: 5px 7px 0px 0px grey;
  transition: all ease .35s;
  border: solid 2px white;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 20px;
}

#tiles:hover {
  top: 65.12%;
  left: 48.9%;
  box-shadow: 5px 7px 0px 0px #003c85;
  transition: all ease .35s;
  border-top: 1px solid white;
  border-left: 1px solid white;
  border-right: none;
  border-bottom: none;
}
<div id="containerTiles">
  <a href='test.php'>
    <div id="tiles">
      <div style="display: table-cell; vertical-align: middle;">
        <div class='tilesText'>copy text pastecopy text pastecopy text pastecopy text pastecopy text pastecopy text pastecopy text pastecopy text paste</div>
      </div>
    </div>
  </a>
</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

Dividing an interface into four sections with jQuery Mobile

Currently, I am working with jQuery mobile and attempting to divide the page into four sections(Fiddle) with header and footer included. Unfortunately, I am facing some issues with this setup.. Check out my Fiddle here <!DOCTYPE html> <html> ...

Firebug displays the class name and location twice in the right panel

When examining a div labeled with .mlm-clearfix, I noticed that Firebug was displaying this class name and its URL twice in the right panel. The style declarations given for the Easy Clear Method in relation to this class are as follows: .mlm-clearfix:bef ...

Utilizing WebElement.findElements() in Selenium to refine search outcomes

After iterating through a list of WebElements, which I refer to as 'graphs', and finding descendants within each graph, I am encountering an issue where similar descendants from different graphs are being included in the results. Currently, I am ...

Learning the basics of JavaScript: Displaying the last number in an array and restarting a function

Hey there, I'm diving into the world of JavaScript and have set myself a challenge to create a simple bingo number machine. Check out my CodePen project here. I've successfully generated an array of 20 numbers, shuffled them, and added a marker t ...

What is the most effective method for relocating a DIV element across the webpage?

Struggling to find a solution for my problem. I have functions that fetch data from an API and display it in a div when a user right-clicks on a context menu. The div is currently fixed to the bottom right of the page, but I want it to be draggable so user ...

Converting HTML to PDF using Node.js without relying on PhantomJS

I'm currently creating PDF files from dynamic HTML by utilizing handlebars in my Node.js application with the html-pdf package. However, I've encountered an issue as the package is reliant on phantomjs which has now been deprecated. Unfortunatel ...

The `margin:auto;` property does not function properly with inline-block elements

I recently adjusted my "container" div by changing it to an inline-block. Previously, I had applied margin:auto; to center it, which worked well with a specified width. Original Code (functional) #container { border: 1px solid black; height: 2 ...

Struggling to retrieve an ID I included in a concealed field

Here is the code snippet: <tr> <td>&nbsp;</td> <td><input name="ID" type="hidden" value="<? echo $id; ?>"/></td> <td><input type="submit" name="Submit" value="Submit"/> <input type="reset" name= ...

How can I ensure that the height of my Flexbox always stretches vertically to 100% and fills the available space?

https://i.sstatic.net/j3VOr.png https://codepen.io/leon-yum/pen/GxWqMe?editors=1100 Attempting to replicate an issue encountered in one of our applications. The Sidebar within our app never expands 100% to accommodate the content. The <div class="cont ...

Get Facebook to recognize and display link previews for websites using ajax technology

It is commonly known that when copying a link from an HTML website onto Facebook, the platform will attempt to fetch available images as previews for the link. But what happens when the content is dynamically generated, such as with JavaScript? In this c ...

Attempting to dynamically assign a nickname to a CSS element selector during runtime

I have been attempting to adjust the position of a font awesome icon within an input field dynamically. My goal was to have the style calculated at runtime, similar to how I've handled other stylesheet elements in the past. However, I am facing diffic ...

Showing the content of an email's HTML Body

In developing my Python Django website, I'm looking to showcase emails on the front end. These emails have already been processed in the backend and are retrieved via AJAX in JSON format. My main concern is displaying the HTML body of these emails wi ...

Tips for loading various content types in Fancybox 3

I am utilizing Fancybox 3 for my gallery where I have disabled the opening/closing animation. Here is how I load my gallery: $(document).on('click', '[data-fancybox-var]', function(e) { e.preventDefault(); var links = $(' ...

Is there a way to automatically click the 'next' arrow on my image slider?

I'm currently working on a website that uses the Semplice theme in Wordpress. The built-in slider doesn't have an autoplay feature, so I attempted to use jQuery to automatically click the 'next' arrow every 5 seconds. However, I ran int ...

Notifying individuals of a file's unavailability using HTML tags

I recently created an API that is designed to deliver files to the frontend. Here is how it looks: <a href="downloadFile.aspx?file=token" download target="_blank"> The file download functionality is working fine. However, the issue arises when the ...

Using session variables on a different php page

Having trouble using a session variable in another page? I fetched data from a database and stored it in a variable, but when I attempt to use it on another page, I get an error saying 'undefined index'. See the code below - can someone help me s ...

Scrollspy in bootstrap incorrectly highlights the navigation item as active

I seem to be having an issue with bootstrap scrollspy. For example: <header class="header pb-4 pb-lg-0 pt-4 sticky-top bg-white"> ... </header> <div class="container-fluid width content-main" data-bs-spy=" ...

Angular - applying the number pipe only when a value is present

While developing my shop app, I encountered an issue with the number pipe. Is there a way to format numbers like 64.90 to display two digits after the decimal point only if there is a value in the database, such as 64.9, and if it's 60 in the database ...

Using CSS3 to showcase image captions

I am facing an issue with displaying captions on my images. The caption needs to display in two different ways - normal and hover. To better explain, I have included an image for reference. Although I have made progress with a large portion of this task, ...

Achieving full child div coverage within a bordered parent div on Chrome

I am encountering an issue where I am trying to insert an image into a bordered div, but in Chrome 96.0 there are unexpected margins appearing from the top and left that I cannot seem to remove. Below is the code I am using: .wrapper { width: 36px; ...