The Unique Font That Mysteriously Blocks Fake Italic Styles on Webkit Browsers

Currently, I am utilizing the PT Sans Narrow font in my project, which unfortunately only offers regular and bold styles. As a result, I require the browser to apply faux italics when needed. Strangely, this functionality is only working on non-webkit browsers at the moment. An example of the issue can be seen in this image:

This peculiar behavior seems to be connected specifically to this font, as other fonts are displaying correctly. (You can observe this by checking out this JSFiddle: http://jsfiddle.net/pEVj7/) The comparison font used in the JSFiddle was created with the same parameters from Font Squirrel.

The solution I'm looking for is a simple way to include italicized text using tags like the following, and have the browser substitute with faux-italics if necessary:

<i>My custom italic text</i>

P.S. While I acknowledge that faux-italics may not be an ideal substitute for real italics, in this case, they are still preferable to having no access to italics at all. Additionally, I cannot use Google Webfonts due to their subpar rendering in Chrome.

Answer №1

It appears that the issue lies within the SVG format of the font. By excluding it, Chrome will utilize the WOFF format and apply a faux italic effect to the text.

To confirm this, I downloaded PT Sans Narrow from Google and used the FontSquirrel generator with default settings. Adding italic text to the sample HTML file generated positive results. However, when running the generator with the SVG option enabled, the outcome remained consistent, with Chrome utilizing the WOFF file. Removing other formats from the CSS file and only referencing the SVG file caused the text to appear upright, despite Chrome still identifying it as PT Sans Narrow in italic form.

Upon reviewing your jsfiddle, I noticed that both the SVG and WOFF files are being loaded, although displayed as text/html content, but recognized as font files. The reason behind this behavior remains unclear and might be related to the internal workings of jsfiddle.

Answer №2

After extensive research and experimentation, I have come up with a viable alternative solution. Although the reason why webkit browsers do not use faux-italics still eludes me, I managed to replicate faux-italics through a combination of CSS and jQuery. Here is the HTML code that I intend to apply this method to:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. <i>Fusce aliquam
mollis pulvinar. In tincidunt, libero vel auctor scelerisque, ligula erat
tempus neque, eu ultrices justo erat a risus.</i> Nulla facilisi. Praesent
porttitor magna sed ultricies lacinia.

Firstly, I need to enclose each word in a span with the class italic. The rationale behind this approach will be explained shortly. I employ the following jQuery script to accomplish this:

$(document).ready(function(){
    $("i").each(function(){
        $element = $(this);

        var words = $element.text().split(" ");
        $element.empty();

        $.each(words, function(i, v) {
            $element.append($("<span class='italic'>").text(v));
            $element.append(" ");
        });
    });

    $("em").each(function(){
        $element = $(this);

        var words = $element.text().split(" ");
        $element.empty();

        $.each(words, function(i, v) {
            $element.append($("<span class='italic'>").text(v));
            $element.append(" ");
        });
    });
});

Subsequently, by utilizing CSS3, I can slant the text by 10 degrees specifically for webkit browsers:

span.italic{
    display:inline-block;
    -webkit-transform:skewX(-10deg);
}

This brings me to the necessity of enclosing each word in its own span. In order for this technique to be effective, the display property must be set to inline-block; therefore, if the italicized phrase spans multiple lines, it may not wrap correctly within a paragraph unless each word has an individual span.


Drawbacks

One potential drawback of this method is that if webkit browsers eventually start supporting faux-italics, the text may appear excessively angled. Additionally, this approach only functions with <i> and <em> tags, excluding all other italicized content. Lastly, any images or additional formatting enclosed within the <i> tag are stripped away.

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

What strategies can be implemented to increase the number of backlinks?

<script type="text/javascript"> $(document).ready(function() { var linkas = $("#button").attr("value"); $('#button').click(function(){ $.get(linkas, function(data){ $(' ...

set ajax url dynamically according to the selected option value

My form features a select box with three distinct choices <select id="tool" name="tool"> <option value="option1">Option1</option> <option value="option2">Option2</option> <option value="option3">Option3</ ...

Angular 2's Multi-select dropdown feature allows users to select multiple options

Recently, I encountered an issue with customizing CSS for angular2-multiselect-dropdown. I found the solution in this link: https://www.npmjs.com/package/angular2-multiselect-dropdown. I have included my code below. Any assistance in resolving this matter ...

Establishing the rotation attribute of an SVG circle to create an angular progress tracker

Exploring the code of an Angular component and came across how the r attribute for an svg circle is defined like this: [attr.r]="radius - stroke / 2" This seems to work, but I'm wondering why it's done this way. Isn't the r attribute suppo ...

How to make text dynamically shrink with TailwindCSS class 'flex-shrink-0'

I've designed an 'Album' (React) component to showcase album artwork, name, and release date in a card-like format. This component consists of two divs - one for the photo and the other for text. Each artist's discography displays multi ...

Why is my client program not receiving a response from this socket.io server?

Currently, I am in the process of developing a trivia game where two users engage in answering questions with the winner being declared at the end. As part of this project, I have integrated socket.io to facilitate the exchange of answers. However, I have ...

Positioning a div absolutely within a targeted div

Is there a way to set a div as absolute within a specific relative div rather than just the parent? For instance, I have a div that's nested inside of a row. However, I would like it to be positioned absolutely in the section instead of the row. Both ...

`problem with moment.js incorrectly identifying the day of a given date`

I'm currently working with a field that has the value 03-01-2020, which is in the DD-MM-YYYY date format. However, when I apply the code moment.utc(document.getElementById('date').value, "DD-MM-YYYY HH:mm:ss").toDate(), I noticed that the re ...

Steps to Create an HTML Text Box that cannot be clicked

Does anyone know of a way to prevent a text box from being clicked without disabling it or blocking mouse hover events? I can't disable the text box because that would interfere with my jQuery tool tips, and blocking mouse hover events is not an opti ...

What is the best way to create a highlighted navigation bar using Angular 2?

Is there a way to keep the navbar active even after refreshing the page in Angular 2? I am currently using CSS to accomplish this, but the active tab is removed upon page refresh. Any suggestions on how to tackle this? HTML:-- <ul class="nav navbar- ...

Instructions for passing a single value from a while loop and showing a different value in a text box through PHP

Can one value be displayed while sending another value in an Input text field simultaneously? I have a form that displays details in descending order, but when I update the details from another page, they are being updated in ascending order instead. Cod ...

Shifting Transition for Customer Reviews

I am working on implementing a testimonial slider on my webpage located at . I am trying to make it automatically slide by itself, but have been unsuccessful so far. I would appreciate if you could visit the demo page on my website and help identify what ...

Unable to display image on HTML page transmitted via socket in Java

After successfully loading my simple HTML in Chrome and seeing it display correctly, I encountered a troubling issue when trying to pass it through a Java socket. Despite only passing bytes through the socket, the image always appears broken. The perplexin ...

The <select> element is experiencing compatibility issues with the camera controls in ThreeJs

I have been developing a ThreeJs application that includes a dropdown menu for user selections, resulting in changes to the displayed objects. However, I have encountered an issue where using the html select tag with camera controls (such as Trackball or ...

Implement the CSS display flex property for more flexible layouts

After working on some HTML code, I found the following: <section class = "personal_proyects"> <article> <div class = "personal_details"> <h3>Canal YT: Codigo RM</h3> < ...

JQuery not properly validating inputs with required attributes after creation

I am currently developing a contact form that includes an "alternative address" <div id='alt'> with toggleable visibility. Inside this div, there is a required <input> field. I encountered an issue where toggling #alt twice (thus hidi ...

Alternative background for browsers that do not have support for border-image styling

I am experimenting with CSS3 border-image to create a simple button design: the left slice of the image is intended to be the left border of the text, the right slice as the right border, and the middle slice should either repeat or stretch as a background ...

CSS - Desiring a border with three layers

Here is the CSS code I am using: border: 2px solid #00ff60; outline: 1px solid #000; outline-offset: 0px; This is how it looks: https://i.sstatic.net/SuvU1.png Is there a way to modify it so that it includes an inner black border, similar to the one at ...

Retrieve the value of the textarea only if it exceeds 15 characters

Could you please explain why in this example: <div id="comment-form"> <h3>Comment on this story:</h3> <form method="post" id="story-comment-form" action="#"> <textarea name="comment" id="story-comment-text"></textarea& ...

Executing a snippet of Bootstrap 5 code under specific circumstances

I need to execute different code blocks based on the window width. When the width is 500px or more, I want to run a specific block of code, and when it's 499px or less, I need another block of code to run. How can I achieve this? For widths of 500px ...