What is the CSS technique for incorporating "two-toned" font variations?

There are specific fonts that offer both an outline and filled variant. When used on overlapping text, these fonts create a stroke effect over the filled text. This differs from a basic outline provided by -webkit-text-stroke-color, as the filled font may include shading or other intricate details.

Check out some examples of fonts designed for this purpose:

I attempted to achieve this effect using CSS with the following code:

http://jsfiddle.net/6SakC/2/

This code creates two H1 spans and uses top-margin to position the outline above the filled text.

However, I find this method less than ideal due to the following issues:

  • I don't want to repeat the text in the HTML code.
  • The positioning requires trial and error guesswork with top-margin values.
  • If the text wraps, the technique no longer works effectively.

Is there a more efficient way to achieve this effect? While duplicating the text is acceptable, I would prefer a more automated approach to positioning.

Thank you!

Answer №1

One way to enhance the design is by inserting the outline text within the h1 tag and utilizing absolute positioning instead of estimating margins. Check out this example on jsFiddle: http://jsfiddle.net/6SakC/4/.

This method also resolves any issues related to text wrapping.

To prevent redundancy in the markup, consider using JavaScript to generate the duplicated text, like demonstrated in this provided jsFiddle link: http://jsfiddle.net/6SakC/5/. Keep in mind that relying too much on JavaScript may have drawbacks, especially if it's disabled in the browser settings and causes a delay in displaying the outlined text.

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

Can Font Awesome icons be resized beyond 'fa-5x'?

I recently implemented the following HTML code snippet: <div class="col-lg-4"> <div class="panel"> <div class="panel-heading"> <div class="row"> <div class="col-xs-3"> <i class="fa fa-cogs fa- ...

Desiring the standard back button feature of a browser to work seamlessly when loading pages via ajax requests

I am currently developing a web application in PHP and implementing the use of AJAX requests to retrieve pages from the server. For example, when a user clicks on menu tabs, an AJAX request is made to the server to fetch the page and load it into a specifi ...

I am looking for an HTML solution that allows me to neatly stack photos of different sizes in two columns, always prioritizing the column with more empty space

Is there an easy method to populate two columns, each with a width of 50%, with photos in a way that the next photo is always added to the column with more available space? The photos come in different sizes but should be able to fit within the width of t ...

Ways to ensure the entire background photo is visible on the page

I've been searching for a solution to fit my specific needs, but nothing I've found seems to work. My screen resolution is 1920x1080 and I'm designing a single-page website. The challenge is that I want the background photo to cover 100% of ...

Seeking instructions on incorporating multiple components in a tab section effectively?

I am currently using a tab system that functions flawlessly. As I delve into learning VueJs, one concern has arisen in my mind about components and/or templates: Using the analogy of tab windows, how can I incorporate two components within a single tab, s ...

Utilize the value of one input-number field as the maximum value for another field

I am looking for a solution to save the value of an input-number field in order to set it as the maximum value for another input-number field. What is the most effective method to achieve this task? Whether it be through PHP, JavaScript, jQuery or any othe ...

Issues with font rendering on Firefox making it difficult to read

Our website's Wordpress theme utilizes the font Montserrat, which is properly displayed in Chrome, IE, and Safari, but is experiencing issues in Firefox. Below is the CSS styling for the font: @font-face { font-family: 'montserratbold'; ...

The Outer Div Can't Contain Google Maps

I am currently working on integrating a map widget into a dashboard I created using gridstack.js. The sample widget layout that I am aiming for can be seen in the link below: https://i.sstatic.net/ZQP6G.png My goal is to embed the map within the inner (w ...

Watching mov and mp4 files directly in your web browser

I am currently experimenting with the HTML5 video tag and database video files. In my database, I have several records that contain both mov and mp4 files. While HTML5 video tag supports mp4 files, it's a different story when it comes to mov files. I& ...

Creating a continuous loop in JQuery when clicking on a table row

I seem to be encountering an issue with what appears to be an infinite loop. My problem arises while trying to create a table dynamically using Ajax. Each row of the table contains a button alongside a thumbnail image and some text. I wish for the button ...

Exploring MVC 5's View and Controller Components

In my GetCourseList.cshtml file (view), I have the following code that displays fetched information from the database: @model IEnumerable<WebApplication8.Models.Courses> @{ Layout = null; } <!DOCTYPE html> <html> <head> ...

What could be causing my webpage to freeze every time a filter button is selected?

Tasked with developing a webpage similar to Pinterest by utilizing data from a JSON response. Each JSON object contains a service_name key, which can be manual, twitter, or instagram. I made an effort to implement three filter buttons to only display the r ...

Javascript's regular expression can be utilized to detect an img tag that has no specified image source (src="")

My specific need is to eliminate all img tags that do not have the attribute "img" specified within them. I attempted to accomplish this using a regular expression - content.replace(/<img[^>]*>/g,""). However, this approach removes all img tags ...

Updating pictures on Bootstrap's project showcase template

I attempted to modify the source of an image by clicking on smaller ones using bootstrap’s template found at . Despite my efforts, I have not been able to achieve the desired result. (Any help is greatly appreciated!) I included id="myImage" on the main ...

Tips for moving a specific menu item to the right in bootstrap 4

Currently, I am integrating Bootstrap 4 into a Laravel 8 blog platform that I am working on. While the menu items are correctly positioned, I am facing an issue where I need to move the last menu item to the right. Despite trying various options like ml- ...

Creating a responsive loading button using Bootstrap 5

I'm struggling to create a button that displays a loading message. In my HTML file, I have: <div class="btn-area"> <button id="connectMetamaskBtn" class="btn sp-btn" type="button" ...

Guide to updating the content of a div by selecting a button located outside the div

Thank you for taking the time to go through this post. I hope that those with similar questions will find their answers as well. Currently, I am in the process of developing a single-page website that is divided into 8 large divs. The concept is such that ...

Refresh your textarea content using the replace method in jQuery

My goal is to extract and manipulate specific values within a user-entered code using jQuery. The code includes custom tags called setting, which I want to extract and display in input fields for easy editing. I have successfully retrieved and displayed th ...

Converting HTML into an image in a Node.js Buffer

Can you suggest a simple method to convert a raw HTML string, like the following: <b>Hello World</b> into a regular PNG image in Node.js Buffer form? I've been exploring various npm packages for a solution that supports this functionali ...

Modifying the color of a specific div using jQuery

I am attempting to develop a function that changes the background color of a div when a user clicks on it and then clicks on a button. The value needs to be saved as a variable, but I'm having trouble getting it to work because it keeps saying that th ...