What is the process for designing a button with a circular element connected to its left edge?

I am currently working on creating a unique button design using a combination of HTML and CSS. The button is rectangular on three sides, with a circular section attached to the right side where the buttons border seamlessly wraps around it.

Below is an image showcasing the button design I aim to achieve:

View Button Design

Here is the code that I have developed so far:

#GetOTPBlock {
   display: flex;
   width: fit-content; 
   padding: 8px
}
.get-otp {
   font-size: 10px;
    padding: 4px;
    border: solid 2px #849dad;
    border-radius: 50%;
    font-weight: bold;
    color: #747f86;
    background-color: #f1f1f1;
    z-index: 333;
}
<div class="row" id="GetOTPBlock">
  <span class="get-otp">OR</span>
  <div id="GetOTPBlockAction">
    <a href="javascript:void(0);" title="Get OTP">Get OTP</a>
  </div>
</div>

Answer №1

One way to achieve this is by wrapping the get-otp element around the GetOTPBlock in your HTML structure. You have the flexibility to customize it according to your requirements.

#GetOTPBlock{
  position:relative;
  margin:1rem;
}

#GetOTPBlock .get-otp{
  position:absolute;
  width:2rem;
  height:2rem;
  top:50%;
  transform:translateY(-50%);
  left:-1rem;
  background-color: white;
  color: #849dad;
  display:grid;
  place-items:center;
  border: 2px solid #849dad;
  border-radius:50%;
  pointer-events:none;
}

#GetOTPBlock a{
  color:white;
  text-decoration:none;
  padding:1rem 2rem;
  display:inline-block;
  background-color:#849dad;
  border-radius:5px;
}
<div class="row" id="GetOTPBlock">
  <span class="get-otp">OR</span>
  <div id="GetOTPBlockAction">
    <a href="javascript:void(0);" title="Get OTP">Get OTP</a>
  </div>
</div>

If you can modify your HTML structure, a simpler approach would be using a pseudo-element:

#GetOTPBlockAction{
  position:relative;
  color: white;
  text-decoration: none;
  padding: 1rem 2rem;
  display: inline-block;
  background-color: #849dad;
  border-radius: 5px;
  margin:1rem;
}

#GetOTPBlockAction::before {
  content:"Or";
  position: absolute;
  width: 2rem;
  height: 2rem;
  top: 50%;
  transform: translateY(-50%);
  left: -1rem;
  background-color: white;
  color: #849dad;
  display: grid;
  place-items: center;
  border: 2px solid #849dad;
  border-radius: 50%;
  pointer-events: none;

}
<a id="GetOTPBlockAction" href="javascript:void(0);" title="Get OTP">Get OTP</a>

Answer №2

To create a circular design, you can utilize the CSS property position: absolute on the circle element and simultaneously use position: relative on the button element to position the circle in relation to the button. By adjusting the values of top: 0 or left: 0, you can control the placement of the circle based on the dimensions of your button.

An alternative approach is to apply a box-shadow effect to produce a secondary circle underneath the original one, giving the impression of a bordered appearance.

.main-btn {
  all: unset; /* Remove default styles */
  border-radius: 20px;
  width: 100px;
  height: 40px;
  background-color: red;
  text-align: center;
  vertical-align: middle;
  position: relative; /* Establishes positioning context for the circle */
}

.circle {
  background-color: black;
  position: absolute;
  border-radius: 50%;
  color: white;
  width: 20px;
  height: 20px;
  top: 10px; /* Half of the circle's height */
  left: -5px;
  box-shadow: 0px 0px 0 1.5px red; /* Creates a duplicated circle with red shadow */
}
<button class="main-btn">
<div class="circle"></div>
</button>

Answer №3

Utilizing the ::before pseudo-element in your CSS can be done as follows:

.otp_button {
    padding: 10px 20px;
    background-color: rgb(71, 73, 111);
    color: #fff;
    border-style: none;
    border-radius: 5px;
    position: relative;

}
.otp_button::before {
    position: absolute;
    content: "or";
    text-transform: uppercase;
    left: -10px;
    background-color: rgb(177, 177, 177);
    font-size: 10px;
    border-radius: 100%;
    padding: 3px;
    border: 1px solid #000;
}
<button class="otp_button">Get OTP</button>

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 specifically modify the color of the last digits in a number?

Seeking guidance on changing the color of the last digits of a number if it ends in a zero or more. For instance, transform 0.50 to 0.50, 10.00 to 10.00, 10,000.00 to 10,000.00, 100,050.00 to 100,050.00, and the like. Any assistance in achieving this would ...

Using JQuery, you can predominantly focus on an html element by referencing its title tag

Is it possible to target an HTML element based on its title tag? Consider the following example: <a class="cat" title="categoryName">categoryName</a> How can we select this anchor element by its title tag and then add some text to it? I att ...

What is the best way to extract the innerHTML of every button and exhibit it in a text box?

How can I create a simpler JavaScript code for clicking buttons to input letters into a text box? Instead of creating getElementByID for each button, is it possible to use some kind of loop? <div id="alpha" > <br/> <div align="cente ...

Sticky sidebar panel featuring a stationary content block

I have a sidebar that is set to position:fixed; and overflow:auto;, causing the scrolling to occur within the fixed element. When the sidebar is activated, the element remains static on the page without any movement. My goal: I am looking to keep the .su ...

When hovering on the list items, the text-decoration with a border-bottom and vertically centered unordered list "jumps"

I'm specifically looking for a solution using CSS only. I have a navigation bar with an unordered list containing list items. My question is how to underline these list items with a border-bottom. The additional requirement is that the navigation bar ...

Guide on creating a square within an element using JavaScript

After conducting thorough research, I find myself unsure of the best course of action. My situation involves a Kendo Grid (table) with 3 rows and 3 columns. Initially, the table displays only the first column, populated upon the page's initial load. S ...

Two collapsible menus featured in the navigation bar

My navbar is displaying two collapse menus, but when one is active and I open the second one, the collapsed content from the second menu gets added to the end of the first one's content. How can I close the other menu when opening the second one? h ...

Vuetify Container with a set maximum width that remains fixed

I recently started developing a web application using Vue.js and Vuetify (https://vuetifyjs.com/en/). Currently, I have a basic layout with 3 columns. However, I noticed that the width of these columns is restricted to a maximum of 960px due to some defau ...

jQuery's promise method in CSS is executed successfully

Seeking advice from someone: Scenario: Currently, I have <div id="breadCrumb" style="width:80%"></div> Now, I want to update the width to 100% and retrieve the width in pixels on click $('#menu_toggle').on('click', funct ...

Looking to extract a Twitter handle using Python's BeautifulSoup module?

I'm struggling to extract the Twitter profile name from a given profile URL using Beautiful Soup in Python. No matter what HTML tags I try, I can't seem to retrieve the name. What specific HTML tags should I be using to successfully grab the prof ...

Is there a way to adjust the background color of the clicked tab with divs and revert the others back to their original color?

<span class="row top-bar-left align-items-center" style="width: 80%; float:left"> <div tabindex="1" class="link tab" routerLink="details" routerLinkActive="active" [qu ...

What could be causing my Bootstrap navbar menu item to move to the line beneath it when there is centered text?

I've implemented a basic Bootstrap navbar from the example provided on the Bootstrap website at . However, when I tried to add custom text to the center of the navbar, it caused the "Contact Us" menu item to break onto two lines instead of staying on ...

How can I access a component variable within the styles in Angular?

Is it possible to utilize a variable width in my Angular 5 component template? I would like to achieve something similar to this: <style> input:checked + .slider:before { transform: translateX({{width}}px); } </style> The &apo ...

Struggling to access a JSON file using Angular framework

I'm currently working with the following JSON and controllers: JSON Format: {"tomcatLogDir":"C:\\apache-tomcat-7.0.70\\logs","tomcatLogs":["1.log","2.log","3.log"]} Factory: app.factory('filesFactory', [ '$http&a ...

What is the best way to stop a jQuery function from applying titles extracted from the first row th's in thead's to multiple tables in a document?

My circumstances: I am new to jQuery and Stack Overflow, seeking assistance for my website project. The challenge: Building a website using Bootstrap 3.3.6 with intricate data tables that need to be stacked dynamically on mobile devices using CSS. It is c ...

Is receiving an error message about a "stray start tag footer" in your HTML validator?

I am perplexed by the error message I am receiving: Stray start tag footer. All I have included here is the tags: <!doctype html> <head> <title>title</title> <meta charset="UTF-8"> <meta name="keywords" cont ...

Incorporating JSTree Into Your Website's Heading: A Step-By-Step

I'm in search of a way to integrate the following code snippet as a JSTree into the heading section of a webpage, depicted below: <div id="jstree"> <ul> <li>Core 1 <ul> & ...

Dynamic reloading of a div with form data using jQuery's AJAX functionality

I am currently developing an online visitor chat software using PHP and MySQL. My goal is to load the page when the submit button is clicked. Submit Button ID: send Visitor ID: vid Chat ID: cid Below is the snippet of code for an Ajax request that I hav ...

Struggling with the navbar-toggler in Bootstrap 4 Beta 2?

As part of my Bootstrap practice, I have implemented a navbar on my webpage. However, I am facing issues with the nav-bar toggler not working for small screens and the icon navbar-toggler-icon not appearing. Below is my current navbar code: <nav class ...

Checking the size of an HTML numerical input field?

When creating a form that accepts numbers, there may be a specific element, such as a phone number input named phNo, that needs to be exactly 7 digits long. To achieve this validation using JavaScript, the approach is: If the length of the element is not ...