Is it possible to conceal the portion of an element that is obscured by another?

https://i.sstatic.net/ZR8M7.png

When applying a hover effect in the image, you can see that the green box appears below. Is there a way to prevent the intersecting part from showing during hovering over the yellow box?

Here is the code snippet:

<div class="container">
  <div class="son">
    This is a title, while has hovering, I dont should see the green square under
  </div>
</div>

.container{
  height: 507px;
  width: 500px;
  background-color: rgba(168,207,69,1);
  border-radius: 32px;
  margin-top:50px;
  z-index:1;
}
.son:hover{

  background-color: rgba(255,207,69,0.5);

}
.son{
  z-index:2;
  position:relative;
  top:-20px;
  width: 300px;
  height:50px;
  background-color: rgba(255,207,69,1);
}

https://jsfiddle.net/7zm8ascx/

Answer №1

To completely cover the green rectangle in your .son:hover background-color, simply set the opacity to 100%. Make sure to adjust the color values accordingly to match the original color with 50% opacity.

.container {
  background-color: rgba(168,207,69,1);
  border-radius: 32px;
  height: 500px;
  margin-top: 50px;
  width: 500px;
}
.son:hover {
  background-color: rgba(254,230,166,1);
}
.son {
  background-color: rgba(255,207,69,1);
  height: 50px;
  position: relative;
  top: -20px;
  width: 300px;
}
<div class="container">
  <div class="son">
    This is a title, while has hovering, I dont should see the green square under
  </div>
</div>

Answer №2

To accomplish this goal, consider utilizing an opaque color such as rgba(255, 231, 161,1).

If opacity is not necessary, opt for using standard color formats like rgb or HEX colors instead of rgba.

Answer №3

Make a simple modification to this snippet

.son:hover {
  background-color: #FFE7A2;
}

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

Do you prefer CSS icons or icon images?

I am currently managing a website that contains numerous icons, each of which is associated with a separate image. I have been contemplating the idea of combining all these icons into one image to improve loading speed. However, I am unsure if this would b ...

A guide on grouping an entire CSS file under one class umbrella

Is there a way to encapsulate a large number of CSS declarations so they only apply when the parent has a specified class? div { color: #ffffff; } ... a { color: #000000; } Can it be structured like this, with a parent class containing all the CSS r ...

Show the WooCommerce checkout shipping fields and eliminate the "Choose a different delivery address?" checkbox

Is there a method to eliminate the checkbox labeled "Ship to a different address?" on the woocommerce checkout page while still displaying the shipping fields? I have attempted the following: add_filter( 'woocommerce_cart_needs_shipping_address', ...

The default setting for the calendar picker indicator should be enabled

Whenever I hover my mouse over it, an indicator pops up, but I want to make it the default <input type="date" class="form-control" name="Date" [(ngModel)]="opening_date" (ngModelChange)="Operating()" style="width:550px" required> inp ...

The content spills over when applying the Bootstrap Grid system

I am working on creating a display heading that includes images on both the left and right sides of the heading. The layout looks great on larger displays, but as I shrink the display size, the text in the heading overflows the column on the right, causing ...

Enhanced Button Dropdown Function

I have the following HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Expanding Dropdown Menu</tit ...

Eliminating unnecessary CSS classes

There are multiple references to the specific ".wiki-content" class in the stylesheet: .wiki-content ul,.wiki-content ol,.wiki-content dl { padding-top:0; margin-top:0; } .wiki-content a,.wiki-content a:link,.wiki-content a:visite ...

What is the best way to make my text scroll horizontally if the container is not wide enough?

Instead of overwhelming you with code, I'll just share a link to the types of animations I've come across so far. Although these options are close to what I'm looking for, none of them are exactly right. The one that comes closest to my vis ...

Is the modal popup displayed in the center of the screen when the submit button is clicked?

My bootstrap modal popup is not working when I click the submit button. I can only use Bootstrap4, JS, and jQuery3.0. JS Fiddle function check() { var inputs = document.getElementsByTagName("input"); var inputs = document.getElementsByTagName("sele ...

Make a big picture fit into a tiny container

I have a question about image rendering. What occurs when we try to fit a large image into a small container? Consider, for example, creating an HTML page with a 100x100 px image on a device with a pixel ratio of 2. Situation 1: Placing the image inside a ...

Customizing the arrow of a Bootstrap tooltip and adjusting its positioning

I've implemented a bootstrap tooltip to show an image in it. So far, I've been successful in achieving this. https://i.sstatic.net/hgzyL.png However, my current requirement is as follows: https://i.sstatic.net/xcxWZ.png I would like to adjust ...

Issues with CSS styling are affecting the display of a form

Hey there! I was working on creating an order form for my website, and everything was going smoothly until I hit a snag while styling the webpage. The problem is that the legends of the form are extending all the way to the right side of the page, and the ...

Angular TS class with an ever-evolving and adaptable style

Currently, I am working with angular 9. Does anyone know a way to dynamically change the CSS of a class in a component? .stick-menu{ transform: translate(10px,20px); } I am looking to dynamically adjust the position of x and y values. For example: .stic ...

Is there a way to ensure consistent heights for various elements within a column, even if their heights are

Currently, I am utilizing the flex property to create uniform columns and vh to ensure they have the same height. This setup is functioning properly, but within each column, there could be a varying number of items. I am interested in having the elements w ...

Assistance required for locating elements in Selenium using Css Selector

Hi there, I'm not really a developer. I've got two checkboxes in my table without any IDs. Usually, I can easily work with Selenium when elements have IDs, but in this case, the table was generated using jquery datatables and no automatic ID ass ...

Looking to effortlessly move and arrange items with ng2-drag-drop in Angular 2?

I have encountered a problem with the ng2-drag-drop library. I am trying to drag and drop items from one div to another, and then freely move the dropped item within the droppable area. One issue I'm facing is that when I drop my draggable item in th ...

Is there a way to eliminate the underscore that appears beside the image?

Here is a simple example of a webpage: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style type="text/css"> * { border:0; margin:0; padding:0; } body { background:# ...

Guidelines on centering an AJAX spinning animation within a parent div

Below is the basic structure of an HTML document for a webpage. <div class="grand-parent"> <div class="header">Heading</div> <div class="parent-div"> <div class="child-div-1"></div> ...

Ways to create space between rows

Here is some code structure that I'm working with: .col_1_6 { width: 70%; float: left; } .col_1_4 { width: 30%; float: left; } .row-content { clear:both; padding-bottom: 105px; } <div class="row-content"> <div ...