What is the best way to position a red circle in the top right corner of a centered div?

I am facing a CSS challenge and wondering if it is possible to achieve this using CSS or any other alternative solution would be appreciated. Below is an example of what I am trying to achieve.

My goal is to include red circles in the top right corner of the divisions. Here's my current code:

HTML

<div class="w3-container customheight">
  <div class="center buttons">
    <a class="todo roundbutton">
      <div class="redicon"></div>
      <div class="redicontext">
        <span class="todotext">1</span>
      </div>
    </a>
    <a class="decision roundbutton">
      <div class="redicontext">
        <span class="decisiontext">2</span>
      </div>
    </a>
    <a class="remark roundbutton">
      <div class="redicontext"></div>
        <span class="remarktext">3</span>
      </div>
    </a>
  </div>
</div>

CSS

.center{
  margin: 0 auto;
}
.roundbutton{
  width: calc(33.333% - 20px);
  height: 100%;
  margin: 10px;
  margin-top: 20px;
  margin-bottom: 20px;
  display:block;
  background-size: contain;
  float:left;
  background-repeat: no-repeat;
  background-position: center center;
  position: relative;
}

.todo{
  background-image: url("../img/todo.jpg"); 
}

.decision{
  background-image: url("../img/decision.jpg"); 
}

.remark{
  background-image: url("../img/remark.jpg"); 
}   

.redicon{
  position: absolute;
  top: 10px;
  left: 3%;
  background: red;
  padding:10px;
  box-sizing: border-box;
  border-radius: 100%;

}

.redicontext{
  position: absolute;
  top: 10px;
  right: 3%;
  padding:10px;
  box-sizing: border-box;
  border-radius: 100%;
}

I have already tried various methods including: - Creating another div behind the first one to apply padding without creating an oval shape - Using absolute values for the red circles, which work with specific height and width but need to be responsive.

Although I have a basic understanding of CSS, I still struggle with it. Any assistance on this matter would be greatly appreciated!

Thank you!

Answer №1

Use a relative position to adjust the circle's placement.

.redicon{
  position: absolute;
  top: -10px;
  right: -10px;
  background: red;
  padding:10px;
  box-sizing: border-box;
  border-radius: 100%;
}

Snippet

.center{
  margin: 0 auto;
}
.roundbutton{
  width: calc(33.333% - 20px);
  height: 130px;
  margin: 10px;
  margin-top: 20px;
  margin-bottom: 20px;
  display:block;
  background-size: contain;
  float:left;
  background-repeat: no-repeat;
  background-position: center center;
  position: relative;
}

.todo{
  background-image: url("//placehold.it/150");
  background-color: #fff;
  border-radius: 100%;
}

.decision{
  background-image: url("//placehold.it/150");
  background-color: #fff;
  border-radius: 100%;
}

.remark{
  background-image: url("//placehold.it/150");
  background-color: #fff;
  border-radius: 100%;
}   

.redicon{
  position: absolute;
  top: -10px;
  right: -10px;
  background: red;
  padding:10px;
  box-sizing: border-box;
  border-radius: 100%;
}

.redicontext{
  position: absolute;
  top: 10px;
  right: 3%;
  padding:10px;
  box-sizing: border-box;
  border-radius: 100%;
}
<div class="w3-container customheight" style="width: 450px;">
  <div class="center buttons">
    <a class="todo roundbutton">
      <div class="redicon"></div>
      <div class="redicontext">
        <span class="todotext">1</span>
      </div>
    </a>
    <a class="decision roundbutton">
      <div class="redicontext">
        <span class="decisiontext">2</span>
      </div>
    </a>
    <a class="remark roundbutton">
      <div class="redicontext">
        <span class="remarktext">3</span>
      </div>
    </a>
  </div>
</div>

Preview

https://i.sstatic.net/lWDmN.png

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 POST request did not yield an HttpResponse object; instead, it returned None

When I submit a selection from a dropdown form to views as a POST request, and then use this selection to query data from Django, I encounter an issue while trying to map Django models data to Highcharts following this approach. The error message "the view ...

Utilizing Bootstrap 4 to create fixed and fluid width side-by-side divs with scrollbars

I want to create a basic dashboard page. I decided to arrange two divs next to each other to serve as the side menu and content. Here is what the layout looks like: https://i.sstatic.net/EATK6.png I encountered an issue where the vertical scrollbar is n ...

Tips for altering the label color of an md-input-container after text has been entered

Is there a way to dynamically change the color of an md-input-container label after certain input is added? The default grey color gives the impression that the field is disabled. I specifically want to modify the color of the label "Description" when the ...

one container stacked on top of another

I have been creating web pages using tables for a long time. Recently, I decided to make the switch to using divs like everyone else, but it has been quite challenging. Can anyone help me solve this issue? I have included an image to better illustrate the ...

Create a sleek design by aligning labels with CSS 3 fancy radio buttons

I have a radio button with a larger circle that needs to be 38px input[type=radio] { visibility: hidden; } .label { font-weight: normal; color: #333; } .label::before { content: ''; position: absolute; left: 0; w ...

Container size is not accommodating elements

Currently in the process of developing a login page and utilizing @media for improved CSS layout on mobile devices. https://i.sstatic.net/LM8q8.png. The issue is that despite implementing @media rules, the inputs and buttons are not extending to the full w ...

The radio buttons are spread out too widely

While working on my website, I encountered an issue with a form that requires the user to input their name, email, gender, and date of birth. I utilized label for="" to ensure the CSS aligns accurately in each section. <form> <table> ...

Extracting targeted information from an HTML page using Python: A step-by-step guide

I'm a beginner in python and I need to scrape information from an HTML text file using python 2.7. The example below shows the structure of one firm's data in the HTML file. The same structure is used for all other firms as well, with each firm ...

The Android View fails to appear as VISIBLE

I am currently working on adding controls to my music player. Below is the XML structure I am using: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_wid ...

Picture goes missing from slideshow

I am currently using a CSS + Javascript slideshow on my website, inspired by an example from the W3Schools website. Here is the code I have adapted for my web application: $(document).ready(function() { var slideIndex = 1; function showSlides(n) { ...

Discovering a deeply nested div or class using Beautiful Soup

Recently, I came across this URL: All I want to do is extract the zestimate and include it in a list. The specific class where it's located is: class="Text-c11n-8-65-2__sc-aiai24-0 eUxMDw". I attempted to target it at a higher level in th ...

Blade - Assign a random CSS class from an array

I have been searching high and low for a solution to this issue, but so far, no luck. If it has already been addressed elsewhere, I apologize. Here is the code snippet I am currently working with: @{ foreach (var item in Model.Activities) ...

Tips for concealing the second dropdown menu from view when the first one is chosen

I'm having an issue with my menu bar that has 2 options showing dropdowns on click, but technically they are all displayed even if I only click one. My goal is to hide the other dropdowns when I click on a different menu item. Can someone help me ide ...

What causes the disappearance of CSS styles when attempting to modify the className in react js?

I am currently working on a basic react application, and I am trying to dynamically change the name of a div element using the following code snippet - <div className={'changeTab ' + (page.login ? 'leftSide' : 'rightSide')} ...

Increase the spacing between elements in a row using Bootstrap's margin utility

I am working with Bootstrap and have a row class containing three different elements. I want to create a margin of 20px between each element in the row container while keeping them all on the same line. Currently, when I add a margin class with a parameter ...

Modify the table layout by incorporating images within separate div containers for each row

In my layout, there is a grey box element that contains a table with rows of small images. I want the table to automatically adjust based on the number of images so that when the grey box reaches its maximum size, the images move to the next row. Is this a ...

What is the process for displaying the current bitcoin price on an HTML page using API integration?

I'm looking to develop an application that can display the current Bitcoin price by fetching data from the API at . I want to showcase this information within an h2 element. Any suggestions on how I could achieve this? Thank you in advance. const e ...

Ways to center a div with position:relative vertically on the page

What is the best way to center a position relative div vertically within its parent element? For example: <div class="parent"> <div style="position:relative;" class="child"> </div> </div> Any suggestions on how to vertic ...

html The selection in the dropdown menu is not showing the expected value

When using Firefox version 46.0.1, I encountered an issue with a select element that contains a value attribute being altered by Javascript code. Despite this change being confirmed in the browser inspector window with the select element showing a new valu ...

MaterialUI Box reigns supreme in the realm of background images

In my React component, I have a form that is structured like this: <Box display="flex" justifyContent="center" alignItems="center" style={{ minHeight: "100vh", backgroundColor: "gray", opacity: "0.8" }} > ... </Box> ...