CSS 3 Shape: "Reverse Circle" or "Hollow Circle"

Trying to create an inverse circle or cut-out circle in CSS has been a challenging task for me. I stumbled upon this insightful answer provided by ScottS.

While Scott's code worked like a charm, I am now aiming to achieve a similar effect on the opposite side of the <div> element. Instead of having a cut-out on the left, my goal is to have it on the right.

Below is the existing code:

body {
  padding: 10px;
  background: url(http://www.dummyimage.com/12x16/ff0000/ffffff.png&text=X++) top left repeat;
}

.inversePair {
  border: 1px solid black;
  display: inline-block;
  position: relative;
  height: 100px;
  text-align: center;
  line-height: 100px;
  vertical-align: middle;
}

#a {
  width: 100px;
  border-radius: 50px;
  background: grey;
  z-index: 1;
}

#b {
  width: 200px;
  /* need to play with margin/padding adjustment
       based on your desired "gap" */
  padding-left: 30px;
  margin-left: -30px;
  /* real borders */
  border-left: none;
  -webkit-border-top-right-radius: 20px;
  -webkit-border-bottom-right-radius: 20px;
  -moz-border-radius-topright: 20px;
  -moz-border-radius-bottomright: 20px;
  border-top-right-radius: 20px;
  border-bottom-right-radius: 20px;
  /* the inverse circle "cut" */
  background-image: -moz-radial-gradient( -23px 50%, /* the -23px left position varies by your "gap" */
  circle closest-corner, /* keep radius to half height */
  transparent 0, /* transparent at center */
  transparent 55px, /*transparent at edge of gap */
  black 56px, /* start circle "border" */
  grey 57px/* end circle border and begin color of rest of background */
  );
  background-image: -webkit-radial-gradient(-23px 50%, circle closest-corner, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 55px, black 56px, grey 57px);
  background-image: -ms-radial-gradient(-23px 50%, circle closest-corner, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 55px, black 56px, grey 57px);
  background-image: -o-radial-gradient(-23px 50%, circle closest-corner, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 55px, black 56px, grey 57px);
  background-image: radial-gradient(-23px 50%, circle closest-corner, rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 55px, black 56px, grey 57px);
}
<div id="a" class="inversePair">A</div>
<div id="b" class="inversePair">B</div>

I'm on a quest to mirror this effect. How should I proceed?

Answer №1

Here is a unique solution for your alignment needs:

body {
  padding: 10px;
  background: url(http://www.dummyimage.com/12x16/ff0000/ffffff.png&text=X++) top left repeat;
}
.inversePair {
  border: 1px solid black;
  display: inline-block;
  position: relative;
  height: 100px;
  text-align: center;
}

#a {
  width: 100px;
  border-radius: 50px;
  background: grey;
}
#b {
  width: 200px;
  border-right: none;
}
<div id="b" class="inversePair">B</div>
<div id="a" class="inversePair">A</div>


If you're looking for a more optimized version of the original answer, check out this JSFiddle link:

body {
  padding: 10px;
}

#a, #b {
  border: 1px solid black;
  display: inline-block;
  height: 100px;
  line-height: 100px;
}

#a {
  background: grey;
  border-radius: 50%;
  width: 100px;
}
#b { 
  width: 200px;
  margin: 0 -20px 0 0;
  padding: 0 40px 0 0;
  border-radius: 20px 0 0 20px;
  border-width: 1px 0 1px 1px;
}
<div id="b">B</div>
<div id="a">A</div>


For another simple alignment option, try this JSFiddle demo:

body {
  padding: 10px;
}

#a, #b {
  border: 1px solid black;
  display: inline-block;
  height: 100px;
  line-height: 100px;
}

.item-align-left, .item-align-right {
  display: flex;
  margin-bottom: 10px;
}
.item-align-left #a, .item-align-right #b { 
  order: 1;
}
.item-align-right #a, .item-align-left #b {
  order: 2;
}

#a {
  background: grey;
  border-radius: 50%;
  width: 100px;
}
#b {
  width: 200px;
}
.item-align-right #b {
  margin: 0 -20px 0 0;
  padding: 0 40px 0 0;
  border-radius: 20px 0 0 20px;
  border-width: 1px 0 1px 1px;
}
.item-align-left #b {
  margin: 0 0 0 -20px;
  padding: 0 0 0 40px;
  border-radius: 0 20px 20px 0;
  border-width: 1px 1px 1px 0;
}
<div class="item-align-right">
  <div id="a">A</div>
  <div id="b">B</div>
</div>
<div class="item-align-left">
  <div id="a">A</div>
  <div id="b">B</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

The CSS styling for a pie chart does not seem to be functioning properly when using jQuery's

https://i.stack.imgur.com/kEAKC.png https://i.stack.imgur.com/03tHg.png After examining the two images above, it appears that the CSS is not functioning properly when I try to append the same HTML code using JavaScript. Below is the snippet of my HTML co ...

What are the steps to recreate the layout of my image using HTML?

What's the best way to create a layout in HTML that expands to fit the entire screen? ...

Utilizing Stylus: Embracing Interpolation within a Mixin

I am encountering an issue while attempting to interpolate values passed into a mixin. positionModifier( key, x, y) &.{key} background-position: {x}px {y}px; An error is being thrown, which is shown below: 351| positionModifie ...

What steps can I take to create a textbox that expands as more text is

Looking to create a unique textbook design that starts out with specific width and height dimensions, but expands downward as users type beyond the initial space. Wondering if CSS can help achieve this functionality? In a standard textbox, only a scroll ba ...

Stop child elements from spilling out of the parent container without using fixed height measurements

I am in the process of creating an angular component with a header, buttons, a table, more buttons, and a footer. However, I am facing some challenges with the layout. <my-component> <div>Header Section</div> <some-stuff class=&quo ...

Troubleshooting Problem with CSS Display in Spring Security 3.2

After deciding to integrate 'Spring security 3.2.0' into my current web application, which was originally developed without Spring and utilizes Primefaces & EJB 3, I encountered a challenge. Upon starting the basic configurations, I noticed that ...

Issues with Animations in Animate.css

Seeking to achieve fluid transitions using Vue.js and Animate.css, encountering issues with certain animations not functioning as expected! Successfully implementing animations such as: bounceIn, bounceOut, and hinge. Experimenting with this on codepen.i ...

Using PHP to create multiple div elements and then concealing them all

I'm having an issue with the hide feature not working. My intention is to hide each dynamically generated div and gain control over them, but the problem seems to lie in the div id incrementing. Any assistance would be greatly appreciated! <?php $ ...

Issue with automatic compiling in Sublime 2 for less2css

Whenever I try to save my style.less file, the automatic compilation doesn't happen. Is there a mistake in how I've set it up? Here's what is currently in my ox.sublime-project file: { "folders": [ { ...

"My attempts to link various buttons in separate Bootstrap modals to their specific content are not yielding successful results

Greetings fellow members of Stack! Please bear with me as I am a newcomer here. I am currently working on a Business website for a friend using Bootstrap3. On our team page, we have multiple members and I would like to display additional details for each ...

I am in need of assistance with my request for two rows of three images to be solved

Hi everyone, I'm new to learning CSS and I need some help with rearranging this code. I want to display 2 rows of 3 images below the "Section" class, but my attempts using float and position aren't working. Can someone guide me on where I might b ...

What causes the disparity in functionality between simple html and css in an Angular 2 project compared to a vanilla html website?

When incorporating the following html/css into a new Angular project created with Angular CLI using 'ng new ProjectName', I encountered issues. Despite adding the CSS to app.component.css or styles.css and the HTML to app.component.html, the Angu ...

Safari not centering element with justify-self in CSS grid

My challenge involves adjusting the alignment of a div (mobile menu) that is currently centered using css grid and the justify-self property in chrome. However, when viewed in Safari, it appears on the left side of the screen behind the Instagram icon: ht ...

Is it possible to still alter options in a read-only Select component in Twitter Bootstrap

Even though I have set my bootstrap select to readonly="true", I am still able to change the selected option. I tried using disabled="true", but then the select is not included when submitted. Is there a way to achieve a combination where the selected op ...

Verify whether the content within the Div has been modified

I am currently making changes to content within a <div> element. I would like to determine if the data in the <div> has been modified and, if so, save it in a session to persist on refresh. How can I verify if the data has been edited and then ...

Having trouble getting the carousel slider to function properly on meteor?

I am currently working on my portfolio page using Meteor, and I want to include a carousel slider gallery. The problem I'm facing is that while the first gallery works fine, the second one does not load correctly and just displays a list of pictures. ...

Is there a way to potentially utilize window.open() to open a specific section of a webpage?

My HTML page consists of 2 div blocks and 2 links. I want to open the content of the first div in a new window when the first link is clicked, and the content of the second div in another new window when the second link is clicked. You can find the code h ...

Tips for customizing the selection tip of a custom cursor using CSS

I have integrated a color picker jquery plugin on my website to allow users to pick colors from an image. I made a modification in the CSS to change the cursor to an eyedropper icon. However, currently when clicking on the image, the color pointed by the u ...

Icons on Google Calendar events - Mini images beside your schedule

I'm in the process of developing a website where I plan to integrate Google Calendar. I want to include a small icon next to specific events to denote certain details. While the "categories" feature in Google Calendar allows me to assign highlight col ...

Ways to eliminate the dotted line from the image map in Internet Explorer 11

Below you will find the code I am working with: <img alt="Testing 2015" border="0" src="images/Test-2015.jpg" usemap="#Map" /> <p><map name="Map"><area coords="790,100,653,135" href="http://www.google.com/" shape="rect" style="cursor ...