Tips for designing a horseshoe-inspired meter using CSS

 

I want to create a horseshoe-shaped gauge using CSS that resembles the image below:

 

 

My attempt involved creating a circle and cutting off the bottom, similar to the technique demonstrated in this fiddle: http://jsfiddle.net/Fz3Ln/12/

 

Here's the markup I used:

<div class="container">
    <div class="horse-shoe-gauge"></div>
</div>
 

And here's the CSS styling:

.container {
   width: 200px;
   height: 180px;
   overflow: hidden;
}
 
.horse-shoe-gauge {
    width: 200px;
    height: 200px;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border-radius: 50%;
    border: 10px solid black;
   box-sizing: border-box;
}
 

However, achieving the perfectly rounded bottom has been challenging for me.

 

If you have any tips or suggestions on how to improve my approach, I would greatly appreciate it. Thank you.

 

Answer №1

To achieve the rounded bottoms that you desired, I created an outer container and then positioned some additional elements absolutely.

HTML

<div class="outerContainer">
    <div class="container">
        <div class="horse-shoe-gauge"></div>
    </div>
    <div class="bottom left"></div>
    <div class="bottom right"></div>
</div>

CSS

.outerContainer {
    position: relative;
}
.container {
    width: 200px;
    height: 180px;
    overflow: hidden;
}
.horse-shoe-gauge {
    width: 200px;
    height: 200px;
    -webkit-border-radius: 50%; 
    -moz-border-radius: 50%; 
    border-radius: 50%; 
    border: 10px solid black;
    box-sizing: border-box;
}
.bottom {
    position: absolute;
    width: 25px;
    height: 10px;
    border-radius: 8px;
    background: #000;
}
.left {
    bottom: -6px;
    left: 38px;
    -webkit-transform: rotate(32deg);
}
.right {
    bottom: -6px;
    left: 137px;
    -webkit-transform: rotate(-32deg);
}

For a live example, check out this jsFiddle

Answer №2

Here's a unique approach using :before and :after to achieve the desired effect without modifying the HTML structure.

However, I would suggest exploring the use of canvas for more precise control over the design.

Check out this JSFiddle link

.horse-shoe-gauge:before {
    content: "";
    display: block;
    position: absolute;
    bottom: -5px;
    left: 12px;
    height: 10px;
    width: 10px;
    border: 15px solid white;
    border-top-color: transparent;
    border-left-color: transparent;
    background-color: black;
    background-clip: padding-box;
    -webkit-border-radius: 50%; 
    -moz-border-radius: 50%; 
    border-radius: 50%; 
}

.horse-shoe-gauge:after {
    content: "";
    display: block;
    position: absolute;
    bottom: -5px;
    right: 12px;
    height: 10px;
    width: 10px;
    border: 15px solid white;
    border-top-color: transparent;
    border-right-color: transparent;
    background-color: black;
    background-clip: padding-box;
    -webkit-border-radius: 50%; 
    -moz-border-radius: 50%; 
    border-radius: 50%; 
}

For a visual demonstration, visit this updated fiddle.

Answer №3

How about giving this a try:

http://codepen.io/robcampo/pen/YXpWLP

This code snippet should be compatible with IE10 and above. It rotates two divs next to each other, utilizing markers to create rounded edges:

<div class="radial-wrapper">
  <div class="radial-section radial-right-section">
    <div class="wedge"></div>
  </div>
  <div class="radial-section radial-left-section">
    <div class="wedge"></div>
  </div>
  <div class="marker start"></div>
  <div class="marker end"></div>
</div>

Although it may appear complex at first glance, the technique is explained step by step in this tutorial:

Feel free to explore and learn from it!

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

Discovering the CSS code for customization

As a beginner, I apologize in advance for any silly questions ˆˆ I am currently working on a website using bootstrap. Everything is functioning correctly, but I am struggling to override some CSS styles. In the image provided, you can see how I used the ...

Exporting JSON data to an Excel file using an array of objects with embedded arrays

I am currently developing a fitness application that allows users to create workout routines and download them as an excel file. The data is structured as an array of objects, with each object representing a workout date and containing details of the exerc ...

Socket.io-powered notification system

I'm currently in the process of developing a notification system for my Events Manager Website. Every time a user is logged in and performs an action (such as creating an event), a notification about the event creation should be sent to other user ...

Guide on incorporating custom items alongside default items in the Context Menu of Handsontable

I attempted to utilize handsontable and am interested in incorporating custom additions to the context menu. While there are numerous tutorials on how to implement custom menus, they often overlook the default items. In an effort to address this issue, I ...

Utilize prop-types inheritance when a component is rendered via props

Is it possible to inherit prop-types when a component is rendered via the parents prop, without direct access to 'ChildProps' and 'Props' interface? Parent Component interface ChildProps { counter: number; setCounter: React.Dispat ...

What is the best way to manage an empty JavaScript object?

I'm feeling stuck. Check out this code snippet: const clientInfoPromise = buildPromiseMethod clientInfoPromise.then((clients) => { console.log('clients ' + JSON.stringify(clients)) console.log(clients.typeOf) console.log(_.k ...

Encountering a Forbidden Error with Superagent

Here is the content of my index.js file I am attempting to fetch a response from a sports data API. I can successfully send curl requests to it, but when trying this method, I encounter a 403 forbidden error. var express = require('express'); v ...

Tips on how to round a whole number to the closest hundred using Javascript

Suppose there is a numerical value given let x = 890 and the objective is to round it off to 900. If the number is 820, then it should be rounded to 800. We can safely assume that the input number (x) will always be an integer. While manually checking ...

Switch the checked status of an input dynamically using jQuery function

It seems like I might be overlooking something quite obvious, but I can't figure out why this jquery function is behaving inconsistently. HTML: <label id="income_this_tax_year"> <div class="left"> <p>Have you had Self-Employm ...

What is the best way to reveal or conceal a div element on mouseover with jQuery?

Currently, I have a table with the following structure. <table> <tr> <td id="divOne">div one</td> <td id="divOne">2222</td> </tr> <tr> <td id="divOne">d ...

The error message that appeared states: "TypeError Object[object object] does not have the SubSelf method, TypeError Object[object object] does not

As I delved into a WebGL project, leveraging the powerful Sim.js and Three.js libraries, an unexpected obstacle emerged: At a certain point, within the code, the constructor for THREE.Ray is utilized in this manner: var ray = new THREE.Ray( this.camera.p ...

``There seems to be an issue with the functionality of Angular's $routeProvider

I'm currently facing an issue with my setup. I have a local angular front-end running on localhost using an Apache Server on Linux. When I try to access localhost, everything works fine and I can see my index.html. However, I have a link in the index. ...

Deploying NextJS: Error in type causes fetch-routing malfunction

Encountering a mysterious and funky NextJS 13.4 Error that has me stumped. Here's a summary of what I've observed: The issue only pops up after running npm run build & npm run start, not during npm run dev The problem occurs both locally and ...

The website is not optimized for mobile viewing

I have recently made an existing website responsive using Twitter Bootstrap. Everything seemed to work fine when I tested it by resizing the browser window, as it perfectly fit in the viewport. However, upon checking the site on mobile and tablet devices, ...

Why won't applying a binding style affect the appearance of my Vue component?

const EventLevelBoard = { name: "EventLevel", data: { levelStyle: { display: "block" }, levelStyleinner: [ { display: "block" }, { display: "block" }, { display: "block&qu ...

Updating the language of the months displayed in the popup calendar

I am attempting to change the language of the clickDate function from English (Jan, Dec, etc.) to another language. However, I am struggling to find a way to do so because I only have access to the scripts provided below. The idate is in the format 2015073 ...

Is it possible for me to include additional fields in a vuetify calendar event?

Is there a method to incorporate additional fields, such as a description, in addition to the name and start/end time for an event on the v-calendar's day view? ...

Markdown in Vue.js filters

I found a helpful example by Evan You on how to convert HTML to markdown - check it out here. However, when trying to install the marked package via npm and implementing it, I encountered an error stating that 'marked' is not defined. After inc ...

Determine whether a div contains any child elements

I am working on a piece of code that checks for the presence of the class "wrong" in any of my divs, and if found, displays a jQuery UI dialog box. My goal now is to enhance this code by adding a condition where it also checks for empty divs before showing ...

Prettyprint XML in Angular 8+ without using any external libraries

I am working with Angular 8+ and I need to display XML content in a nicely formatted way on my HTML page. The data is coming from the backend (Java) as a string, and I would like to present it in its XML format without relying on any external libraries or ...