Using CSS to Position a Circle at the Top of a Border

Breaking down the complex issue into a simple statement, I am dealing with a blue circle inside a box with a red border.

How can I ensure that the circle remains centered while overlapping the top horizontal line of the box's border?

I tried different approaches to achieve the desired outcome: https://jsfiddle.net/pgcft3z7/1/

HTML:

<div class="container">
  <div class="circle">
    Circle Text Here
  </div>
</div>

CSS:

.circle {
  display: flex;
  align-items: center;
  text-align: center;
  justify-content: center;
  color: white;
  border-radius: 50%;
  width: 130px;
  height: 130px;
  margin: 0 auto;
  background: blue;
  position:absolute;
  top: -5px;
  left: 200px;
}

.container {
  margin-top: 40px;
  border: solid 1px;
  border-color: red;
}

This solution requires manually setting the left and top values, which may affect the responsiveness and alignment over time.

Here is an example of the current appearance: https://jsfiddle.net/pgcft3z7/

Answer №1

Take a look at this JSFiddle link.

.circle {
  display: flex;
  align-items: center;
  text-align: center;
  justify-content: center;
  color: white;
  border-radius: 50%;
  width: 130px;
  height: 130px;
  margin: 0 auto;
  background: blue;
  position: relative;
}
.border {
  border: solid 1px;
  border-color: red;
  width: 100%;
  height: 70px;
  top: 30px;
  position: absolute;
}
.container {
  margin-top: 40px;
  position: relative;
}
<div class="container">
  <div class="border">

  </div>
  <div class="circle">
    Circle Text Goes Here
  </div>
</div>

Answer №2

.style{
  position:relative;        /* in order to contain inner absolute circle pos */
  margin-top:50px;
  background:red;
  height:0;
  border:1px solid red;
}
.shape{
  position: absolute;
  width:40px; height:40px;
  top:50%;    left:50%;                /* 50% of parent */
  transform: translate(-50%, -50%);    /* -50% of self */
  
  background:blue;
  border-radius:50%;
}
<div class="style">
  <div class="shape"></div>
</div>

Answer №3

To upgrade your circle category, simply integrate the following:

  positioning: relative;
  shift upwards by -20px;

Answer №4

Take a look at this amazing design here

.circle {
  display: flex;
  align-items: center;
  text-align: center;
  justify-content: center;
  color: white;
  border-radius: 50%;
  width: 130px;
  height: 130px;
  margin: 0 auto;
  background: blue;
  position:relative;
  top: -65px;
  left: 0;
}

.container {
  margin-top: 100px;
  border: solid 1px;
  border-color: red;
}
<div class="container">
  <div class="circle">
    Content Inside Circle Goes Here
  </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

Cocos2D-JS is unable to import a json file that has been exported from CocosStudio

Trying to import a json file that was exported from cocosstudio v2.3.2 var myScene = ccs.sceneReader.createNodeWithSceneFile('res/Scene.json'); Found this code in the sample-cocos2d-js-scene-gui-master repository. Encountering an error: Can& ...

Tips for Implementing CdvPurchase.Store in Angular

Is there a way to configure cordova-plugin-purchase v13 in conjunction with Angular 15? Here is a snippet of what I have attempted. Below is my PaymentService class that is set to be provided at the root level. // payment.service.ts import { Injectable } ...

The libmagic library detects the MIME type of files as text/plain rather than text/javascript or

In my web project's interface, I am using libmagic to retrieve the MIME type of a file. Interestingly, I am encountering issues where css and js files are being identified as text/plain MIME type. When using Chromium, the following warnings are displ ...

Issues arise when trying to access JSON data that has been added to an array using the JavaScript .push method

I am encountering an issue where I cannot retrieve values from an array after storing it in a variable outside of the getJSON function. The response in JSON format looks like this: [ { "Book_ID": "1", "Book_Name": "Computer Architectu ...

Creating a full-width tab card with Bootstrap-Vue: A step-by-step guide

I stumbled upon something similar in the documentation for bootstrap-vue: A card with tabs: https://i.sstatic.net/HoVEC.png Now, how can I style the tabs to look like this: https://i.sstatic.net/dbsRj.png This is my current code: <b-card no-body ...

Creating a CSS dropdown menu with absolute positioning and setting the left position to auto

Just laying out my usual HTML menu structure: <div id="page"> <h1>Home</h1> <ul id="nav"> <li><a href="http://example.com/">Home</a> <ul> <li><a href="http://examp ...

Is your Bootstrap input displaying the has-error class with a glyphicon, but the alignment is not vertically centered?

What is the reason for the misalignment of glyphicon-warning-sign form-control-feedback vertically in the code below after applying font-size: 20px; to the label? <div class="container"> <div class="content align-left contact"> ...

Animating the variable's width with jQuery

Having difficulty achieving smooth animation on a variable set div width. It should animate similarly to a progress bar. A demo can be found here. Any suggestions on how to improve the animation for smoother transitions? Thanks in advance! Here is the HTM ...

Sending data to a Bootstrap modal dialog box in an Angular application

Using span and ng-repeat, I have created tags that trigger a modal pop-up when the remove button is clicked. Within this modal, there is a delete button that calls a function. I am trying to figure out how to pass the id of the remove button to the modal ...

MongoDB suggests

I'm currently developing an app that requires autocomplete functionality for search. I've started implementing it using regular expressions (regexp), but I'm unsure if this is the optimal approach. Each new character input in the search bar ...

The error notification is not appearing in the correct location

I've been troubleshooting my jQuery error function for hours now (including the success function). I'm struggling to figure out how to display an error message only below the button that I click. To help clarify my issue, I've created a JSFi ...

Running the NPM build command results in an error specifically related to an HTML file

I encountered an issue in my AngularJS application when running the command: npm run build -- -prod The error message I received was: ERROR in ng:///home/directoryling/appname-play.component.html (173,41): The left-hand side of an arithmetic operation ...

Expand the element's functionality to encompass the overscroll area on OS X

I have a webpage with a fixed background and a floating footer at the bottom. When users on OS X overscroll, they can see the background below the footer. Rather than disabling overscrolling for my page, I want to extend the bottom div to cover the backgro ...

What is the best way to store JSON encoded items in an array using square brackets?

Currently, I am utilizing Javascript along with NodeJS to dynamically generate an array of JSON objects. My goal is to store this array of JSON objects in a .json file for future reference. However, when I attempt to save the file, I encounter an issue whe ...

Modify the heading color of elements in a class to a distinct color when the cursor hovers over the element

I currently have 3 heading elements: elem1, elem2, and elem3. When I hover over elem1, I want elem1 to turn yellow and elem2 and elem3 to turn purple. If I hover over elem2, I want elem2 to be yellow and the others to be purple. Once I release the hover, I ...

Angular- Product Details

I'm currently expanding my knowledge of angular (utilizing the ionic framework with phone gap included) and I'm working on developing a single application that displays a list of data. When a user clicks on an item in the list, I want to show the ...

What is causing the UI to change every time I add a tag to refresh the web view?

Recently, I added a pull-to-refresh feature to my React Native webview app using the react-native-pull-to-refresh library. After implementing the tag, I noticed that the UI got rearranged with the webview shifted down and the top half occupied by the pull- ...

Is this example showcasing the use of JavaScript closures?

I have a JavaScript query that may be geared towards beginners: var countries = [ "Bangladesh", "Germany", "Pakistan"]; function checkExistence(arr, input) { for (var i = 0; i < arr.length; i++) { if (arr[i] != input) { a ...

Vue 3: `defineProps` allows components to locally reference declared variables

Why am I receiving a warning error message: defineProps is referencing locally declared variables. eslint(vue/valid-define-props) whenever I utilize a custom validator in props within an SFC <script setup> mode: <script setup> import { valid ...

Troubleshooting Scroll Problems with Angular 5 and PDF.JS

I am working with Angular 5 and PDF.JS. Successfully downloaded a PDF and rendered it. Now, I need to display the PDF in a window by placing it inside a div. <div class="container border"> <div id="OptionsPanel" class="row lighten-1" *ngIf="isLoa ...