Creating a circular price display using CSS:

Below is the code snippet that I am working with:

.special-price {
  text-align: center;
  background-color: #2e566e;
}

.special-price .offer {
  border-radius: 50%;
  background-color: #56c243;
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  height: 150px;
  width: 150px;
  display: inline-block;
  text-align: center;
  border: 1px solid;
}

.offer .symbol {
  vertical-align: top;
}

.offer .dollars {
  font-size: 60px;
}

.offer .cents {
  vertical-align: top;
}
<div class="row">
  <div class="special-price col-xs-12 col-md-8 col-md-offset-2">
    <div class="general-comparison clearfix">
      <div class="offer">
        <sup class="symbol">$</sup><span class="dollars">34</span><sup class="cents">.99</sup><span class="tax">+ TAX</span>
      </div>
      <!-- end .general-comparison -->
    </div>
  </div>
</div>

Query/Concern

  1. Why does the dollar sign extend beyond the circle?
  2. Even though I have applied text-align:center to the parent container, why is the child element offer not centered within the parent element special-price?

I am open to any suggestions for improving the visual appearance of this, as I do not possess a keen eye for design.

For a demonstration, you can view the JSFiddle linked here.

Answer №1

If you're looking to vertically center text, this previous solution offers a range of methods to achieve that.

My approach involved adding a nested div called price within the main offer container. This allowed for better control over the positioning of the text within the bubble element.

<div class="offer">
  <div class="price">
    <sup class="symbol">$</sup><span class="dollars">34</span><sup class="cents">.99</sup><span class="tax">+ TAX</span>
  </div>
</div>

Here is the https://i.sstatic.net/U7tJh.png for reference.

For a live example, you can view this JSFiddle demonstration. I also increased the text size and moved the +TAX portion to a new line for better readability.

Answer №2

If you wish to make adjustments to the price and unit at a later stage, consider utilizing a version with segmented content. Alternatively, you can incorporate the Dollar unit and cents into the pseudo-elements before and after.

For tasks like this, I find using flex to be quite effective. The

display: flex; align-items: center;
property aligns the content both vertically and horizontally within the circular section. Meanwhile, applying display: flex; to the p tag centers the sup tags horizontally.

* {
  box-sizing: border-box;
}

.price {
  width: 55px;
  height: 55px;
  border-radius: 50%;
  background-color: green;
  display: flex;
  align-items: center;
  color: #fff;
  }

.price, .price * {
  margin: 0;
  padding: 0;
}
    
.price p {
  font-size: 24px;
  display: flex;
  margin: 0 auto;
 }
 
 .price p sup {
  font-size: 12px;
 }
<section class='price'>
  <p>
  <sup>$</sup>
  34
  <sup>.99</sup>
  </p>
</section>

Answer №3

If you want to resolve these issues, you should consider implementing the following changes:

line-height: 2.6; should be applied to .special-price .offer

Additionally, you will need to adjust vertical-align to middle for both .offer .symbol and .offer .cents.

By making these adjustments, you should see an improvement in the display. Feel free to modify the line-height value to achieve the desired outcome.

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

Creating a CSS layout with tabs that include a visually appealing right space

My webpage is set up for tabbed browsing, with the tabs displayed as <li>s in block form. The parent div containing the tabs is floated to the right. However, I am encountering an issue where the last tab is not fully aligning with the right side of ...

Looking for an alternative to document.querySelectorAll?

My issue involves using querySelectorAll('a') to select all buttons, but I only want to target two specific buttons labeled 'Know More'. How can I achieve this? Below is the code snippet in question: const buttons = document.query ...

Halting the HTML-Embedded Video

Currently, I am utilizing a cross-browser embedding method like the following: <video width="549" height="309" controls poster="video/stills/index_demo_videoScreen.jpg" style="margin-top:20px;"> <source src="video/2014-reel-web.mp4" type="vid ...

Do you mean using a JSON object as a value?

When creating a JSON object where the value itself is an object, what is the correct way to write it? var data ='{"phone":{"gtd": "080"}}'; OR var data ='{"phone":"{gtd: 080}"}'; This question may seem straightforward. I am curious ...

What is the best way to display up to 8 items in a row using flexbox?

I'm looking to display my items in a grid system with equal spacing between each item per row. While using space-between works for the most part, I've encountered an issue with odd numbers of items. In this case, the last items in a row should be ...

Using Jquery and CSS to add a class with a 1-second delay when the mouse enters

I have successfully implemented the addClass function in my code, but I'm encountering issues when attempting to use delay or setTimeout functions. It's important to note that I'm avoiding the use of webkit attributes in CSS. If anyone has ...

A few of the input fields I filled out are not getting sent to the PHP script

Currently, I am working on a school project that involves creating a website similar to IMDB. My task is to include comments in our database, but I am facing an issue where two fields (fid and spoiler) are not getting posted to the PHP script handling the ...

Utilizing Jquery to pass two classes along

I am looking for assistance on how to pass multiple classes within if-else statements and jQuery. My goal is to have both divs and divs2 change when the next button is clicked. Can someone please provide guidance on achieving this? --code not mine-- ...

Detecting iOS format in HTML email communications allows for a more seamless

Recently, I discovered a meta tag that removes the phone number as a link in HTML on iOS. I'm curious if this also works with HTML emails. <meta name="format-detection" content="telephone=no"> I've been using workarounds to handle address ...

Having issues with implementing CSS3 animations on my webpage

I'm having trouble implementing a bouncing mouse animation on my website. The code works perfectly on another site, but on mine, it's not functioning at all. Here is the CSS code: .mouse { display: block; margin: 0 auto; text-alig ...

Ensuring User Input Integrity with JavaScript Prompt Validation

I need help with validating input from a Javascript prompt() in an external js file using HTML code. I know how to call the Javascript function and write the validation logic, but I'm unsure how to handle the prompt and user input in HTML. Do I need ...

Avoid Conversion of HTML Entities in Table Cells

<table> <tr> <td>&gt;</td> </tr> <tr> <td>&&#xfeff;GT</td> </tr> </table> In the code snippet above, I have table cells containing HTML entities. A re ...

Toggle Visibility of Div Based on Matching Class Name When Clicked

Just delving into the world of jQuery and could use some guidance. Is there a way to show a div with a matching class when a specific button is clicked? For example, clicking on a button with the class '.project1' should display the corresponding ...

Flexible layout of perfectly square elements

I am currently working on creating a responsive grid layout consisting of squares that are positioned absolutely within their parent element. The goal is to ensure that when the page is resized, the squares scale proportionally with their parent container ...

Conceal one object when the other is revealed?

Is there a way to hide the element with the class .close-button while showing another element with the ID #loading-animation? Can jQuery conditionals help achieve this? For example: if ($('#loading-animation').is(':visible')) { $ ...

Having trouble displaying a background image on a React application

Public>images>img-2.jpg src>components>pages>Services.js> import React from 'react'; import '../../App.css'; export default function Services() { return <h1 className='services ...

Tips on creating a responsive absolute div

I'm currently working on creating a profile component with Material UI and React.js. I'm having trouble making the Avatar/profile photo and profile name div responsive. Here are some screenshots to illustrate my issue: The specific div that need ...

The ng-View feature appears to be malfunctioning within AngularJS

I'm extremely new to AngularJS and am having trouble with ng-view. Here is the code from AngularFormsApp.js: var angularFormsApp = angular.module('angularFormsApp', ["ngRoute"]); angularFormsApp.config(function ($routeProvider) { $routeP ...

The dropdown menu in Bootstrap is malfunctioning despite the up and down arrow keys working properly

I've been attempting to create a basic dropdown menu using Bootstrap dropdown, and so far, it's been working perfectly in most instances. However, on certain pages, when I click on the three dots that are supposed to activate the dropdown, nothin ...

Activate the WebDAV feature within the .htaccess file

Can WebDAV be activated through an .htaccess file? I'm experiencing issues with Plesk not recognizing my modified config files that have WebDAV enabled. Is it feasible to enable WebDAV without using an .htaccess file? ...