Challenges with text formatting on various devices such as PCs, tablets, iPhones, and iPads in both portrait and landscape orientations

I have been experimenting with establishing a standard for font sizes in CSS, but I am facing challenges due to variations in devices and resolutions. Font sizes that work well on one device may not appear as intended on another, especially when switching between landscape and portrait modes.

To address this issue, I have begun using the rem unit to calculate my font sizes, implementing a mixin like the one below:

@mixin font-size($sizeValue: 2.4) {
    font-size: ($sizeValue * 10) + px;
    font-size: $sizeValue + rem;
}

@mixin small-size() {
    @include font-size(1.8);

    @include small-width {
        @include font-size(1.8);
    }

    @include large-width {
        @include font-size(1.8);
    }
}

While I initially thought adjusting the font size based on device resolution would solve the problem, I found that using 2.4 rem seemed to be a good fit for most PCs and laptops. However, the font appeared too small on tablets in portrait mode.

I am open to suggestions or if there is a CSS media query approach that dynamically scales font sizes across all devices. Any guidance or advice on simplifying this process would be greatly appreciated!

Answer №1

After extensive research, I discovered that any elements utilizing a retina display or similar technology require unique styling for margins, padding, width, height, font-size, and more compared to standard displays. Given the characteristics of retina displays, the solution was relatively straightforward (albeit tedious). Leveraging Sass (and bootstrap), I devised a series of mixins like the following:

@import "../../global/variables";
@import "structure";

@mixin make-font($size) {
    font-size: 1 * $size;

    @include iphone-portrait {
        font-size: 2 * $size;
    }
}

@mixin header-font {
    @include make-font($h1);
}
@mixin lead-font {
    @include make-font($lead);
}
@mixin default-font {
    @include make-font($p);
}
@mixin small-font {
    @include make-font($small);
}
@mixin font-size($size) {
    @include make-font($size);
}

The differentiation in handling fonts for iPhone screens can be observed in the code above. The mixin for iphone-portrait was sourced from , with modifications made to suit my needs.

@mixin iphone-portrait {
    @media only screen and (min-device-width : 414px) and (max-device-width : 736px) and (orientation : portrait) {
        @content;
    }

    @media only screen and (min-device-width : 320px) and (max-device-width : 568px) and (orientation : portrait) {
        @content;
    }

    @media only screen and (min-device-width : 320px) and (max-device-width : 480px) and (orientation : portrait) {
        @content;
    }
}

Additional media queries can be appended to simplify the process further. This methodology primarily focuses on fonts, though similar mixins were crafted for other design elements. For instance, consider the customization done for the navbar:

.navbar-default {
    @include make-navbar;
    @include lead-font;
    position: fixed;
    top: 0;
    width: 100%;
    background-color: $white-sky;
    color: $midnight-blue;
    margin: 0;
    border: 0;
    z-index: 1;
    box-shadow: none;
    border-radius: 0;

    @include iphone-portrait {
        @include make-navbar(2);
    }
}

The corresponding mixin for the navbar had a structure akin to this:

@mixin make-navbar($multiplyer: 1) {
    // Styles here
}

// Additional mixin for sub-height calculations

The flexibility of using a $multiplyer variable facilitates easy scaling. By adjusting the value passed to the mixin, it's possible to double or modify element sizes as needed.

This method has been successfully tested and verified. It offers adaptability for various scenarios where different scaling factors may be required.

Hoping this detailed explanation proves beneficial for others encountering similar challenges.

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

Disabling Hover effect on a particular element

Is there a way to eliminate the hover effect on my 'h3' tag (lighter grey hover effect), while keeping it as a link inside my 'a' tag? .speakers a { color: var(--clr-grey); } .speakers a:hover { color: var(--clr-lgrey); } &l ...

Unraveling the Mystery of JSON Objects in PHP

Here is the format of my JSON data : { "amount":550, "items":[ {"item_id":12334, "price": 504}, {"item_id":12335, "price":206} ] } Can someone guide me on how to properly parse this data so that I can retrieve each piece of information in in ...

How can I apply a CSS filter to achieve a blue-toned effect on an image?

Is there a way to change the color of an image to "bluescale" or "greenscale," similar to using filters in CSS? Or is it possible to use a combination of filters for this effect? filter:grayscale(100%); Thank you! I found a solution, but it may not be ...

The change() function in jQuery appears to have a glitch where it does not properly execute during the initial onclick event, but functions correctly for

Here is the button code snippet: <li class="cnt-li"> <button class="btn-container" title="Add Container" data-toggle="modal" data-target=".add-ctn-modal"> <img src="images/add.png" alt="Add Container"> </button> </li> ...

Achieve a top position in CSS layout without resorting to negative values

This may seem like a simple thing, but I'm struggling to achieve it without using negative values for padding-top. Here's how my site looks: Here is the CSS code I am using: .center { width: 1030px; margin: 0 auto; } .top-panel { backgr ...

Using jQuery to highlight the navigation menu when a specific div scrolls into view

I have implemented a side navigation consisting of circular divs. Clicking on one scrolls you to the corresponding .block div, and everything functions correctly. However, I am now curious if it is feasible to highlight the relevant .nav-item div based on ...

Tips for sending JSON information

My Android platform requires me to send a large amount of JSON data to a server. I am considering whether it would be beneficial to split the data into smaller packets or send it all at once. Additionally, I am wondering if running the sending code in a ...

Identifying the current tab using CAPSPageMenu in Objective-C

Utilizing CAPSPageMenu with two tabs, I have added a button to the right bar button item. Upon clicking this button, a view pops up with a button labeled sayHello. The challenge I am facing is determining which tab I was on when clicking the sayHello butto ...

How to position a new div within its parent element using CSS without causing the rest of the content to

I'm currently working on implementing a short pop-up feature in my web application that will appear when a user clicks on a code snippet to copy it. However, I'm facing difficulties with preventing the pop-up from causing a shift in the parent di ...

DataModel List exclusively reads the final element

In my database, I have recorded location updates with numerous x and y coordinates. The second method, readFirestore(), is responsible for reading the location data and comparing it with the favorite locations stored in the SQLite database. If a favorite l ...

Angular's browser animation feature allows for smooth slide-up animations from the bottom

I have been experimenting with creating a simple animation, and it's working, but in the opposite direction of what I intended. I want the div to open from bottom to top and close from top to bottom. Here is my animation code in Angular: animations: ...

When the parent DIV is hovered over, the image and text properties will be altered

Greetings, I am just starting out in web development and would like to seek guidance from the Stack Overflow community. Here is a link to my code: https://codepen.io/noxwon/pen/RwrmxKX My code is very basic and filled with repetitive lines. I have multip ...

Robotic Arm in Motion

GOAL: The aim of the code below is to create a robotic arm that consists of three layers (upper, lower, and middle), all connected to the base. There are four sliders provided to independently move each part except for the base which moves the entire arm. ...

The divs are intersecting each other

For some reason, when I try to add another section under the jumbotron it overlaps with the jumbotron. I have included my code below: http://www.bootply.com/IUd0GWEuAn ...

Establishing a Connection between an Android Application and a Jersey RESTful Web Service

I have successfully created a basic REST Web Service that receives three Strings from a client and stores them in a database. It's currently functioning well when accessed from a Java client application. Now, I'm interested in replicating this f ...

Are there any reliable sources for a complete list of browser CSS properties?

Is there a way to easily access a comprehensive list of CSS properties supported by specific browsers, particularly IE8? Any suggestions on where I can find this information? ...

Is it possible to save and retrieve recorded phone calls as audio files in a database?

What is the required format for saving audio files in an SQLite database? ...

Achieving successful implementation of MVVM in Android for effective unit testing of the application

After looking through numerous tutorials on Android data binding, I am still feeling confused about how to properly utilize it. The more tutorials I read, the more overwhelmed I become as each one has its own approach to implementation. Some sources advi ...

How to include a listview in the footer navbar using jQuery Mobile

Is there a way to include areas instead of links in the footer navbar, and then incorporate a list view within one of those areas? The navbar only seems to accept anchors, not divs, and the styling of the list view is not displaying correctly in the provid ...

JavaScript does not function properly with dynamically loaded content

Trying to load the page content using the JQuery load() method. See below for the code snippet: $(window).ready(function() { $('#content').load('views/login.html'); }); .mdl-layout { align-items: center; justify-content: center ...