dividing a circle in half with CSS using an image background

Is it possible to divide a circle into 2 parts using both RGB and URL images?
Here is an example of how I want it to look: https://i.sstatic.net/r5sWj.png

I have managed to write code that works with RGB, but I am unsure how to achieve the same effect with a URL image. Can someone please assist me:

.divided-circle {
  width: 25px;
  height: 25px;
  background: linear-gradient( 135deg, #26A0DA 50%, #d92550 50%);
  border-radius: 50%;
  border: 0.5px solid #9b9b9b;
  margin-right: 5px;
}
<div>
  <div class="divided-circle"></div>
</div>

Answer №1

Below is a sample implementation for you to try:

.container {
  width:200px;
  height:200px;
  border-radius:50%;
  background:blue;  /* initial background color */
  position:relative;
  overflow:hidden;
}
.container::before {
  content:"";
  display:block;
  padding-top:100%;
  background:url(https://picsum.photos/id/222/800/800) center/cover; /* second background image */
  /* adjust the angle below to change the rotation */
  -webkit-mask:linear-gradient(45deg,#fff 49.8%,transparent 50%);
          mask:linear-gradient(45deg,#fff 49.8%,transparent 50%);
}
<div class="container"></div>

Use CSS variables to customize easily:

.container {
  --angle:30deg; /* customize the rotation angle */
  /* initial background color */
  --background1:yellow;
  /* second background image */
  --background2:url(https://picsum.photos/id/333/800/800) center/cover;
  
  width:200px;
  height:200px;
  display:inline-block;
  border-radius:50%;
  background:var(--background1); 
  position:relative;
  overflow:hidden;
}
.container::before {
  content:"";
  display:block;
  padding-top:100%;
  background:var(--background2); 
  -webkit-mask:linear-gradient(var(--angle),#fff 49.8%,transparent 50%);
          mask:linear-gradient(var(--angle),#fff 49.8%,transparent 50%);
}
<div class="container"></div>

<div class="container" style="--background1:green;--background2:linear-gradient(red,blue);--angle:90deg;"></div>

<div class="container" style="--background1:url(https://picsum.photos/id/444/800/800?blur) center/cover;--background2:url(https://picsum.photos/id/555/800/800) center/cover;--angle:135deg;"></div>

Answer №2

To achieve this effect, you can utilize the clip-path property. Here is an example:

.shape1 {
  position: absolute;
  clip-path: polygon(0 0, 0% 100%, 100% 0);
}

.shape2 {
  position: absolute;
  clip-path: polygon(100% 100%, 0% 100%, 100% 0);
}
<img class="shape1" src="https://example.com/image1.png"/>
<img class="shape2" src="https://example.com/image2.png"/>

For more information on the clip-path property, visit this link.

Answer №3

To achieve a rounded border, you can use the border-radius property and incorporate images or text inside the div elements...

.circle-section{
  width: 150px;
  height: 150px;
  margin-right: 5px;
  display: flex;
  transform: rotate(45deg);
}

.circle-section .left {
  width: 50%;
  height: 100%;
  border-radius:  100% 0% 0% 100% / 50% 50% 50% 50%;
  background: #cdcdcd;
  border: 0.5px solid #9b9b9b;
  border-right: none;
}

.circle-section .right {
  width: 50%;
  height: 100%;
  background: #212121;
  border-radius: 0% 100% 100% 0% / 50% 50% 50% 50%;
  border: 0.5px solid #9b9b9b;
  border-left: none;
}
<div>
  <div class="circle-section">
    <div class="left"></div>
    <div class="right"></div>
  </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

Struggling with your Dropdown Menu onclick functionality in Javascript? Let me lend

I am seeking assistance with implementing a Javascript onclick Dropdown Menu. The current issue I am facing is that when one menu is opened and another menu is clicked, the previous menu remains open. My desired solution is to have the previously open menu ...

Having Trouble with JQuery Triggering Tabs inside an iFrame

I am curious why this code functions properly on my parent's HTML page: $("#assessmentsTab").trigger("click"); but fails to work within my iFrame: $("#assessmentsTab", window.parent.document).trigger("click"); Does anyone have any suggestions? I ...

Internet Explorer not recognizing attribute selector in jQuery

My JavaScript code utilizes the css selector [style="display:none"], and it functions correctly in Chrome, Firefox, Opera, and Safari on Windows. However, in Internet Explorer 11, it behaves unexpectedly. To test this issue, simply click on the buttons (e ...

Need to update various form fields at once with jquery?

There is a form with fields for firstname, lastname, email, country, along with edit icon and submit/cancel buttons. When the user clicks on the edit icon in the top right corner, all values will be displayed in textboxes and the country will be shown in ...

Focus border radius for anchor tag image

I am trying to implement the following CSS: .sky:focus {border-radius: 25px; border: #000 solid 1px; outline: none} And my HTML looks like this: <a class='sky' href='#'><img src='cloud.jpg'></a> I want a 25 ...

Choosing jQuery over JQuery Mobile for a standard web application to effectively manage different devices

Creating a Unique Web Application In the works is a unique web application, similar to Trello, that divides a page into columns where tasks/cards can be added and moved between them. This desktop-focused platform will feature an information column on the ...

"Positioning a div around a Bootstrap form-inline: A step-by-step guide

When using Bootstrap 3 "form-inline" within a <div>, I noticed that the div seems to be nested within the form-inline. This is how my code looks: HTML <div class="wrapper"> <div class="form-inline"> <div ...

Resize image dimensions to fit within css div class container

How can I make my image completely fit the size of my div class without cutting off any parts? I've tried using background-size: cover, but it only scales the image to fill the div and cuts off part of it. I also attempted to use object-fit: fill, but ...

What could be causing the background color not to change on the HTML page with Bootstrap?

Learning html, bootstrap, and css styling can be a confusing endeavor. Sometimes things don't work as expected, like changing the background color. Despite following what seems like a simple solution after googling, the background color remains unchan ...

Getting the present location on Google Maps for the web: A step-by-step guide

As a newcomer to this API, I have successfully generated an API key but am unsure of how to implement Google Maps. Despite my extensive research, I have been unable to find a solution that works for me. I am seeking assistance in locating users or devices ...

Achieving consistent image column heights that decrease evenly

I am trying to create a grid-like layout where each column in a row has the same height and contains an image while maintaining its proportions. Currently, I am using the flex-grow property to adjust the ratio of the images. Although this works, it often ...

Setting the width of input-group inputs is a feature introduced in Bootstrap 4

Need assistance with a problem involving an input-group in bootstrap 4. Within the input-group, there are two inputs— one with a prepend and the other with an append. The setup is contained within a col-12 div in a form-group, and the goal is to set spe ...

Guide to autoplay an uploaded mp4 video in a flask application

I've been working on a Flask application that includes an upload button for videos in mp4 format. I'm facing an issue where after uploading a video, it only shows a generic grey screen without playing the video. I want to ensure that once a video ...

Creating a fullscreen layout in HTML with specific minimum and maximum widths

Looking to create a layout where one item takes up 1/3 of the screen-width with a minimum width of 500px and a maximum width of 700px, while another item fills the rest of the screen. Ideally, setting a width of 66% should work, but issues arise when the h ...

The jQuery scroll function is not working for the span class I specified. What could be causing this issue?

I attempted to implement a scroll-to plugin to move between elements on a page when clicking previous and next buttons. The source demo works differently from my modified version, and I am struggling to figure out where I went wrong. Source demo: My Curr ...

Android failing to adapt to font size changes set by media queries in HTML code

Recently, I've been facing an unusual issue on a Nexus 7 where changing the font-size on the HTML element seems to be ignored. Removing the smaller font size resolves the problem but creates new issues for phone displays. CSS: html { font-size: 10px ...

Looking for a solution to resolve the issue "ERROR TypeError: Cannot set property 'id' of undefined"?

Whenever I attempt to call getHistoryData() from the HTML, an error message "ERROR TypeError: Cannot set property 'id' of undefined" appears. export class Data { id : string ; fromTime : any ; toTime : any ; deviceType : string ...

The custom radio button is not showing up on iOs Safari

My code for custom radio buttons using CSS is as follows: input[type=radio]{ display:none; } .radio-options label::before { content: "\2b24"; color:#e2e2e2; display: inline-block !important; width: 17px; height: 17px; vert ...

Having trouble implementing styles for an element selected using the document.getElementsByClassName() method

In order to adjust the style of a dropdown menu, I need to change its top value to align it properly. The element is being generated by Drupal (a CMS tool) and is configured with classes for styling purposes in the admin view where content is authored. How ...

Hiding a button based on the visibility of another button in the user's viewport

Is there a way to dynamically hide button B when the user scrolls and button A becomes visible on the screen? Additionally, how can we show button B again once button A is no longer visible to the user? Both buttons should never be visible simultaneously. ...