What could be causing my line-clamp to malfunction when using a fixed height in the Safari browser?

I have a problem with the design of my episode list on mobile devices. The list has a fixed height, and I am using the line-clamp-2 property for the episode titles that exceed two lines.

While everything looks fine on my PC and even when using Dev Tools to simulate different device views, I encounter an issue when I view the page on my actual iPhone 7. The layout does not display as expected, even though it appeared correctly during development on my PC.

To style the episode items, I set a fixed height of 70px with 12px padding on the sides and 0.25rem padding on the top and bottom. I also tried various solutions, including applying overflow-hidden and line-clamp directly to the div element instead of the p tag, but the problem persists on mobile.

I am using TailwindCSS to style my React component. Here is a snippet of my code:

<div className="lg:h-[calc(100vh-60px)] overflow-y-scroll bg-[#222] h-[30vh] max-lg:mb-[20px]">
    {listEpisode.map((item, i) => (
        <Link
            to={`episode-url`}
            key={i}
            className="w-full h-[70px] px-[12px] leading-normal
            py-1 hover:text-white hover:opacity-80 hover:bg-white/20
            duration-200 ease-in-out line-clamp-2 overflow-hidden
            odd:bg-[#111111] even:bg-[#272727]"
        >
            <p className="inline after:whitespace-pre">
                {item.title}
            </p>
        </Link>
    ))}
</div>

In Dev Tools on Chrome, the layout appears correctly when set to iPhone 6/7/8 viewport size (which matches my physical device). However, when viewing the page on Safari on my iPhone 7, the layout is not as expected:

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

I am struggling to identify the cause of this issue and find a solution to fix it, especially since the design was working fine on my PC.

Answer №1

I've found a solution by making some adjustments to my CSS styling.

I modified the styling of my a tag by setting it to display as flex with a fixed height of 80px, along with padding and margin properties. The a tag acts as the parent element, containing a div that wraps around the p tag. The div doesn't have a set height, allowing it to adjust its height automatically. Within this div, which now acts as a paragraph, I applied the line-clamp-2 property.

On my device, the result looks satisfactory, with no issues on PC.

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

It's worth noting that I included two div elements inside the a tag to better suit my preferences. While this extra step may not be necessary for everyone, it might provide some inspiration for those facing similar challenges.

Below is the Tailwind CSS code I used:

<div className="lg:h-[calc(100vh-60px)] overflow-y-scroll bg-[#222] h-[30vh] max-lg:mb-[20px]">
    {listEpisode.map((item, i) => (
        <Link
            to={`episode-url`}
            key={i}
            className="flex items-center h-[80px]
            px-[12px] py-[8px] w-full hover:text-white 
            hover:opacity-80 hover:bg-white/20 duration-200 ease-in-out"
        >
            <div className="mr-[6px] h-full flex items-center justify-center text-amber-400 ">
                <p className="font-extrabold px-[4px] border-r-[2px] opacity-80">
                    {i+1}
                </p>
            </div>
            <div className="mx-[6px] w-full flex">
                <p className="line-clamp-2 w-full text-[#E2DFD2]">
                    {item.title}
                </p>
            </div>
        </Link>
    ))}
</div>

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

Tips for extracting DEX using dex wireless adapter on iOS CoreBluetooth technology?

Currently, I am using a DEX BLE-1 adapter from Honeywell to extract dex data from vending machines. In my iOS app developed in Swift 3, I utilize CoreBluetooth for scanning and pairing with the peripheral device. The adapter comprises three services: seria ...

Finding a predecessor with Selenide through tag and class identification

Trying to find the ancestor element using Selenide library on a website. The ancestor element is <div class="BorderGrid-cell" ...>. The .closest(".BorderGrid-cell") method works well. However, the .closest("div.BorderGrid-ce ...

"Encountering an issue with the live preview feature in Br

Currently, I am working on a project offline and trying to make Brackets' live preview feature work smoothly. It has proven to be quite convenient for my tasks. While opening my project files using the "open file" option in Brackets, I encountered an ...

Changing the Div Class in Master page from a Child page is a straightforward process that involves modifying

I am trying to dynamically change the style of a div element in the master page from my child page. This is the code I am using: protected void ShowMsgText(int MsgID) { HtmlGenericControl MsgInner; MsgInner = ((HtmlGenericControl) ...

Configuring the color of the active page link in the navbar using Python Flask

In order to highlight the current page that the user is on, I want the link of the current page to have a different color compared to the other page links. This will help the user easily identify which page they are currently viewing. I am implementing thi ...

Display images stored in a UIImageView within a TableView on a separate ViewController

Any assistance would be greatly appreciated! Currently, I am working with a table view sourced from an iOS table view of 2014 world cup countries by groups The following is the code snippet from the sidebarviewcontroller: - (void)viewDidLoad [super vie ...

Unable to transmit a variety of text or variables via email through PHP

Can someone assist me in figuring out how to send more content in an email? I have been attempting to include additional information in the email, but haven't been successful. I am using ajax to call and send the email, however, only basic emails seem ...

What is the best way to create a sticky/fixed navbar that conceals the div above it while scrolling on the page?

When I am at the top of the page, I want to display the phone number and email above the navigation bar. However, as soon as I start scrolling down, I want the phone number and email to disappear and only show the navigation bar. I have attempted using fix ...

What strategies can I use to make my div content more adaptable to different screen sizes and

Currently, in my project, I have implemented a layout using the top nav menu (purple part) and the left menu (pink part) as shown in the image. However, I am facing an issue where, upon deleting some content from the view, the pink menu on the left extends ...

Background Patterns on Webpages

My website has a lovely gradient background on the html tag in css, while the body tag showcases a seamless pattern repeating on both the x and y axes. Everything was looking great until I checked the website on an iPad/iPhone in portrait mode, where the ...

What is the best way to conceal padding designated for invisible scrollbars?

I am facing a perplexing problem with a nav element that always shows an empty scrollbar area, even when it is not required. Here is how it looks with all content displayed: https://i.stack.imgur.com/PzeiP.png This is how it appears when the window heigh ...

Issue with Angular 6: Animation with LESS is failing to work post deployment

Hello everyone, I'm facing an issue with my LESS animation. When I deploy my app on the server after using ng build --prod, the CSS animations are not visible in browsers. They work perfectly fine on localhost but fail to work after deployment and I c ...

I seem to be having an issue with the decimal point on my calculator - I only want to see one dot

Only need one dot for the calculator to function properly. The current situation with multiple dots is causing confusion. I intend to address other aspects of the code later, but I'm currently struggling with this issue. function dec(d) { let ...

Tips for altering the design of a registration page

I'm struggling to modify my registration page layout so that the avatar is positioned on the left while the username, password input boxes are on the right. I attempted to use split divs without success and also tried adjusting the positioning of the ...

drawImage - Maintain scale while resizing

I am currently working on resizing an image using drawImage while maintaining the scale. Here is what I have so far... window.onload = function() { var c = document.getElementById("myCanvas"); var ctx = c.getContext(" ...

AngularJS: Showcase HTML code within ng-view along with its corresponding output displayed in a navigation format such as Html, Css, JS, and Result

Currently, I am working on a web application. One of the screens, screen-1, consists of a series of buttons labeled 'Code'. When a user clicks on any of these buttons, it loads a different HTML page, screen-2, in the ng-view using $location.path( ...

Ways to customize hover color of Bootstrap 5 Dropdown menu

I'm having trouble modifying the hover color for a dropdown menu using Bootstrap 5. I'm unsure of the correct method to achieve this. The desired outcome is as follows: However, at the moment it appears like this: Apologies for the oversight, h ...

When CSS animations are used on numerous elements, it can lead to variations in the speed of

I made an animation to move elements from the top to the bottom of a page. I have 4 objects with this animation applied, but for some reason, they are moving at different speeds. It's confusing me. What could be causing this inconsistency? body { ...

The functionality of Bootstrap styles is not compatible with Code Igniter

I tried placing the bootstrap folder in the root folder and loading the styles in the header section of view files like this. Unfortunately, it didn't work as expected. Can someone please assist me in solving this issue? <link href="<?php e ...

Interactive HTML/CSS Periodic Table with Dynamic Design

Recently, I have been immersing myself in learning about responsive design in HTML/CSS and decided to challenge myself by coding the periodic table of elements using HTML/CSS to hone my skills. While I have set up the basic structure of the table with div ...