How can I incorporate calc() with fit-content or a similar function?

Is there a way to set the height of a div to "fit-content minus 15px" without using JavaScript? I attempted to use calc(), but it did not yield the desired result.

My objective is to dynamically adjust the height of an element containing multiple p tags, each with a border-bottom. I need to hide the border of the last p tag due to framework limitations that do not allow the use of last-child or last-of-type selectors. Thus, I am attempting to shorten the container's height to achieve this.

.wrapper {
  width: 100px;
  background: red;
  height: calc(fit-content - 15px)
}

.child {
  height: 100px;
  width: 50px;
  background: blue;
}
<div class="wrapper">
  <div class="child"></div>
</div>

P.S. I am utilizing Sass in this project, although I am not very familiar with it.

Answer №1

Apply the clip-path property to remove 15px from the bottom of an element

.wrapper {
  width: 100px;
  background: red;
  clip-path: inset(0 0 15px 0);
}

.child {
  height: 100px;
  border-bottom: 15px solid green; /* this will be hidden */
  width: 50px;
  background: blue;
}
<div class="wrapper">
  <div class="child"></div>
</div>

Answer №2

Use a mask to conceal the bottom 15px

.container {
  width: 100px;
  background: red;
  -webkit-mask: linear-gradient(#000 0 0) 0 -15px no-repeat;
}

.item {
  height: 100px;
  width: 50px;
  border-bottom: 15px solid; 
  background: blue;
}
<div class="container">
  <div class="item"></div>
</div>

Answer №3

To create a layered effect, you can utilize the CSS pseudo-elements ::after and ::before

.container{
   position: relative;
   z-index: 2;
}
.container::after {
   content: '';
   position: absolute;
   inset: 0;
   z-index: 1;
   width: 100%;
   height: calc(100% - 20px);
}

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

Utilizing CSS for a responsive background image

While constructing a website, I encountered an issue where the client is using a mobile device and I want to prevent them from loading a particular background image. For larger screens, my plan is to incorporate approximately 5 images with different resolu ...

Having trouble capturing Ajax calls with Selenium? Reach out for assistance with HTML coding or Selenese scripting

While using Selenium IDE to record a .Net application, I encountered a scenario where a textbox is present and I need to enter a name to search for. Once I start typing, matching options appear in a dropdown below that I must select before the application ...

After attempting to read in this JSON text string, it is stubbornly refusing to display properly with a line break

I have a snippet of text stored in a JSON file that appears like this "I want a new line\nhere". This is the code I am using to display the text after replacing the \n with a <br />: <p className="subtitle is-5 has-text-w ...

Applying a CSS border to a div that perfectly encloses a span, adjusting to the

My goal is to create a nested structure where a div contains a span element like this: ---------- |Sentence| ---------- ----------------- |It's a looooong| |sentence | ----------------- While it works well for short sentences, long ones end u ...

Adjust various text lengths to fit web browser content

I am using a web browser within my Windows Form. I am populating it with text each time, with almost the same text size in each loop. The size of my web browser is fixed, and I want to automatically adjust the text content to fit the browser. For example, ...

Issues with displaying video content and controlling the Bootstrap 5 video carousel

I have encountered an issue while coding a website for a friend's company. He requested a video carousel to be added to his existing site, so I incorporated links and scripts for Bootstrap in order to create a gallery for his products and a carousel t ...

Iframe form submissions

I am interested in accomplishing the following task. My objective is to submit a form to my booking engine and show the results on either a new page or within a Div element. Ideally, when the user clicks the submit button, it would display an Iframe or re ...

An innovative approach to incorporating multiple patterns into HTML input using markup alone, without the need for JavaScript

Input fields are currently set to accept phone numbers in the format 555-555-5555 using the pattern [0-9]{3}-[0-9]{3}-[0-9]{4}. Is it possible to modify the pattern to also allow phone numbers in the format of 5555555555? <input type="tel" cl ...

Restricting zooming to only occur within the img element in a UI

Is there a method to enable image zoom inside specific divs without affecting the overall page zoom? At the moment, I have: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale ...

How can I make my opacity change on hover without the need for JavaScript?

I've been attempting to design a book cover that will become fully visible when hovered over, but for some reason it's not working #book_cover { display: block; margin-left: auto; margin-right: auto; width: 25%; height: 71%; ...

Choose the label by utilizing the CSS selector

I am currently using CSS to create tabs with radio buttons. However, I am struggling to figure out how to select the corresponding <label> for the radio button. To keep the labels separate from the content and display them as tabs, I have structured ...

Encountered a parsing error when attempting to integrate SCSS with webpack and babel setup

I am facing an issue while trying to integrate SCSS into my webpack and babel setup. When running npm run build, I encounter an error that I'm unfamiliar with. As a beginner in using webpack and babel, I'm unsure about the necessary changes requ ...

Determining with jQuery if the right element has been successfully "dropped"

Imagine having 10 different draggable boxes and 2 droppable areas. You need to correctly match 5 boxes with droppable area 1 and the other 5 with droppable area 2. If a box intended for droppable area 1 is mistakenly dropped into area 2, it should not wor ...

Adjust the border color of the <input> element when it is clicked on

I'm currently working on a login screen for my next.js application and I've encountered an issue where the border color changes to a mixture of white and blue when I select an input field. https://i.stack.imgur.com/R2yKa.png I attempted to reso ...

How to Programmatically Assign Bootstrap Class to an Element Using Angular 2

I am working on a page with several input boxes that need to be flagged for certain criteria. <div class="form-group"> <label class="d-block">Allowance Type</label> <div class="input-group"> ...

Having difficulty setting a value for a tooltip with replaceWith() function

When using jQuery's .replaceWith() method to insert new DOM contents, I noticed that all content gets replaced except for the value of the title. Even though I tried different approaches, the tooltip only displays {{descriptions.title}} instead of the ...

I need to figure out how to nest a div inside of a ul-li-a and ensure that the text inside the

In my search button, I have a cached list of options. When I select one, it should trigger the menu and choose the correct option. However, I am having trouble comparing the innerText of a div with the selected option from the search area. Both a and div e ...

Unexpected behavior observed: Title attribute malfunctioning upon double clicking span element

I recently implemented the following code: <span title="hello">Hello</span> Under normal circumstances, the title attribute functions correctly when hovering over the element. However, after double clicking on the span element (causing the t ...

What is the method for HTML inline handlers to retrieve the global window object and the variables contained within it?

During my coding test, I encountered an interesting scenario. I had a function called write and used a button with an inline onclick handler to trigger the write() function. function write(text) { alert(text) } <button onclick='write("Some tex ...

One column in HTML table row is functional, while the other is not functioning as intended

Currently, I am working on a mapping application that allows users to add features to a database. These features are then displayed on a mapping page in an HTML table. The table consists of three columns: Feature Name, Selected (with an on/off slider switc ...