What is the best way for me to make sure the element overflows properly?

How can I make the contents of the <div class="tags> element cause overflow so that one can scroll its contents instead of the element simply extending in height?

I've experimented with different combinations of overflow-y: scroll and min-height: 0, but I'm struggling to understand why it behaves this way. Can someone help clarify it for me?

.card {
  width: 300px;
  height: 200px;
  padding: 0.5rem;
  margin: 1rem;
  background: lightskyblue;
  font-size: 0.9rem;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 4px 6px rgba(0, 0, 0, 0.23);
}
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.customerAvatar {
  background: green;
  width: 50px;
  height: 50px;
}
.ownerAvatar {
  background: red;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  align-self: flex-start;
}
.details {
  display: grid;
  flex-grow: 1;
  grid-gap: 5px;
  grid-template: 4fr 1fr / 1fr 1fr;
  min-height: 0;
  min-width: 0;
}
.caseContainer {
  display: inline-block;
  min-height: 0;
  min-width: 0;
}
.tags {
  display: flex;
  flex-wrap: wrap;
  overflow-y: scroll;
}
.tag {
  background: lightcoral;
  box-sizing: border-box;
  margin: 2px;
  border-radius: 2rem;
  padding: 0.25rem 0.75rem;
  max-width: 100%;
  word-wrap: break-word;
}
input,
textarea {
  width: 100%;
  box-sizing: border-box;
  background: transparent;
  border: none;
  font: inherit;
  transition: all 0.2s;
}
textarea {
  resize: none;
}
textarea::-webkit-scrollbar {
  width: 3px;
}

textarea::-webkit-scrollbar-track {
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
}

textarea::-webkit-scrollbar-thumb {
  background-color: rgb(47, 147, 241);
  border-radius: 3px;
}

input::placeholder,
textarea::placeholder {
  color: rgba(0, 0, 0, 0.3);
}

input:focus,
textarea:focus {
  outline: none;
  box-shadow: -2px 0px 0px 0px rgba(47, 147, 241, 0.5);
}
<div class="card">
  <div class="header">
    <div class="customerAvatar"></div>
    <div class="ownerAvatar"></div>
  </div>
  <div class="details">
    <div class="caseContainer">
      <input name="case" id="case" placeholder="Case tags" />
      <div class="tags">
        <div class="tag">AAAAAAAAAAAAA</div>
        <div class="tag">BBBBBb</div>
        <div class="tag">CCC</div>
        <div class="tag">D</div>
        <div class="tag">FFFFFFFFFFFFFFFFF</div>
      </div>
    </div>
    <textarea name="profilert" id="profilert" placeholder="Profilert"></textarea>
    <input name="dato_frist" id="dato_frist" placeholder="Dato - Frist"></input>
    <input name="kontakt" id="kontakt" placeholder="Kontakt"></input>
  </div>
</div>

Answer №1

Is this the concept you have in mind?

I implemented display: flex and flex:auto to adjust the container as required.

.card {
  width: 300px;
  height: 200px;
  padding: 0.5rem;
  margin: 1rem;
  background: lightskyblue;
  font-size: 0.9rem;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 4px 6px rgba(0, 0, 0, 0.23);
  display: flex;
  flex-direction: column;
}
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.customerAvatar {
  background: green;
  width: 50px;
  height: 50px;
}
.ownerAvatar {
  background: red;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  align-self: flex-start;
}
.details {
  display: grid;
  flex-grow: 1;
  grid-gap: 5px;
  grid-template: 4fr 1fr / 1fr 1fr;
  min-height: 0;
  min-width: 0;
}
.caseContainer {
  display: inline-block;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex: auto;
  flex-direction: column;
}
.tags {
  display: flex;
  flex-wrap: wrap;
  flex: auto;
  overflow: auto;
}
.tag {
  background: lightcoral;
  box-sizing: border-box;
  margin: 2px;
  border-radius: 2rem;
  padding: 0.25rem 0.75rem;
  max-width: 100%;
  word-wrap: break-word;
}
input,
textarea {
  min-width: 100%;
  align-self: flex-start;
  box-sizing: border-box;
  background: transparent;
  border: none;
  font: inherit;
  transition: all 0.2s;
}
textarea {
  resize: none;
}
textarea::-webkit-scrollbar {
  width: 3px;
}

textarea::-webkit-scrollbar-track {
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
}

textarea::-webkit-scrollbar-thumb {
  background-color: rgb(47, 147, 241);
  border-radius: 3px;
}

input::placeholder,
textarea::placeholder {
  color: rgba(0, 0, 0, 0.3);
}

input:focus,
textarea:focus {
  outline: none;
  box-shadow: -2px 0px 0px 0px rgba(47, 147, 241, 0.5);
}
<div class="card">
  <div class="header">
    <div class="customerAvatar"></div>
    <div class="ownerAvatar"></div>
  </div>
  <div class="details">
    <div class="caseContainer">
      <input name="case" id="case" placeholder="Case tags" />
      <div class="tags">
        <div class="tag">AAAAAAAAAAAAA</div>
        <div class="tag">BBBBBb</div>
        <div class="tag">CCC</div>
        <div class="tag">D</div>
        <div class="tag">FFFFFFFFFFFFFFFFF</div>
      </div>
    </div>
    <textarea name="profilert" id="profilert" placeholder="Profilert"></textarea>
    <input name="dato_frist" id="dato_frist" placeholder="Dato - Frist"></input>
    <input name="kontakt" id="kontakt" placeholder="Kontakt"></input>
  </div>
</div>

Answer №2

I set a specific height for the parent element to be 100px.

Then I added a height of 90% to the scrolling element.

The reason for using 90% is to prevent the scrollbar's height from overlapping other elements.

This way, the height of your scroll element is relative to its parent element.

.card {
  width: 300px;
  height: 200px;
  padding: 0.5rem;
  margin: 1rem;
  font-size: 0.9rem;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 4px 6px rgba(0, 0, 0, 0.23);
  border-radius:10px;
}
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.customerAvatar {
  background: green;
  width: 50px;
  height: 50px;
}
.ownerAvatar {
  background: #e52d27;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  align-self: flex-start;
}
.details {
  display: grid;
  flex-grow: 1;
  grid-gap: 5px;
  grid-template: 4fr 1fr / 1fr 1fr;
  
}
.caseContainer {
  display: inline-block;
  min-height: 0;
  min-width: 0;
  height:100px;
}
.tags {
  display: flex;
  flex-wrap: wrap;
  overflow-y: scroll;
  max-height:90%;
}
.tag {
  background: lightcoral;
  box-sizing: border-box;
  margin: 2px;
  border-radius: 2rem;
  padding: 0.25rem 0.75rem;
  max-width: 100%;
  word-wrap: break-word;
}
input,
textarea {
  width: 100%;
  box-sizing: border-box;
  background: transparent;
  border: none;
  font: inherit;
  transition: all 0.2s;
}
textarea {
  resize: none;
}
textarea::-webkit-scrollbar {
  width: 3px;
}

textarea::-webkit-scrollbar-track {
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
}

textarea::-webkit-scrollbar-thumb {
  background-color: rgb(47, 147, 241);
  border-radius: 3px;
}

input::placeholder,
textarea::placeholder {
  color: rgba(0, 0, 0, 0.3);
}

input:focus,
textarea:focus {
  outline: none;
  box-shadow: -2px 0px 0px 0px rgba(47, 147, 241, 0.5);
}
<div class="card">
  <div class="header">
    <div class="customerAvatar"></div>
    <div class="ownerAvatar"></div>
  </div>
  <div class="details">
    <div class="caseContainer">
      <input name="case" id="case" placeholder="Case tags" />
      <div class="tags">
        <div class="tag">AAAAAAAAAAAAA</div>
        <div class="tag">BBBBBb</div>
        <div class="tag">CCC</div>
        <div class="tag">D</div>
        <div class="tag">FFFFFFFFFFFFFFFFF</div>
      </div>
    </div>
    <textarea name="profilert" id="profilert" placeholder="Profilert"></textarea>
    <input name="dato_frist" id="dato_frist" placeholder="Dato - Frist"></input>
    <input name="kontakt" id="kontakt" placeholder="Kontakt"></input>
  </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 to set the default value for an angularJS select dropdown

Can someone assist me with setting a default value for a select dropdown using AngularJS? I have explored similar threads on StackOverflow, but none of the suggested solutions have resolved my issue. Therefore, I am reaching out to seek help here. Essenti ...

Identify when a div reaches the end of the screen using CSS

I've developed a custom dropdown feature using Vue 2 and TypeScript to meet our specific requirements (without relying on jQuery). The dropdown functions correctly, opening the options list downwards when the main box is clicked. One enhancement I a ...

Chrome is giving me trouble with the Select (dropdown) background image feature

Is it possible to set an image as the background for a select/drop-down menu? I've tried using the following CSS, which works in Firefox and IE but not in Chrome: #main .drop-down-loc { width:506px; height: 30px; border: none; background-color: Tr ...

Activating text wrapping functionality

My current project involves converting HTML to PDF using jsPDF. In order to ensure that every word appears in the exact location as it does in the original HTML, I decided to wrap each word in <span> tags. Specifically, I have a font tag (not added b ...

What is the best way to retrieve the name of a dynamic form in a Controller

How can I retrieve the dynamic form name in my controller? See below for the code snippet: HTML <form name="{{myForm}}" novalidate> <input type="text" ng-model="username" name="username" required/> <span ng-show="(submit & ...

How can I make a bootstrap container maximize the available viewport space?

I've come across several similar posts, but none seem to address my particular dilemma. My challenge lies in presenting a table at the end of a bootstrap grid: <div class="container-fluid"> <!-- Various rows with different size ...

Looking for tips on resolving issues with the bootstrap navigation bar?

Check out this code snippet: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport ...

The 'Bfrip' button is missing from the DOM

Having some issues with displaying table content using DataTables. Everything seems to be working smoothly except for the Buttons, which are not appearing as expected. <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.1 ...

What is the best way to position an element on the left side of the navbar without having it animated?

Could someone assist me in placing the Life's Good logo on the left side of the nav bar without applying the animation from the "btn" class? Below is a snippet of my code with an example where I want the logo highlighted in Yellow: * { padding:0; m ...

How to Incorporate LessCSS into the Blueprint Framework?

Can LessCSS be integrated with Blueprint framework? What are the prerequisites for starting? ...

Tips for preventing the larger background from displaying a scroll on a web page

Specifically tailored for this specific page: I am looking to eliminate the scrollbar at the bottom of the browser, similar to how it appears on this page: Thank you ...

What are some solutions for repairing unresponsive buttons on a webpage?

My task is to troubleshoot this webpage as the buttons are not functioning correctly. Here’s a snippet of the source code: <!DOCTYPE html> <html lang="en"> <head> ... </head> <body> <div id="container" ...

Floating CSS containers

Apologies for not including a picture. You can view the design I am trying to achieve here. I am attempting to create two boxes with a third box below them, and another box on the right side of the layout. All enclosed within a larger container. Everythin ...

Ensure that when adjusting the height of a div, the content is always pushed down without affecting the overall layout of the page

My webpage contains a div element positioned in the middle of the content, with its height being adjustable through JavaScript code. I am seeking a way to manage the scrolling behavior when the height of the div changes. Specifically, I want the content t ...

How can you quickly navigate to the top of the page before clicking on a link in the same window/tab?

Could someone assist me with a coding issue I am facing? I would like to be able to go to the top of the page when clicking on a link and have the link open in the same tab. I attempted to implement this functionality using the following code, however, I ...

Ways to determine if a textbox is empty and trigger a popup notification with jQuery

I'm having trouble with checking if the textbox is empty in my form. Every time I try to submit, instead of receiving an alert message saying "Firstname is empty," I get a message that says "Please fill out filled." ('#submit').click(func ...

What is the best way to obtain a direct file link from a server URL using JavaScript?

After acquiring a file located at /home/johndoe/index.html, I am utilizing a tool like XAMPP to host, with the folder /home being hosted on localhost. The variables in play are as follows: $server_addr = "localhost"; $server_root = "/home"; $file_dir = " ...

Increase the height of a div dynamically in HTML during program execution

Within my datagrid, there exists an expandable/collapsible section above the content (see Picture 1 https://i.sstatic.net/N68Rl.png). Upon expanding the content, a scroll bar appears within the datagrid element to display the data (see Picture 2 https://i. ...

Adding JavaScript to dynamically loaded AJAX content

I'm new to AJAX and JavaScript and unsure of how to get it working. Here is the website: When you click on portfolio images, the details load via AJAX. I want to create a slideshow for projects with multiple full-sized images. However, due to the co ...

One way to eliminate a prefix from a downloaded file path is by trimming the URL. For example, if you have a URL like "http://localhost

As my web app runs on port number, I am looking to download some files in a specific section. However, the download file path is being prefixed with "". <a href={file_path} download={file_name}> <Button variant={"link"}> <b>Dow ...