CSS - How child elements can appear transparent over their parent

Is it feasible to create a scenario where a child element has the ability to see through its parent, displaying the background image only within the child and not in the parent element as illustrated below?

Can this be achieved using CSS or any other method?

https://i.sstatic.net/coO7l.jpg

Answer №1

It is not possible to directly subtract one element from another to achieve this effect; a workaround is required. Imagine the white strip as three individual elements placed side by side. The outer ones are filled with white, while the center remains transparent. These three elements are contained within a wrapper with a white border to create the illusion of white edges. You can see this effect in action in the example provided below.

img {
  width: 100%;
}

.center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.row {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100px;
  border: 5px solid white;
}

.row .col {
  display: inline-block;
  height: 100%;
  background-color: white;
  width: 100%;
}

.row .col.m {
  background-color: transparent;
  width: 500px;
}

.row .col span {
  color: white;
  text-align: center;
}
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSfz6VkKDw0b3AacQg2PhSq8BpHf1z8Ngg-iYt_1Qqu5cR6Q3_Z&usqp=CAU">

<div class="center row"> 
  <div class="l col"></div>
  <div class="m col">
    <span class="center"> Welcome back, <br> user1! </span>
  </div>
  <div class="r col"></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

Troubleshooting CSS Text Display on HTML5 Video for Mobile Devices

I am currently working on positioning text and a button over an HTML5 video without using media queries to address mobile display issues. The problem arises when using the car-image-overlay class from Bootstrap 4 to show the div containing the text over th ...

The XML request fails to retrieve any output from the PHP script

I am seeking tools to enable the calling of .php from .html files. Here is an issue: while this example successfully works in a .php file: <html> <head> <meta http-equiv="content-type" content="text/html" charset="utf-8"> &l ...

Modifying the HTML content of a span element does not always initialize all of its properties

I've been working on setting up a comments-reply system for my website. I have all the necessary PHP files in place, but I'm facing an issue with updating the vote counts dynamically. In the image provided, you can see that upon voting once, I a ...

My HTML form submission to the node.js file is stuck in an endless loading loop

As I work on setting up a basic form submission on my server to collect contact information, I run into an issue. The data is successfully received by my node.js server file upon submission but when I attempt to submit the form, the page tries to load the ...

Choosing Dropdown Options Using Query Strings

Currently, I am utilizing Bootstrap 4 in conjunction with CodeIgniter 3 for my project. The webpage features a simple dropdown group that offers various options to choose from. By default, the value displayed is 'Please Select'. However, I am in ...

What is the best way to include a class in the <td> element of a dynamic table?

My goal is to sum up the values in a specific column of a dynamic table by attaching an id property to each row. I am specifically focused on assigning an id to each <td> in every row of the table. UPDATE: Although I have all 4 keys in the <td> ...

The div width set to 100% is not functioning properly upon the initial form loading in IE11, however, it is working

[![enter image description here][1]][1]Can anyone assist me in resolving this issue? When my Div with the id "Coverage" loads initially, its width is set to the content width. However, after a refresh, it expands to 100% width. This problem does not occu ...

Ways to make certain HTML elements stay fixed on a webpage while allowing others to be scrollable

In this layout, the page features a navbar at the top followed by a row with two columns. The left column displays the user's profile information (such as profile picture and short bio), while the right column shows other information. However, when a ...

Side Panel Extending Off Screen Upon Resizing

I'm encountering an issue with the sidebar on my HTML page. The problem arises when I click the 'Upload Data' button, causing the sidebar's header to extend beyond the screen if I resize the window. The only way to fix this is by refres ...

Diverse Values within the Inner Border

Is it possible to create an inner border with unique values for each side? For instance: Top: 20px Right: 80px Bottom: 40px Left: 10px Can you provide an example of how this can be achieved? Thank you! :) ...

Guide to configuring an Angular Material Footer using Flex-Layout

Could someone help me with setting up the footer in my Angular Material app? I want it to: stick to the bottom when the content height is smaller than the view-port move down or get pushed down when the content height exceeds the view-port One important ...

Is there a way to invoke an AngularJS function using JavaScript without specifying the ID parameter?

I am interested in invoking an AngularJS function without relying on the use of an id parameter. My current method for calling the AngularJS function is shown below: JS File: angular.element(document.getElementById('service_search')).scope().s ...

Enhance the appearance of Bootstrap forms with custom styles

After customizing a selection form in Bootstrap to mimic a specific image, I have successfully added the necessary styles. If you wish to see the html and css used to achieve this design, please refer to the link below: https://i.sstatic.net/b67Yf.png HT ...

Using the Drupal Colorbox module with Internet Explorer

This problem has been driving me crazy! I'm struggling to make Colorbox show the borders correctly in IE7 (and even in IE6, but I'll settle for just IE7 at this point!). You can check out the issue here. When you click on a picture in the galler ...

Creating a half-page Bootstrap Carousel: Steps and Tips

Is there a way to make this Bootstrap 3 carousel half-page? I'm struggling to figure out what adjustments need to be made in order to achieve that. It displays well in a small window, but once I expand it to full screen, the carousel takes over the en ...

Do frameworks typically result in redundant CSS declarations?

Working on my latest Wordpress theme project, I have integrated the Bootstrap framework. One of the styles included in the Bootstrap CSS file is: input, textarea, .uneditable-input { width: 206px; } This style rule is causing issues with how my search ...

What is the best way to include a variable in an anchor tag?

In my Vue application, I have a header that displays different links based on the environment. The root of the link changes depending on the environment, so I've stored an environment variable with this root value. I'm importing this variable in ...

Missing td data when using Beautiful Soup to parse HTML tables in Python

When attempting to extract a table using Beautiful Soup, I encounter an issue. from selenium import webdriver from bs4 import BeautifulSoup import pandas as pd import numpy as np import lxml import xlrd HorseNo = ["T421"] ...

AngularJS: Creating a dual-column layout with alternating styles

Struggling to create a two-column layout that repeats in AngularJS using a JSON object of image data. I'm aiming for a display of images in a side-by-side format, but my odd/even logic seems to be off no matter what adjustments I make. Can anyone poin ...

What would you name this particular element?

I want to create a unique slider design but I'm unsure where to begin or how to search for information because I don't know the correct terminology. Does this type of slider have a specific name? I heard about Marquee, but that seems like someth ...