Instructions on setting div opacity when Overflow is set to visibleExplanation on setting opacity for div with Overflow

In my HTML code, I have a div element and an image tag stacked one on top of the other. The div is smaller than the image. I have set the overflow property to visible for the div. My query is, when I add an image to the image tag, the content that overflows through the div should have an opacity of 0.5.

https://example.com/image.jpg

This is how it currently appears... Any assistance?

<div style="border-style: solid; border-width: 2px; height: 5cm; width: 8cm;top: 20px; left: 20px; position:relative; overflow:visible;" id="divimg">
          <img src="https://example.com/image.jpg" id="displayimg" style="height: 7cm; width: 10cm;" />
        </div>

Answer №1

If you want to transform the HTML code into this structure:

<div id="holder">
  <div id="overlay">          
  <img src="https://stepupandlive.files.wordpress.com/2014/09/3d-animated-frog-image.jpg" id="displayimg"  />

    </div>    
    <div id="box"></box>  

</div>

Here is the corresponding CSS:

#holder {
    width:500px;
    height:250px;
    position:relative;
    overflow:hidden;

}

#overlay {
    width:500px;
    height:250px;
    opacity:0.5;

}
#displayimg {

    width:500px;
    height:250px;

}
#box {
    width:250px;
    height:100px;
    background-color:black;
     position:absolute;
    left:200px;
    top:70px;
    overflow:hidden;

}
#box #ima {

    position:absolute;
     width:500px;
    height:250px;
    display:block;
}

And adding some JQuery magic:

$('#box').append('<img src="https://stepupandlive.files.wordpress.com/2014/09/3d-animated-frog-image.jpg" id="ima"  /> ');

$('#ima').offset($('#holder').offset());

$( "#box" ).draggable();

  $( "#box" ).draggable({

      drag: function() {
      $('#ima').offset($('#holder').offset());
      }

    });     

If you're interested in enabling resizing functionality, additional calculations will be needed, but it's definitely achievable...

Answer №2

Check out this demonstration tailored to your specific needs.

.outter_div{width:400px; height: 200px;position: relative;}
.outter_div:after{content:"";border:50px solid rgba(255,255,255,0.5);position: absolute; top: 0;width: 300px;height: 100px;}
img{width: 100%;position:}
 <div class="outter_div">
       <img src="https://stepupandlive.files.wordpress.com/2014/09/3d-animated-frog-image.jpg"/>
</div>

Discover the JSFiddle demo here

Answer №3

After some brainstorming, here is the finalized code snippet:

<div class="wrapper">
    <div class="content">
        <div class="text">This is a sample text</div>
    </div>
</div>

.content {
    background-image:url(http://lorempixel.com/g/200/200/);
    position: relative;
}
.wrapper {
    width:300px;
    height:300px;
}
.text {
    text-align: center;
    padding:15px;
    border: solid 30px rgba(255, 255, 255, 0.5);
    color:white;
}

Check out the JSFiddle demo here

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

Is there a way to automatically mute the sound on a parallax website homepage video when I navigate back to the homepage from another page?

Is there a way to automatically mute the sound of the homepage video on a parallax website when navigating back to it from a separate page? If I click on the enter button and navigate to the "Our DNA" page, then click on the events link in the menu from t ...

Assigning a changing label to a radio button

Looking to create a dynamic form where clicking a button calls a JavaScript function. Here's the code snippet: function addRadioButton(type){ var element = document.createElement("input"); //Set attributes for the element. element.setAttr ...

Guidance on creating a custom color selection tool for a specific task

Looking for assistance in converting a code snippet that uses <button> elements to select colors into a color picker. I am unsure how to retrieve the selected color and use it within a JavaScript function. Can someone provide guidance on this? Here i ...

Run XQuery dynamically in JavaScript and store the outcome in a JavaScript variable

Looking to achieve the following: Running a dynamic XQUERY stored in a JavaScript variable example var myxquery = For Channels.Channel where Channel/availability = yes And Channels.Channel/Label = 'CNN' Return EXIST(Channels.Channel/Id)&apo ...

Python web scraping: Extracting data from HTML tag names

Seeking help with extracting user data from a website by retrieving User IDs directly from tag names. I am utilizing python selenium and beautiful soup to extract the UID specifically from the div tag. For instance: <"div id="UID_**60CE07D6DF5C02A987E ...

The #each helper in Handlebars is used to iterate over an array

I have a function that generates an array as output. I am looking for a way to iterate over this array using the each method. Can anyone provide guidance on how to achieve this? Consider if the handlebars helper produces the following array: details: [{ ...

How can the background of a div be altered when text is typed into an input field?

I need help with the following code. I want to be able to change the background color of a div with the class "target_bg" from red (default) to green every time someone enters or types text into the input field. <div class="target_bg"></div> & ...

Explore interactive hover effects with jQuery and UI for a dynamic user experience!

Is it possible to initiate dragging on mouseover instead of click? Imagine a div that instantly starts dragging when hovered over. How can this be achieved? I would appreciate any guidance on how to make this happen. Thank you ...

RStudio Connect now automatically inserts CSS code into cells when updating

My current project involves creating an app for holiday requests. The main page of the app is displayed like this: At the bottom right corner, you'll notice a column labeled "Accepted?" which displays either "OK" or "DENIED" in different colors. When ...

Utilizing Node and Electron to dynamically adjust CSS style properties

Having a dilemma here: I need to access the CSS properties from styles.css within Electron. Trying to use document.getElementsByClassName() won't work because Node doesn't have document. The goal is to change the color of a specific div when the ...

Activate the div when hovering over the span

Experiencing an issue with triggering a visible div while hovering over a span. Here is the code structure: <ul class="products"> <li> <a href="somelink"> <img src="some image"> <div class="overlay"> Some Text</div> & ...

Utilizing MUI for layering components vertically: A step-by-step guide

I am looking for a way to style a div differently on Desktop and Mobile devices: ------------------------------------------------------------------ | (icon) | (content) |(button here)| ----------------------------------------- ...

Image remains fluid within a static div without resizing

Any assistance would be greatly appreciated. I am currently facing an issue with a fixed div that is floating at the bottom of the screen, serving as ad space for the mobile version of a website. The problem arises when attempting to resize the browser win ...

Ways to generate arrays in Typescript

My dilemma lies in a generator method I've created that asynchronously adds items to an array, and then yields each item using yield* array at the end of the process. However, TypeScript compiler is throwing me off with an error message (TS2766) that ...

Utilizing an unknown provider in AngularJS constants: a guide

Can anyone help me figure out what's going on with this code snippet? var app = angular.module('myApp', []); app.constant('_START_REQUEST_', '_START_REQUEST_'); app.constant('_END_REQUEST_&ap ...

Vibrant array of colors in AmCharts' line graphs

I'm looking to enhance my graph by having lines between the bullets in different colors based on their direction. For instance, if a line is rising (going from a bullet of smaller value to greater value), it should be green; if a line is falling, it s ...

Angulajs: The correct way to simulate a Promise received from $http

Seeking guidance after struggling with unit testing an angular service, specifically the failed part of a promise. (function () { angular.module('testable') .factory('myService', ["$http", "$q", function ($http, $q) { retur ...

What is the best way to identify the position of an element in an array given my specific circumstances

I am trying to utilize the ng-repeat directive in order to display an array. Here is what I have: <div ng-repeat="stu in school"> <div>{{stu.name}}</div> <div>{{stu.grade}}</div> </div> JavaScript $scope.scho ...

Move buttons from one group to another group

I have a task to update a group of buttons with different buttons depending on the initial button chosen. Button1: when clicked, both buttons will be replaced by Button1a and Button1b Button2: when clicked, both buttons will be replaced by Button2a ...

Error: Unable to access property XXX because it is not defined

Upon trying to serve my application, I encountered errors in the console similar to the one below. It seems to be related to angular-animate. How can I resolve this issue in angular? Can someone assist me with fixing it? Uncaught TypeError: Cannot read pr ...