Forming a ring around a character within a header one element

I am faced with the challenge of only circling a single letter within a word that is contained in an H1 tag. While creating a circle around text is easy, I specifically need to target just one letter:

.large {
  font-size: 5em;
}

.circle {
  border-radius: 50%;
  padding: -0.5% 5% 0% 5%;
  background: #fff;
  border: 10px solid red;
  color: red;
}
<h1 class="large">
  <span class="circle">e</span>Text
</h1>

Check out the Fiddle here: https://jsfiddle.net/henzen/zwph2nsv/4/ This code snippet produces the following output:

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

The circle seems to match the height of the H1 element (as far as I can tell) - my goal is to reduce its vertical size so that it hugs the "e" closely both vertically and horizontally.

Is there a way to achieve this without separating the "e" from the rest of the word in the HTML markup?

I have experimented with Unicode characters like &#9428, but they don't offer consistent styling across various browsers.

Any advice or suggestions would be greatly appreciated.

Answer №1

One solution is to utilize a pseudo element.

    .large {
      font-size: 5em;
    }

   .circle {
     position: relative;
     color: red;
    }
    
    .circle:after {
      content: '';
      width: 39px;
      height: 44px;
      border: 4px solid red;
      position: absolute;
      border-radius: 50%;
      left: -5px;
      top: 27px;
    }
<h1 class="large">
  <span class="circle">e</span>Text
</h1>

Answer №2

Utilize a pseudo element for this effect.

Give this a shot: https://jsfiddle.net/2gtazqdy/12/

* {
 margin: 0;
 padding: 0;
}

.large {
  font-size: 5em;
}


.circle {
  height: 50px;
  width: 50px;
  display: inline-block;
  padding-left: 20px;
}

.circle::after {
  display: inline-block;
  height: 50px;
  width: 50px;

  z-index: 1;
  position: absolute;
  top: 18px;
  left: 4px;

  content: "";

  color: red;

  background: transparent;
  border: 10px solid red;
  border-radius: 50%;
}

Here is the outcome I achieved: https://i.sstatic.net/wxmbs.png

Answer №3

Give this a shot in your HTML markup:

<h1> <span> C </span> ircle </h1>

Next, style the span within the h1 element in your CSS by adding some padding to create a rectangular shape:

padding: 20px 10px;

Then, apply a border around the span, for example:

border: 5px solid #ddd;

Lastly, add a border radius to round the edges. It may take some trial and error with pixel values to get it just right:

Border-radius: 20px

Your updated HTML:

<h1> <span> C </span>ircle </h1>

Your complete CSS styling:

h1 span{
    padding: 20px 10px;
    border: 5px solid #ddd;
    border-radius: 20px;
}

Answer №4

To create a circular shape, you'll need the following:

  • display: inline-block (or display: block)
  • Equal width, height, and line-height
  • text-align: center

Ensure that em values correspond to the font-size of the container.

Here's an Example:

.large {
  font-size: 5em;
}

.circle {
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  line-height: 0.8em;
  text-align: center;
  border-radius: 50%;
  background: #fff;
  border: 0.05em solid red;
  color: red;
}
<h1 class="large">
  <span class="circle">e</span>Text
</h1>

Answer №5

Feel free to test out this code snippet

.big{
text-align: center;
font: 40px Arial, sans-serif;
color:#000;
font-weight:bold;
}
.round {
  border-radius: 50%;
background: #fff;
border: 6px solid red;
padding: 3px 10px;
text-align: center;
font: 28px Arial, sans-serif;
color: #000;
font-weight: bold;
}
<h1 class="big">
  <span class="round">e</span>Text
</h1>

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 navigation bar's background color remains static and doesn't update as

Struggling with HTML/CSS and unable to get the NAV bar to display the specified background color. Tried putting the nav in a class, commented out parts of the code, but still couldn't make it work. Despite looking for solutions, I can't figure ou ...

What is the solution to the error message "cannot find specified file or directory, lstat 'scss/'"?

I am currently following a tutorial on YouTube here where the instructor is demonstrating how to run an npm script "sass" file using the terminal. When I try executing the command npm run sass, it gives me an error message: Error: ENOENT: no such file o ...

Tips for choosing a particular value in an HTML <script> query

Can someone please help me figure out how to select specific values in a form using a query? I'm trying to extract certain values like Hello and Lorem ipsum..., as well as Hi and Nullam fringilla... from the Content.join(''); section. I apo ...

The Angular Observable continues to show an array instead of a single string value

The project I am working on is a bit disorganized, so I will try to explain it as simply as possible. For context, the technologies being used include Angular, Spring, and Maven. However, I believe the only relevant part is Angular. My goal is to make a c ...

Having trouble with Jquery not working, and I'm stumped trying to solve it

I wrote this function but I can't figure out why it's not working. The JS file is being loaded because other functions inside it are functioning properly, but those with this specific format aren't: $(function () { .... }); The intention ...

HTML - Align 3 tables horizontally with text below

I have successfully floated 3 tables next to each other using <table style="float:left;">. However, I am facing an issue where some text is being wrapped to the right side of the right-most table instead of being left-justified at the very ...

premature submission alert on button press

I'm encountering an issue where my form is being submitted prematurely when I click on the button. The desired behavior is for the button to create a textarea upon clicking, allowing me to write in it before submitting by clicking the button again. Ho ...

Scrape data from LinkedIn search results using HtmlAgilityPack

Looking to fetch the top search result for a LinkedIn query. Check out this fiddle: https://dotnetfiddle.net/Vtwi7g Passing this link to 'html' variable: Targeting the first result : Wondering how to pass credentials for logging into Lin ...

What is causing the align content property to not function as expected in this situation?

Is it expected for the flex items of the .center-section-container to be closer together when using this property? They do not seem to be affected at all. I have applied flex wrap so the items are now in different lines but too far away from each other, I ...

Incorporate a fontawesome icon into a dynamically created button using ajax

Is it possible to insert fontawesome icons into a button created using this code snippet? $.each(response, function (i, item) { trHTML += '<tr><td>' + item.name + '</td><td>' + "<input type='button&apo ...

Struggling to locate the element using xpath on a JavaScript enabled website in Selenium with Chrome

I have been attempting to extract data from a website that utilizes Javascript. Despite researching similar inquiries on xpath in Selenium, I have not found a solution. I initially tried using requests, but as the JavaScript doesn't load completely, I ...

Tips on how to showcase up to 200 characters from a string

<?php include ($_SERVER['DOCUMENT_ROOT'].'/header.php'); include ($_SERVER['DOCUMENT_ROOT'].'/adtop.php'); if(mysql_num_rows($deals) > 0){ while($row = mysql_fetch_assoc($deals)){ echo '<div id= ...

Make sure to utilize the className attribute when styling a Material-UI component

I am attempting to apply CSS styles to a Material-UI component. defined in MyCss.css .trackTitle { color:white; } located in myComponent.js import "./MyCss.css" <Grid container item xs={1} className="trackTitle"> change col ...

How can JavaScript be used to toggle the visibility of text on a webpage

Can anyone help me with a problem I'm having toggling text? I have a truncated text and I want to be able to switch back and forth between the truncated text and the original text on button click. Here is a link to the pen. var myButton = documen ...

Conceal pagination numbers using jquery pagination

I have integrated a jquery function to handle pagination of items on my website. Below is the function code: (function($) { var pagify = { items: {}, container: null, totalPages: 1, perPage: 3, ...

Exploring Android Webview capabilities using HTML 5 geolocation

Utilizing a webview to load a web application, I am using the HTML 5 geolocation API within the page to detect the user's location. While this feature works seamlessly in all browsers and even in an iOS application, I am facing issues getting it to fu ...

Effective Ways to Redirect During or After Executing the onClick Function of Button

I am currently working on implementing a feature for my Next.js website. The functionality involves allowing users to create a new group by clicking a button, and then being redirected to an "Invite members" page with the auto-generated group_id included i ...

Capture information from an HTML5 form and securely store it in a MySQL database

I have a simple web form that includes a "date" type input field. I want to retrieve the date entered by the user and store it in my MySQL database, which has a DATE type column. I am looking for some PHP/JS magic to facilitate the communication between t ...

Error in Form Validation: inconsistent positioning of relative jump and sticky header

I have a webpage with a web form and a sticky header. When a user attempts to submit the form without filling in required fields using a modern-ish browser, an error message pops up as expected. The issue arises when the sticky header hides the input field ...

The content within a div block is having trouble aligning vertically

I need help with centering the content inside my fixed-top navigation bar vertically. I am using bootstrap to design my page, and the navigation bar consists of an image as the nav header and a container with links. The container surrounding these element ...