What is the best way to create a semi-completed circle?

I'm looking to create a unique design by filling half of the circled outline. Take a look at this image and accompanying code snippet:

    <body>
        <div id="ui">
            <div class="status">
                <div class="health">
                    <i class="fa fa-solid fa-heart"></i>
                </div>
                <div class="armor">
                    <i class="fa fa-solid fa-shield-halved"></i>
                </div>
                <div class="hunger">
                    <i class="fa fa-solid fa-drumstick-bite"></i>
                </div>
                <div class="thirst">
                    <i class="fa fa-solid fa-wine-bottle"></i>
                </div>
            </div>
        </div>
    </body>
.thirst, .armor, .health, .hunger {
    display: flex;
    justify-content: center;
    align-items: center; 
    outline-style: solid;
    outline-offset: -3.5px;
    outline-width: 3.5px;
    border-radius: 100%;
    font-size: 14px;
    margin-top: 10%;
    color: rgb(0, 0, 0);
    height: 40px; width: 40px;
    box-shadow: 0px 0px 2px rgb(0, 0, 0);
    text-shadow: 0px 0px 1px rgb(0, 0, 0);
    background-color: rgba(0, 0, 0, 0.5);
}

The current appearance of the circular outline is shown below:

Despite attempts to implement linear gradient, I encountered some challenges.

Answer №1

To create circular gradients, it is recommended to use radial-gradient instead of linear-gradient. Adjusting the percentages in the code will allow you to control the thickness of the line.

.status {
  display: flex;
}

.thirst, .armor, .health, .hunger {
    display: flex;
    justify-content: center;
    align-items: center; 
    outline-style: solid;
    outline-offset: -3.5px;
    outline-width: 3.5px;
    border-radius: 100%;
    font-size: 14px;
    margin-top: 10%;
    color: rgb(0, 0, 0);
    height: 40px; width: 40px;
    box-shadow: 0px 0px 2px rgb(0, 0, 0);
    text-shadow: 0px 0px 1px rgb(0, 0, 0);
    background-color: rgba(0, 0, 0, 0.5);
    margin-right: 10px;
}

.health {
  background: radial-gradient(rgba(0,0,0,0.5) 0% 40%, black 41%);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" rel="stylesheet"/>
<div id="ui">
    <div class="status">
        <div class="health">
            <i class="fa fa-solid fa-heart"></i>
        </div>
        <div class="armor">
            <i class="fa fa-solid fa-shield-halved"></i>
        </div>
        <div class="hunger">
            <i class="fa fa-solid fa-drumstick-bite"></i>
        </div>
        <div class="thirst">
            <i class="fa fa-solid fa-wine-bottle"></i>
        </div>
    </div>
</div>

Answer №2

In my approach to tackling this challenge, I opted not to use the "outline" property as it may not be the most effective solution. Instead, I utilized a combination of a background-image with a radial-gradient for the background and a conic-gradient with percentage values to represent the health status. Additionally, I leveraged CSS variables in setting these values and provided examples within the markup on how they can be adjusted. To add a touch of flexibility, I incorporated color variations.

The output of my implementation looks like:

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

.thirst, .armor, .health, .hunger {
    --health: 50%;
    --healthColor: #f8f8f8;
    display: flex;
    justify-content: center;
    align-items: center; 
    color: #fff;
    height: 40px; 
      aspect-ratio: 1;
    border-radius: 50%;
    font-size: 14px;
    box-shadow: 0px 0px 2px rgb(0, 0, 0);
    text-shadow: 0px 0px 1px rgb(0, 0, 0);
    background-color: transparent;
      background-image: radial-gradient(
          circle,
            #252526 15px,
            transparent 9px 18px,
            #252526 18px
        ),
            /* conic gradient can also be done using deg units. 90deg = 25%, etc */
        conic-gradient(
          var(--healthColor) var(--health),
            #252526 0
        );
}

body {
    display: flex;
    gap: 40px;
    background: #7d7d7e;
}
.ui {
    width: 40px;
}
.status {
  display: grid;
    gap: 10px;
}

<!-- The remaining code snippets are related to styling levels and UI elements -->

<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" rel="stylesheet"/>

<div><img src="https://i.imgur.com/Jhb4elX.png"></div>

<div id="ui" class="ui">
  <div class="status">
    <div class="health"><i class="fa fa-solid fa-heart"></i></div>
    <div class="armor"><i class="fa fa-solid fa-shield-halved"></i></div>
    <div class="hunger"><i class="fa fa-solid fa-drumstick-bite"></i></div>
    <div class="thirst"><i class="fa fa-solid fa-wine-bottle"></i></div>
  </div>
</div>

<!-- Additional UI element configurations with custom styles based on different levels -->

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

Transforming an HTML and Javascript Project into a Standalone Application

Currently, I am engaged in a side project to enhance my skills in HTML/CSS/JavaScript. I have been using Aptana as my primary tool for coding, and it is configured to run smoothly in a browser environment. Specifically, the project I am working on is a te ...

Extracting information from JSON ( AngularJS)

I have a collection of questions stored in my JSON file, but I want to display only one at a time until the user selects the correct answer and proceeds to the next question. Here is the HTML template: <div ng-controller="quizController"> <ul> ...

Styling a Form Submission with CSS

I am currently working on a website that contains the following PHP code: echo "<form action='choice.php' method='post'>"; echo "<input type='submit' name='choice' value='left' /> "; As I am i ...

Set the height of one element to equal the height of a different element using CSS

This is the code that I am working with: <div class="row"> <div class="box-body"> <div class="col-lg-12"> <div class="wrapper2"> <div class="col-xs-6"> <ul id="matchline ...

Tips to position a div directly on top of table cells using absolute positioning

I have a div inside the second table cell that I want to position absolutely right outside the <td>. Currently, the issue is that the <td> elements below are overlapping the div. Eventually, each <td> will contain a div that appears on ro ...

How to Align HTML Menu in the Middle of the Page

I've been struggling to center my menu on the page. I tried setting the display to block and using margin auto for left and right, but it's not working as expected. You can see the issue in this JSFiddle. Any help would be appreciated. <ul id ...

Is it possible to save a dynamic web page to a file?

I am a beginner C++ programmer diving into the world of web development for the first time. My current challenge involves finding a way to continuously capture and save the HTML content of a constantly updating third-party website onto a static HTML file ...

Intersection of content in panel-body using bootstrap tab pills

Can someone help me solve a major issue? I need the content of each tab to overlap as if they are unaware of each other. Currently, my code is saved in this fiddle: https://jsfiddle.net/axq882de/1/. When I click on different tabs, the contents should remai ...

I'm having trouble making the colors change on my Icon font/sprite rollover

I am currently attempting to position some related icons above my main navigation menu. The goal is to change the text and icon colors when a user hovers over a specific area (the tag with large padding). Unfortunately, I am facing challenges in achieving ...

Wrapping a series of grids within a parent container to manage height effectively with grid960

Testing on the following browsers: Internet Explorer, Chrome, Firefox; Check out this example of an ideal layout in a PDF: Here is the link to the direct page: While Grid systems work well for width layout, I struggle with setting height constants. In ...

Grid numbering with CSS in jQuery mobile design

Looking to create a numbered grid where the user inputs a number and the grid is generated. I am considering using CSS, HTML, or Jquery Mobile for an iPad project. I'm unsure of the best approach at the moment. I would like the grid and numbers to aut ...

The functionality of my bootstrap carousel seems to be malfunctioning as the fdi-Carousel slide is

Whenever I check for errors in the Chrome console, I come across this error: Uncaught ReferenceError: $ is not defined. It seems to be related to my code. Can anyone help me identify what might be causing this issue? Below is a snippet of my code from &apo ...

What could be the reason behind Bootstrap not functioning properly?

I'm having trouble with the navigation display in bootstrap, as I am new to it. <!DOCTYPE html> <html> <head> <title>Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <l ...

Position an image to the right with a specific height using position absolute in Bootstrap 4.3

enter image description hereI am in the process of updating my Bootstrap 4.0 CSS to Bootstrap 4.3 CSS. Within my price section, there are 3 pricing panels. One of these panels includes an image with absolute positioning and specific pixel coordinates - l- ...

developing a star rating system for a mobile website

Can star ratings be implemented in a mobile website using HTML, CSS, and JS? The HTML code for the stars is as follows: <div class="rating"> <span>☆</span><span>☆</span><span>☆</span><span>☆</sp ...

Stop a div at a specific point with this unique jQuery plugin

I am looking to implement a similar feature on my website that can be seen here: The desired functionality is when a link stops at a certain point while scrolling, and upon clicking the link it smoothly scrolls to a designated div. Additionally, as you sc ...

Is there a way to customize the mark style in Bootstrap?

I've gone through numerous articles on this issue, but I'm still unable to resolve it. My goal is simply to eliminate the padding that bootstrap automatically adds around the mark tag. This is important because I am dynamically changing highlight ...

The integration of Angular CLI with SCSS is no longer a separate process -

It seems like I might be overlooking something very straightforward here. After a fresh installation of angular-cli, I created a new website with SCSS. I input the SCSS in the global style.scss as well as some in a component SCSS file. However, when I se ...

Two separate tables displaying unique AJAX JSON response datasets

As a beginner in javascript, I am facing a challenge. I want to fetch JSON responses from 2 separate AJAX requests and create 2 different tables. Currently, I have successfully achieved this for one JSON response and table. In my HTML, I have the followi ...

Manage the width of flex items organized vertically within a flexbox parent

I'm struggling to achieve the desired effect where the boxes labeled "HALF" only take up 50% of the width, evenly sharing the first row. The main requirement is that these boxes remain within a single container. Is it possible to accomplish this usin ...