Creating a custom CSS clip to apply a rounded path on an image

I have been experimenting with applying a "clip path" to an image using a rounded path. While I am aware that SVG clip paths are an option, I found them to be less responsive. As an alternative, I attempted to place the SVG graphic under the image within a div element. However, I encountered difficulties with mobile views as only the left side of the SVG was visible.

https://i.sstatic.net/58Izj.png

Could you assist me in discovering a more effective solution for this issue? I am open to any suggestions, even if they involve a completely different (and potentially superior) approach. I have created a fiddle for experimentation and problem understanding. When you resize the preview window to a mobile view, the issue becomes apparent:

https://jsfiddle.net/Lrtgr858/16/

html,
body {
  background-color: #F7F7F7;
  padding: 0;
  overflow-x: hidden;
}

.svg-image-clip {
  overflow: hidden;
  top: -90px;
  position: relative;
  display: block;
  width: 120%;
  height: auto;
  content: '';
  background-image: url(https://svgshare.com/i/5r3.svg);
  background-size: cover;
  height: 200px;
  left: 60%;
  transform: translateX(-60%);
  -webkit-transform: translateX(-60%);
  -moz-transform: translateX(-60%);
}

.fullsize-image-div {
  width: 100%;
  height: 300px;
  background-image: url(http://fs1.directupload.net/images/180315/vlz5bgwm.jpg);
  background-size: cover;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fullsize-image-div h1 {
  color: white;
  font-size: 3rem;
}
<div class="fullsize-image-div">
  <h1 style="text-align:center">Hello, this is a test.</h1>
</div>
<div class="svg-image-clip"></div>

Answer №1

To achieve the desired effect, you can utilize the clip-path property.

It is unnecessary to include svg-image-clip in your code. Please remove this element.

Include

clip-path: ellipse(75% 100% at 50% 0%);
within the .fullsize-image-div class.

Below is the functional code:

html,
body {
  background-color: #F7F7F7;
  padding: 0;
  overflow-x: hidden;
}


.fullsize-image-div {
  width: 100%;
  height: 300px;
  background-image: url(http://fs1.directupload.net/images/180315/vlz5bgwm.jpg);
  background-size: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  clip-path: ellipse(85% 100% at 50% 0%);
}

.fullsize-image-div h1 {
  color: white;
  font-size: 3rem;
}
<div class="fullsize-image-div">
  <h1 style="text-align:center">Hello, this is a test.</h1>
</div>

Answer №2

If you're looking to achieve a specific look for your element, there are a couple of options available without needing to use an SVG element. Here are two alternatives:

1. One approach is to utilize a pseudo element with the border radius set only on the bottom sides and a white border color. This method should work across various platforms:

Example:

.fullsize-image-div:before {
    content: "";
    position: absolute;
    bottom: -100px;
    left: 50%;
    margin-left: -900px;
    height: 1000px;
    width: 1600px;
    border-radius: 100%;
    border: 100px solid #fff;
}

I made some adjustments in your fiddle to demonstrate this concept. Feel free to customize the sizing as you see fit:

FIDDLE

2. Another option is to implement modern CSS3 clip-path using the ellipse() function:

clip-path: ellipse(100% 98% at 50% 0%);

I also incorporated some relative units (vw) for sizing/font to enhance responsiveness. Keep in mind that this may not be supported in Internet Explorer (clip-path). Again, feel free to adjust according to your needs:

Codepen

p.s. I find Codepen to be quite handy :)

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

unusual behavior observed in addEventListener

I have recently delved into learning about the DOM. I have a project in mind where I want to create a website with buttons that, when clicked, play different drum sounds. As part of my experimentation with JavaScript, I wanted to explore the this keyword. ...

Display a persistent bar on the page until the user reaches a specified <div> element through scrolling

Looking to implement a sticky bar at the bottom of my page that fades out once the user scrolls to a specific div and then fades back in when scrolling up and the div is out of view. This bar should only appear if the user's screen size is not large ...

Is there a way to showcase views.py outcomes promptly and dynamically on template.html within a Django project?

I am working on a django website project with a template called exper.html and views.py handling the backend processing. My goal is to allow users to input parameters or text in a textarea, click submit, and have views.py process the input to generate ima ...

enigmatic margin surrounding navigation dots

I have added a straightforward dot navigation to the banner of my website. You can check it out HERE. The HTML code I used is shown below: <ul class="carousel-dots"> <li> <a href=""></a> </li> <li> ...

How can I preselect an item in a dropdown list in HTML using the result of an SQL query

Is this the correct method for setting a default value in an HTML drop down menu? The variable $vendor_name is determined by retrieving an array of results through a query, which is then looped to generate table rows in HTML. Consequently, the value of $v ...

Is there a way to make the fixed table header scroll along with the table body data?

I am facing an issue with my table where I have multiple columns. I have managed to fix the table header successfully, however, when I scroll horizontally through the table body columns, the header remains fixed and does not move accordingly. How can I res ...

I'm seeking guidance on how to delete a specific ul li element by its id after making an ajax request to delete a corresponding row in MySQL database. I'm unsure about the correct placement for the jQuery

I have created an app that displays a list of income items. Each item is contained within an li element with a unique id, along with the item description and a small trash icon. Currently, I have implemented code that triggers an AJAX call when the user cl ...

Styling the Next and Previous Page Links in your WordPress Website

Currently working on developing my own custom Wordpress theme and everything is going well, except for one little detail. I am trying to customize the styling of my next/previous page links so that the next page-link appears on the right side and the previ ...

Attempting to place words beneath an image can distort the overall layout

Having trouble aligning text under 3 images in a row? All the solutions I've come across end up stacking the images vertically instead of horizontally. HTML: <div id="SecondFooter" class="responsiveColumn"> <a href="link here" t ...

Different approach to handling overflow without using the hidden property in CSS

Having trouble with my CSS layout I've created a form within a fixed 500 pixel width div that is centered on the page using margin auto; To create a table-like structure within the div, I used div elements as rows. Due to varying heights of these ro ...

Incorporate dynamic body color changes across all pages using AngularJS

On the home page, I want to change the color scheme so that it is consistent across all pages. The user should be able to choose a color from a list on the home page and have it apply to every page. Currently, the color selection only applies to the home p ...

Automatically trigger a PHP reload/refresh based on user input

My website has a form that populates a table with data. Currently, after the user submits the data, they have to manually refresh the page in order to see the new data displayed. Is there a way to automatically refresh the table every time the user hits ...

What is the process to create a sticky Material UI grid element?

Currently, I am in the process of developing the front-end for a shopping cart. To organize the content, I have split the container into two columns using Grid container and Grid item. In each column, various components are placed - the left side containin ...

How can we implement a function on every table using jQuery?

I have created a custom jQuery function for implementing pagination. However, I encountered an issue where when I load the function on a page with multiple tables, the pagination system gets applied to all tables. This means that the number of pages refle ...

Discovering the process of extracting a date from the Date Picker component and displaying it in a table using Material-UI in ReactJS

I am using the Date Picker component from Material-UI for React JS to display selected dates in a table. However, I am encountering an error when trying to show the date object in a table row. Can anyone provide guidance on how to achieve this? import ...

What is the best way to use regular expressions to match text with varied endings?

Here is my current situation. <h2>Details</h2>\n +<p>(.*)<br />|</p> ^ there's a tab space, wondering if there's a better way to show one or more (seems to be working) I am attempting to f ...

The PHP code fails to execute properly after being uploaded to the server

I am facing an issue with my PHP code not working when uploaded to the server. It works fine on localhost, but why is it not running properly on the server? <?php ob_start(); include 'CUserDB.php'; session_start(); include 'config.php&a ...

Retrieve a HTML element's tag using jQuery

I have a search bar with two tabs to choose from for the type of search. I am looking to assign the .active class to the list item whose search_type matches a parameter from a request (e.g., params[request_type]). <ul data-tabs="tabs" class="tabs"> ...

Modify the contents of a textbox by editing the text as you type

Text within the text box follows this format: login -u username -p password When entering this text, I want to substitute 'password' with a series of '*'s equal in length. For example: 'login -u <a href="/cdn-cgi/l/email-prot ...

Extract all information from the HTML table and store it in an array

I'm currently able to store all generic text data in an array, but I'm facing difficulties with the select boxes inside table cells. In my jQuery script, I have the following: $('.image-button').click(function(){ var myTableArr ...