`Before inheriting height from its own element, CSS``

Currently, I am working on creating a pop-up block to enable language switching on a website. The design of the block includes specific shadows that need to be separate from the pop-up block itself. In order to achieve this, I decided to position the shadow under the block using the ::before pseudo-element.

The challenge I'm facing now is making sure that the shadow inherits the height from the element it is applied to. As the block currently contains three language options, I cannot set a static height as more languages may be added in the future.

Here is my code snippet:

.l-pop {
  width: 150px;
  height: auto;
  position: absolute;
  bottom: -80px;
  background: #FFFFFF;
  box-shadow: 0px 4px 80px rgba(0, 0, 0, 0.07), 0px 1.67px 33.42px rgba(0, 0, 0, 0.0503), 0px 0.89px 17.87px rgba(0, 0, 0, 0.0417), 0px 0.5px 10.02px rgba(0, 0, 0, 0.035), 0px 0.27px 5.32px rgba(0, 0, 0, 0.0283), 0px 0.11px 2.21px rgba(0, 0, 0, 0.0197);
  border-radius: 6px;
  z-index: 3;
  padding: 8px 5px;
  display: flex;
  flex-direction: column;
}

.l-pop::before {
  content: '';
  width: inherit;
  height: inherit;
  /* height: 100% */
}
<div class="language__pop-up l-pop">
  <div class="l-pop__item">
    <img src="" alt="">
    <p></p>
  </div>
  <div class="l-pop__item">
    <img src="" alt="">
    <p></p>
  </div>
  <div class="l-pop__item">
    <img src="" alt="">
    <p></p>
  </div>
</div>

Interestingly, the width inheritance for the ::before element works fine at 150px, but the height inheritance does not behave as expected.

Is there a solution where the ::before pseudo-element can effectively inherit its height from the parent element?

I have tried both height: inherit and height: 100%, but neither has yielded the desired outcome.

Thank you!

Answer №1

The reason it's functioning properly with regards to width is because you specified the element with the class language__pop-up l-pop to have a width of 150px. However, when you set the height to auto, that's why it's not working for height. To resolve this issue, try setting the height in pixels just like you did for the width of the element with the class language__pop-up l-pop

Answer №2

I discovered a solution by including position:absolute in the before element.

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

What is the most effective approach for updating a CSS file to a newer version?

Whenever I make changes to the CSS, I typically update the version of the CSS file in the master. This requires me to upload both the CSS and master files. Is there a way to change the CSS version without having to upload the master file? <link rel="st ...

Top method for showcasing data on a webpage

Currently, I am working on developing an intranet site that retrieves test data from a database and presents the results on a standard HTML webpage. At this point, Python is configured as cgi and is providing the desired outcomes. However, there is now a ...

HTML needs to be wrapped around every set of three items using C# ForEach loop

Currently, I am faced with the task of constructing an HTML code structure within C# code behind. Specifically, I need to insert an HTML element that spans 3 columns in a row of 12 columns (utilizing Zurb Foundation). To achieve this, I am iterating throu ...

Asynchronously load an AngularJS controller from AJAX without altering the route

I am looking to dynamically load an Angular controller after making an AJAX call that generates a new view in HTML. Here is the setup I currently have: Example of a View: HTML Snippet From AJAX <!-- CVS Pharmacy Extracare - Add View --> <d ...

Achieving vertical centering by adjusting padding within the parent container

I've successfully set up a DIV with a height of 200px and an inner div at 150px, leaving me 50px for the image caption. Now I want to vertically center the text within that remaining 50px. .captioned { width: 300px; height: 200px; display: fl ...

Showing XML content with JavaScript

Trying to parse a simple XML list using JavaScript, but having trouble formatting it the way I need. <TOURS> <MONTH> <TOUR> <NUMBER>1</NUMBER> <VENUE>City Name - Venue Name</VENUE> < ...

Creating a collapsible navbar using JavaScript

I have implemented a responsive navbar that shrinks with the page size using @media screen. Everything works well, but I need the navbar to collapse into a vertical drop-down menu when the page size is very small, requiring a click to open. Unfortunately, ...

Error message: "An issue occurred with the Bootstrap Modal in

I've designed an AngularJS app like so: <!DOCTYPE html> <html ng-app="StudentProgram"> <head> <title>Manage Student Programs</title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2. ...

Issue with CSS elements unable to shift to the left

My attempt to align CSS elements to the right using margin-right: 200px is not working, while margin-left: 200px does. This issue arises even though my CSS file appears as follows: .wrapper { display: inline-block; position: abso ...

switching tabs on a webpage

My PHP page has a menu tab with tabs labeled as Dash and Project. The Dash tab contains a table displaying data. The scenario is that when I click on a row in the table within the Dash tab, it should navigate to the Project tab, where a simple form is disp ...

The jQuery AJAX call consistently triggers the error handler, despite the fact that the returned data is valid

I'm facing an issue where I am trying to retrieve content from a .php file using an ajax query. The datatype is set to json and in my php file, I am returning the data like this: echo json_encode($myData). However, the ajax query always goes into "err ...

Retrieve the Span class value contained within a Select Option

I realize it may appear repetitive, but it is not. This is the appearance of my select: <select id="avpMy4Y7E4cH_-iIRmmAK6-2GsEOu6Sjr-0-0"> <option value="1Ltr [ <span class=money>Rs.1,495.00</span> ]">...< ...

What are some ways to display alternative content when JavaScript is not enabled?

When JavaScript is disabled, I want to display an entirely different set of content. While I am aware that the <noscript> tag can be used for this purpose, how can I ensure that the remaining page elements are hidden as well? Any suggestions would b ...

Element search feature added to dropdown menu

I am seeking valuable advice and guidance to navigate through this challenging situation. Here's the scenario: I need to create a dropdown menu similar to the one below. <ul class="dropdown"> <li><a href="#">America</a></l ...

Jquery functionality fails to execute post-Ajax request

Here is the function in question: $(document).ready(function() { $('.post_button, .btn_favorite').click(function() { //Fade in the Popup $('.login_modal_message').fadeIn(500); // Add the mask to body $('body').append(' ...

Unable to showcase array JSON values on HTML using ng-model

Utilizing ngTagInput for autocomplete textbox and successfully receiving suggestions. To display the values of data-ng-model (named "list") I am using: {{list}} and it is showing correctly. However, when selecting "list1", the display appears as: [{"lis ...

Unable to substitute a value using the useState hook in React

Whenever I click a key, I attempt to update the value of a variable but it appears not to be working as intended. ↓ The current implementation is not effective and needs improvement import React, { useState, useEffect } from 'react'; const Li ...

Choose tag using position in a sequence

I am working on updating the label text "E-mail" to say "User Name" in this HTML markup. The only tool I have access to for this task is jQuery. <div class="foo" style="border:1px solid #444"> <span class="field-with-fancyplaceholde ...

Having trouble with sharing a basic HTML file?

Just the other day, I crafted an HTML file using Notepad++. I have a bit of a novice question: How can I send this file to a friend via email without them being able to view the code, only the actual webpage when they open it? The file is not online, jus ...

Conceal SVG components using JavaScript

I'm diving into the world of SVG animation using JavaScript. I have a scenario where there is a play button at the beginning, which, when clicked, triggers the music to start playing and should hide itself. Here's a look at my HTML setup: <a ...