The effectiveness of the javascript widget is hindered by the absence of the meta viewport tag,

As I work on creating a widget to appear at the bottom of webpages, I've encountered a styling issue. The widget's display varies based on whether the webpage includes a specified meta viewport tag or not.

<meta name="viewport" content="width=device-width, initial-scale=1">

Websites with the viewport tag look good, but those without it make the widget appear very small. To add to this complexity, I use .em for font sizes.

Here's a snippet from my style.css file:

.mywidget li a{
   color:#304FFE;
   font-size:2.0em;
}

I aim for my widget's style to seamlessly adapt to mobile responsive and non-responsive pages alike. Seeking expert advice on how to achieve this effectively!

Speaking of successful implementation, companies like Zopim handle this flawlessly!

Zopim's chat button maintains its impeccable appearance even on non-mobile optimized websites. It remains constant in size and placement, regardless of zoom level. Your customers can easily connect with you via a consistent chat button experience.

Current Approach (Room for Improvement - open to suggestions)

I resort to using CSS3 media queries by checking if a viewport meta tag is present. If not, I load a specific CSS file with corresponding media queries.

var viewport = document.querySelector("meta[name=viewport]");
if(viewport === null){
      //create my media css element
}

In these media queries, I adjust the font size by a few em units. For instance:

@media only screen and (min-width : 320px) {
 .mywidget li a {
    font-size: 3.5em!important;
  }  

}

The challenge with this method is determining the precise increase in em units needed. I strive for consistency across both mobile responsive and non-responsive pages. Any insights or tips are highly valued!

Answer №1

To maintain the current appearance without any alterations, you can specify px as the unit in font-size. I recently explored the zopimchat widget, which seems to be the element mentioned on their website.

The text "We're online" utilizes font-size with a value of 18px;, while the input text has a font-size set at 12px;.

I inspected both measurements using Chrome DevTools.

If you must utilize ems, it is beneficial to refer to MDN's explanation (link provides detailed information):
An em value adjusts dynamically. In defining the font-size property, an em equals the size of the font inherited from the parent element. If no font size is specified on the page, it defaults to 16px by most browsers.

Hence, if you do not define the font-size within .mywidget, the appearance will rely on the webpage calling your widget. Setting it there means li a will inherit from .mywidget providing some control, but necessitating a fixed value once again brings you back to pixels rather than ems, albeit in a different context.

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

Unable to transfer the component between components

This is the code I have: index.js: import React from "react"; import ReactDOM from "react-dom"; import {dest, People} from './components/people'; import json from './people.json'; function initFromJson() { let names = []; for(let ...

Symfony: Implementing real-time updating of values through ajax requests

My goal is to update the values of a table using Ajax in Symfony. The operation involves clicking on an update button, which retrieves the ID of the selected row and the new value of the updated attribute. Here is my Twig file: <tbody> {% for ...

Unable to locate image files stored in vendor/images in the Rails 4 view

I have successfully set up a custom bootstrap theme with Rails 4, and placed the image file here: /vendor/assets/images/custom_bootstrap_theme/demo/bg01.jpg The index.html.erb file is referencing this image as follows: <img src="/vendor/assets/image ...

The color of the navbar-toggler-icon in Bootstrap cannot be altered

While working on customizing my Bootstrap 5 navbar, I encountered an issue with changing the color of the navbar-toggler-icon. The preset colors, navbar-light and navbar-dark, didn't align with my theme, so I attempted to change the color to pure whit ...

javascript include new attribute adjustment

I am working with this JavaScript code snippet: <script> $('.tile').on('click', function () { $(".tile").addClass("flipOutX"); setTimeout(function(){ $(".tile-group.main").css({ marginLeft:"-40px", widt ...

Allow iframe to be edited within jsfiddle

I have a question that I need to ask soon, but first I need an editable iframe in jsfiddle. It's working fine on my local machine, but not on jsfiddle. I believe it's because of the frames being used? On my local machine, I use: setTimeout(&apo ...

Issue with Jquery animation persists: mouse cursor does not change and style remains unchanged even after clicking

I have encountered an issue with JQuery animation on Chrome. According to the requirements, I need to animate a div when a link is clicked. When the cursor hovers over the link, it should be underlined and change to a pointer. However, even after clickin ...

Show or hide a div through two variables that toggle between different states

It's possible that I'm not fully awake, so missing the obvious is a possibility. However, I have 2 variables that determine whether a div has a specific class or not. The class functions more like a toggle; so the following conditions should tri ...

What is the best way to bring a module into an Angular project?

I have a project in Angular with an additional module created as an npm package. The structure of the module is as follows: --otherModule --other-module.module.ts --index.ts --package.json index.ts: export { OtherModule } from './other-module ...

Generating HTML within controller actions

I am struggling to make a decision on whether it is acceptable to generate HTML in controller actions and return this HTML to AJAX calls from my view using jQuery. For example, when choosing a client through jQuery Autocomplete, in addition to retrieving ...

Flex Item will only respect the margin or padding when both are set simultaneously

I've been playing around with CSS and running into a problem where a flexbox item isn't respecting margin and padding correctly, causing the right side to have no margin. Here's a simplified example I came up with: <body> <div c ...

`CSS animation for vanishing line effect`

I want to create an animated logo that gives the illusion of being pulled up by a rope, represented by a vertical black line, from the bottom of the page to the top. As the logo moves upwards, I would like the rope to disappear behind it, but I'm uns ...

What is the best way to resume a paused animation using JavaScript?

My first game involves triggering an animation that transitions the game screen to greyscale when the character dies. Despite my efforts, I have been unable to successfully trigger this animation using document.getElementById("object").animationP ...

The form within the while loop is only functioning with the initial result

Within a while loop, I have a form that is being processed with ajax. The issue is that it only works on the first form and not on the others. Can someone take a look? <?php while($a = $stmt->fetch()){ ?> <form method="post" action=""> ...

What is the process of integrating data from the OpenWeatherMap API into the WindowInfo feature of Google Maps?

My current project involves retrieving weather information from the openweathermap API and displaying it in an infowindow on Google Maps. However, there seems to be an issue where I am getting data from the previous marker instead of the current one. var ...

Issue with EJS template displaying no information

I am encountering an issue with ejs templates. While I have successfully used it in a previous project, in my current one, it's not working as intended. Instead of rendering the cards with the passed data, all I see is a blank page. Here is my code fo ...

Pan motion gesture above HTML components

Is it possible to create a hovering effect over elements in a container using a pan gesture? Here's the HTML code: <div class="container"> <div class="item"></div> <div class="item"></div> <div class="item">< ...

What is the best way to display a selected checkbox in an AJAX editing modal?

Can someone assist me in loading the checked checkboxes in an edit modal? I am using checkboxes to assign multiple roles in my system. Everything was working fine, but I encountered an issue with my edit modal where the checkboxes appear blank and unchecke ...

Tips for generating automatic views in Backbone without manual instantiation

Is there a more efficient way to instantiate the view rather than directly below the definition? var BVApp = Backbone.View.extend({ Name: 'BVApp', // do chonka stuff }); $A.Class.add(new BVApp()); ...

The final position of the Angular increment animation does not hold

Is there a way to trigger an animation when the value of countAllOrders changes? Specifically, I am attempting to adjust the margin of a list using keyframes in an Angular animation. Here is my HTML code: <ul class="digits" [@ordersValue]=&q ...