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

Transforming the style of a particular element within React using Array().fill().map's method

Looking for a way to dynamically change the color of an array in React + styled jsx? Let's say you want to change the color when the number of elements in the array is a multiple of 4 (e.g. the index is 4, 8, etc.) Is there a clever solution to achi ...

Display a hidden div upon loading the page if a certain condition is met

As a beginner in this field, I am struggling to assist a friend with a project. He needs a simple quote form that can generate HTML quotes for his client on a private WordPress page. The form should display a specific div based on the radio button selecti ...

Modifying the Placeholder Color in a Material UI Autocomplete: Tips and Tricks

In my team, we are working on two projects that both utilize an internal library with a header containing a search box. In one project, the placeholder text "Search" displays normally. https://i.stack.imgur.com/lhL5V.png However, in the second project wh ...

What is the significance of a colon appearing at the start of HTML attribute names in a Vue template?

<circle r="3" :cx="airport.x" :cy="airport.y" class="airport__marker" /> Are the attributes v-bind:cx and v-bind:cy equivalent to what is shown above? ...

Modify a CSS style with JavaScript or jQuery

Can CSS rules be overwritten using jQuery or JavaScript? Imagine a table with rows categorized by different classes - "names" for persons and "company" for companies. How can we efficiently hide or show specific rows based on these classes? If we have a ...

Customize the appearance of parent components based on the content of their child elements

I am currently working on a component that contains multiple instances, each with its own unique internal component (acting as a modal wrapper). I need to customize the size of each modal instance independently. How can I achieve this customization when th ...

Resizeable drag and drop two-column design

Experimenting with creating a drag re-sizable layout using jQuery UI was quite an interesting challenge for me. If you want to check out the result, here is the link. However, my original goal was to achieve something different from what I ended up with. ...

The mobile page is refusing to scroll, causing all the text to bunch up at the top of the screen

After learning HTML/CSS/Js/PhP over a few months, I recently completed my first website. I am facing an issue with one of the pages on my website when viewed on a mobile device. The parallax scrolling header image does not scroll either horizontally or ve ...

Tips on Updating Array Value with jQuery

I have been working on using jQuery to edit array values. Here is my approach: From a modal, each time I click the "Add item" button, it pushes values to an array and appends the data to a table. var iteminfo = { "row": 'row' + cnt, "ma ...

Another option instead of using the .siblings() method would be

Is there an alternative to using the .siblings() method in jQuery for traversing through divs of a specific class in separate container divs? How can this be achieved with the following code: HTML: <div id="container1"> <div id="1"></di ...

Is there a way to keep my fixed footer container from moving while zooming in and out on a webpage

Is there a way to prevent the bottom text from shifting when zoomed in or out on the page? The rest of the content remains stable, but due to using position:absolute for this section to stay at the bottom of another div (content), it causes movement. #con ...

Automated HTML loader

I have a webpage that utilizes AJAX to load portions of HTML content. These fragments contain images, some of which are specified in a separate CSS file using background-image properties. I am trying to implement a pre-loader so that the loaded content w ...

Utilizing Core-TransitionEnd in Polymer: A Beginner's Guide

After a ripple animation on an item has executed, I would like to run a function. Currently, I am using the following code: <post-card id="card1"> <img width="70" height="70" src="../images/start.png"> <h2>P ...

Creating an SVG element that adjusts to the size of its parent container: tips and tricks

I'm attempting to achieve the following: Displaying an SVG square (with a 1:1 aspect ratio) inside a div element. When the width of the div is greater than its height, the square should adjust to fit within the container based on the height (red box ...

What is the best way to make a CSS change triggered by a onScroll() event stay in place permanently?

I need a div element to be displayed as a "scroll back to top" button on my webpage when the user has scrolled past a certain point. To achieve this, I am using the JavaScript code provided below: $(document).ready(function() { $(window).scroll(functio ...

Interested in learning how to code games using JavaScript?

Hi everyone, I'm currently exploring the world of Javascript and have been tasked with completing a game for a class project. The game involves a truck that must catch falling kiwis while only being able to move left or right. A timer is set for two m ...

Customize the border style for the span element

I attempted to use the code below in JavaScript/jQuery to adjust the border thickness. Unfortunately, it seems to be ineffective. Can someone please assist me? //$("span").css({"border":"4px solid green"}); document.getElementById("192.168.42.151:8984_ ...

What could be causing my ASP.Net MVC script bundles to load on every page view?

I'm a bit puzzled. The _layout.cshtml page I have below contains several bundles of .css and .js files. Upon the initial site load, each file in the bundles is processed, which makes sense. However, every time a new view is loaded, each line of code f ...

Uncovering Inline Styles Infused with Javascript for Effective Debugging of Javascript Code

SITUATION: I have recently inherited a website from the previous developer who has scattered important functions across numerous lengthy JS files. I am struggling to track down the source of an inline CSS style within the JS or identify which function is d ...

Combining a standard JSS class with Material-UI's class overrides using the classnames library

I am exploring the method of assigning multiple classes to an element in React by utilizing the classnames package from JedWatson, along with Material-UI's "overriding with classes" technique. For reference, you can see an instance in MUI's docu ...