css overlaying transparent shape on top of image

I am striving to achieve this visual effect

This is my current code:

    #image1 {
    position: absolute;
    bottom: 0px;
    align-self: auto;
    background-color: #dc022e;
    width: 340px;
    height: 100px;
    border-radius: 50% / 100%;
    border-bottom-left-radius: 0;
    /*transform: rotate(10deg);*/
    border-bottom-right-radius: 0;
    opacity: 0.8;
    }
    
    #image2 img {
    width: 80%;
    }
<div>
  <div id="image2">
    <img src="http://t1.gstatic.com/images?q=tbn:ANd9GcThtVuIQ7CBYssbdwtzZjVLI_uw09SeLmyrxaRQEngnQAked5ZB">
  </div>
  <div id="image1"></div>
</div>

I am unsure of how to implement the desired rotation and margin trimming shown in the reference image

Answer №1

An easy illustration of this concept involves a pseudo element with the image set as the background.

div {
  position: relative;
  height: 300px;
  width: 500px;
  background: url(http://lorempixel.com/500/300);/*path to image*/
  overflow: hidden;/*conceals the rest of the circle*/
}

div:before {
  content: "";
  position: absolute; /*positioned in relation to div*/
  top: 100%;
  left: 50%;
  width: 0;/*specify value if no hover effect desired*/
  height: 0;
  border-radius: 50%;
  background: tomato;/*can be rgba value (opacity can be removed)*/
  opacity: 0.5;
  transform: translate(-50%, -50%);/*centers it on the image*/
  transition: all 0.4s;
}


/*Demo Only*/
div:hover:before {/*add this to your pseudo declaration to remove hover effect*/
  height: 100%;
  width: 150%;/*makes shape wider than square*/
  transform: translate(-50%, -50%) rotate(5deg);/*center and rotate the shape*/
}
div {/*Additional styling for text*/
  font-size: 40px;
  line-height: 300px;
  text-align: center;
}
<div>HOVER ME</div>

Answer №2

Instead of using nested elements, consider utilizing a pseudo element placed at the bottom of the container div. To achieve this effect, ensure the container div has position:relative and overflow:hidden properties set. Remember that pseudo elements require the content declaration.

To adjust the border radius, experiment with adjusting the left | width | height values of the pseudo element without the need for rotation.

Instead of specifying a hex color and opacity, you can opt for the "new" color space by using the rgba(r,g,b,a) format where a represents the opacity value.

For creating a passepartout effect, utilize the border declaration.

#image2{
    position:relative;
    border:10px solid #888;
    overflow:hidden;
    box-shadow:0 0 4px #aaa;
}

#image2::after {
    content:"";
    display:block;
    position: absolute;
    bottom: 0;left:-10%;
    background-color: #dc022e;
    width: 120%;
    height: 60%;
    border-radius: 100% 100% 0 0;
    opacity: 0.8;
}
    
#image2 img {
    width: 100%;
    display:block;
    position:relative;
}
<div id="image2">
    <img src="http://t1.gstatic.com/images?q=tbn:ANd9GcThtVuIQ7CBYssbdwtzZjVLI_uw09SeLmyrxaRQEngnQAked5ZB">
  </div>

Answer №3

To achieve the desired effect, consider using position: absolute for your image and position: relative for your overlay. Adjust the top position and width as needed. Check out this helpful Fiddle for reference.

Edit: An updated version of the Fiddle showcases border and overflow properties on the img container. Keep in mind that rotating a circle may not be the most efficient solution. Consider utilizing a pseudo element instead of nesting images for a cleaner approach.

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

Layer several divs inside a main div

I'm grappling with a simple issue and could use some help to resolve it. Utilizing bootstrap, below is my CSS and div structure. How can I achieve an overlap of DIV 1, DIV 2, and DIV 3? Essentially, I want to position them on the same level, one behi ...

What is the method to choose an invisible link without an identifier using Selenium WebDriver?

I am attempting to click on the link labeled 'User Requested'. This link only appears when hovering over the menu. This is the HTML code: <ul class="k-widget k-reset k-header k-menu k-menu-horizontal" id="menu" data-role="menu" tabindex="0" ...

Trigger an alert when a button is clicked and redirect the user to an newly opened tab

I recently created a button with a link that opens in a new tab. I also implemented some JavaScript to display an alert. Everything is working as expected, but after the user clicks "OK" on the alert, they remain on the same page. I would like to automati ...

Guide on how to dynamically generate a dropdown menu based on the selection made in another dropdown

Could anyone provide me with a demonstration on how to dynamically create a dropdown menu based on the onchange event of another dropdown? I currently have a dropdown menu where users can select multiple options, as shown below: <select id='fir ...

jQuery selector unable to locate the specified class in the table row

After receiving an array of strings as a response from an SQL query, I am using JavaScript to dynamically add this data as rows to an HTML table: loadUsers: function() { . . . function displayUsersOnTable(response) { for(var i = ...

Tips for implementing a scrolling renderer in ThreeJS?

I'm currently utilizing the OrtographicCamera. Within the HTML, a canvas is declared and then passed to the renderer like this: var canvas = document.getElementById("canvas") var width = canvas.clientWidth; var height = canvas.clientHeight; render ...

Adding information to a single class that shares a common name

Currently, I have successfully implemented a row cloning scenario where multiple dynamic rows are created after confirming an inventory number from a MySQL database. However, I am facing an issue with inserting the inventory data only to the next DIV eleme ...

Limit the 'contenteditable' attribute in table data to accept only integers

I have a question regarding editing table data row. Is there a way to restrict it to only integers? Thank you for your assistance! <td contenteditable="true" class="product_rate"></td> ...

Tips for creating multiple full-screen overlays in HTML

I am new to the world of web development and I am currently working on implementing a set of buttons that will trigger specific overlays when clicked. I found the following code snippet on W3schools which creates a button along with an overlay effect. < ...

Change the marquee scrolling back to its original starting point

I am trying to implement a continuous image scroll (marquee) in HTML. My goal is to have the marquee stop scrolling when the mouse hovers over it, with the images returning to their initial position. Once the mouse moves away, I want the marquee to resume ...

Scroll the div back to the top when the form is submitted

I have set up a form in a pop-up using Bootstrap modal. The form is quite long, so after submission, the message appears at the top of the form. However, I want it to scroll to the top when the user submits the form so they can easily see the message. Is ...

Having trouble designing a button in my ASP.net Class

After creating a new instance, I would like to add an asp button. However, I am facing challenges with assigning a name and id to the button. For example: <asp:Button ID="Button1" runat="server" Text="Button" />. Every time I try to add quotation mar ...

Are there any React-UI libraries that come with a stylish green color scheme?

Currently working on a small React site and deciding on a UI library. While I do like Material UI and Bootstrap, I find that they have limited default themes available. I am looking for libraries with green-color-based themes or ones that make it easy to ...

Tips for centering Navigation image as screen size decreases

I'm currently in the process of creating a navigation bar, and here's what I have so far: <!-- #region Navigation --> <div class="container "> <nav class="navbar navbar-fixed-top bg-white box-shadow " style= ...

What is the best way to add the current date to a database?

code: <?php session_start(); if(isset($_POST['enq'])) { extract($_POST); $query = mysqli_query($link, "SELECT * FROM enquires2 WHERE email = '".$email. "'"); if(mysqli_num_rows($query) > 0) { echo '<script&g ...

Arrange components within the form

Just started experimenting with this a few days ago. In my form, there is a text field and a button that I want to align side by side at the center of the form. .row { width: 100%; margin-bottom: 20px; display: flex; flex-wrap: wrap; } .col-6 { ...

Adjusting the transparency of numerous elements using JavaScript or jQuery

My task involves creating a large form where elements initially have an opacity of 0.5, and when a button is clicked, the opacity changes to 1.0. While I can achieve this using JavaScript, I want to find a more efficient way by avoiding individual if state ...

Validate the presence of an element on a page using selenium

I attempted to use the following code: if driver.find_element_by_xpath("/html/body/div[2]/div[3]/div[1]/div[1]/button"): pass believing it would be successful, however it did not work and instead resulted in: selenium.common. ...

The issue with CSS3 flex-wrap not functioning properly on Safari and Chrome in IOS 10.1.1

My goal is to create a dynamic grid layout using flex wrap and min-width: 50%, where each cell should occupy the entire width. However, I'm encountering an issue in iOS 10.1.1 (iPhone 5c) Safari and Chrome where the display is not grid-like but rather ...

The 100% CSS styling in Android WebView 4.4 is failing to display any content

When utilizing an Android webview to load a basic HTML page, I encountered an issue where the content div with 100% width and height was not visible on a Galaxy Nexus 4.4.2 device. This problem did not occur when viewed in a browser. Below are the setting ...