Can you identify the factor that is altering the dimensions of this specific "span"?

My webpage features both English and Portuguese languages, which can be switched by clicking a flag at the top of the page. This language swap is achieved through a class in a span. Here's an example:

  <div>
  <span class="por1">Portuguese text 1</span>
  <span class="eng1">English text 2</span>
  Some text 3 that is correct in both languages
  </div>

Initially, in CSS (where English is set as the default language):

  .por1 { display: none }
  .eng1 { display: inline-block }

Upon clicking the flag, the languages are swapped using JavaScript.

This functionality works flawlessly on desktops without errors in W3C validation, but when it comes to mobile devices only, the texts within both spans appear smaller than text 3. Despite removing all @media, the issue persists.

If I remove the two CSS lines - .por1 and .eng1, both texts 1 and 2 show up simultaneously with the correct size. It seems like the problem is related to the display property...?

Interestingly, there appears to be a behavior where the two spans .por1 and .eng1 have CSS for mobile devices even though they do not exist in the code. In fact, debugging in Chrome reveals that the two spans do not have any special formatting applied to them.

Here is the page. Give it a look on a smartphone to see the difference in text sizes in the title already.

EDIT I have simplified the page to its maximum state. Now, take a look at the complete code including CSS:

<!DOCTYPE html>
<html>
<head>
<title>Crazy</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<style type="text/css">
 body { font-size: 24px; }
 .por1 { display: none }
 .eng1 { display: inline-block }
 h2 { font-size: 2em; }
 h3 { font-size: 1.7em; }
</style>
</head>

<body>
<h2> <span class="por1">Borboletas e Mariposas</span><span class="eng1">Butterflies and Moths</span> <br> (Rhopalocera, Heterocera) </h2>

<h3> oplus <span class="por1">Borboletas     </span><span class="eng1">Butterflies  </span> (Papilionoidea) </h3>

<div class="inner"><span class="por1">asa-de-vidro   </span><span class="eng1">Glasswing    </span> (Greta sp.)</div>
<div class="inner"><span class="por1">mariposa-walker</span><span class="eng1">Walker's moth</span> (Lepidoptera, Erebidae: Sosxetra grata)</div>
<div class="inner"><span class="por1">mariposa       </span><span class="eng1">herilia moth </span> (Erebidae: Letis sp. (herilia?))</div>

</body></html>

Removing the first <div class="inner"> still results in various font sizes being rendered unnaturally. However, deleting the second or third aligns the rendering correctly. Strangely, if I remove the (herilia?) from the third <div class="inner">, it displays correctly too! Similarly, eliminating the ? or oplus resolves the problem. The cause remains unclear!

EDIT 2

Check out the incorrect rendering screenshot below:

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

And here's the screenshot of the accurate rendering (select 'herilia?' removed):

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

EDIT 3 If I modify h3 { font-size: 1.7em; } to h3 { font-size: 1.5em; }, the issue disappears!

Answer №1

It appears that you are facing a common issue related to font size adjustment in webkit mobile browsers, which I have encountered before.

To prevent autosizing, I like to use the following workaround:

 div { max-height: 9999px; } 

You can apply this to either the div element or spans. Give it a try and let me know how it works for you.

Edit

In order to avoid this issue, you may also need to utilize similar techniques. The problem is likely due to incorrect viewport configuration and text sizes below 18 pixels. The browser assumes these texts are too small for users to read comfortably and consequently adjusts the size dynamically.

Answer №2

Consider setting a custom font size for your span elements

Answer №3

It seems like you are aware of how to manipulate font size using CSS, but prefer not to based on your comments.

I recommend considering adjusting the font size dynamically with JavaScript to accommodate various contexts. If you need assistance with this, feel free to reach out to us for help.

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

Utilizing PHP and JQuery Variables within the CodeIgniter Framework

Can someone please provide guidance on the best approach to handle this particular situation? I currently have a sidebar populated with Li Elements using a foreach loop, which is working perfectly. Each element contains a link that, when clicked, trigger ...

Conceal flex items when there is inadequate space available

I need help with customizing my JIRA timeline chart to show information about epics in progress. When an epic spans multiple releases, there is enough space on the timeline bar to display all relevant details. However, if an epic only spans one release, th ...

What are some techniques for utilizing CSS with form.ImageField in Django?

When attempting to apply CSS to form.ImageField in Django similar to CharField, I encountered an error. File "/Users/hogehoge/Desktop/hoge/hoge/forms.py", line 42, in PostForm photo = forms.ImageField(label='Image', validators=[fi ...

Encountered an Ajax issue while initializing a datatable on a table inside a modal dialog

I have a modal that contains a search box. When the search button is clicked, an ajax call is made to the controller to retrieve a table of results, which are then inserted into a div like this: $.ajax({ url: url, data: JSON.stringify(viewModel), ...

What is causing vertical-align:middle to not function in the same way as text-align:center?

Is there a reason why vertical-align:middle doesn't seem to work as easily as text-align:center? It's frustrating that it's so challenging to get it right. I'm curious why the folks at W3C haven't created something like text-alig ...

Click anywhere outside the sidemenu to close it

I want the menu to behave like the side menu on Medium. When the side menu is open and the user clicks outside of #sidebar-wrapper, the side menu should close. Currently, I have to click the toggle X to close the menu. html <a id="menu-toggle" href="# ...

Creating a cutting-edge Windows Phone 8 application with JavaScript on Visual Studio 2013 Ultimate, recently updated to update 2

I am trying to create a windows phone 8 app using java-script in visual studio ultimate 2013 update 2, but I cannot seem to find the option for windows phone 8. Only the option for 8.1 is available. Can someone guide me on how to develop an app for windo ...

Changing the content of a DOM element containing nested elements using JavaScript/jQuery

Need some help with a DOM element that looks like this: <span>text</span> <b>some more text</b> even more text here <div>maybe some text here</div> How can I replace text with candy to achieve this result: <span> ...

Is there a way to set a specific table height in Internet Explorer

Exploring a new challenge, I find myself in need of setting a fixed height on a table while allowing the rest of the content to scroll over. This is an uncommon task for me as tables are not usually my go-to element. Check out this working demo in Chrome ...

Parsing HTML that necessitates JavaScript using Objective-C

I have encountered a situation where I need to extract data from the HTML of a website. However, the website's content is being blocked by JavaScript. Upon inspecting the string output, it appears that the HTML content is not as expected. The incor ...

Possible rephrased version: "Solution for sticky positioning that behaves like it

Currently, I am in the process of developing a sample website for a potential client. Although I have successfully implemented this feature before, I am facing challenges in replicating it now. The structure I am working on comprises of a title div (appear ...

Unique rephrased text: "Varied wrapping styles in both

Feeling frustrated with a seemingly commonplace issue. Despite the thousands of times it has been asked before, I can't seem to find an answer on Google. I wanted to neatly display my text within one of my cards, but so far I've only achieved th ...

The information in the table quickly appears in its raw format before being formatted and enhanced by jquery DataTables

I have encountered an issue where table data loads briefly and unformatted before jquery DataTables kicks in. After doing some research, I found that many suggest hiding the table using CSS and then showing it using jQuery with initComplete. However, des ...

Tips for changing the color of a button link upon hover, without having to directly hover over the link

When I hover directly over the link, it changes color. However, when I hover over the button and not the link itself, the color does not change. btn:hover{ color: black; } The above code is not working as intended. a:hover{ color:black } Currently, th ...

Tips for incorporating fading text and a CTA into your content block

I am looking to protect the full content of my blog posts and allow access only to subscribed members. I want readers to see just a glimpse of the article before it disappears, prompting them to take action with a Call to Action (CTA) like in the fading te ...

Tips for incorporating padding when an h1 title spans multiple lines

I'm facing an issue with a div that has a width of 46%. When the text in the h1 tag is too long, it gets broken into multiple lines and the left padding is not consistent. Is there a way to maintain the same left padding for the second line? To help ...

What is the best way to use JavaScript to conceal all div elements?

Can someone please provide a JavaScript solution to hide all divs on a web page without using jQuery? I am looking for a method that does not involve using the arrays that are associated with document.getElementByTag. If this is not possible, could you p ...

What causes the discrepancy in CSS behavior between local and remote websites?

My chrome extension enhances facebook chatbox with jquery autocompletion. I am trying to make the suggestion list menu horizontal by modifying the jquery-ui.css. When changing display:block to display:inline, the list becomes horizontal in a local HTML fil ...

Positioning Issue: Z-index Functionality Failing

I've been struggling to find a solution to my issue regarding a search function. Whenever I type, the search function dropdown gets hidden behind the menu bar, even after adjusting the z-index values. I've heard that z-index doesn't always ...

Unexpected behavior from Jquery

Users can select options that reveal more choices and text boxes upon clicking. Despite copying and pasting the code for all options, one specific part is not working as expected. The rest of the options function correctly. The code snippet causing issue ...