Issues with the functionality of the :before and :after pseudo-elements in IOS devices

Struggling to make the border-dashing effect work on iOS devices using :after and :before. It's functioning properly on desktop and Android, but not displaying text on iOS.

Here is a demo of other devices:

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

And here is a demo of iOS devices:

https://i.sstatic.net/1vire.png

h2.service-heading {
  font-size: 36px;
  color: #762d2f;
  text-transform: uppercase;
  position: relative;
  display: table;
  margin-left: auto;
  margin-right: auto;
  max-width: calc(100% - 36px);
  position: relative;
}

h2.service-heading::after {
  content: '';
  position: absolute;
  width: calc(100% - 5px);
  display: block;
  height: 6px;
  border-bottom: 6px solid #762d2f;
  z-index: 9999;
  clear: both;
  left: 0;
  bottom: 0px;
}

h2.service-heading::before {
  content: '';
  position: absolute;
  width: 10px;
  display: block;
  height: 6px;
  border-bottom: 6px solid #762d2f;
  z-index: 9999;
  clear: both;
  bottom: 0px;
  right: -10px
}
<h2 class="service-heading" align="center"> Our Services</h2>

If you have any insights on resolving this issue, I would greatly appreciate it. Thank you in advance!

Answer №1

Using a pseudo-element is not necessary for this. You can achieve the desired effect with just a background.

h2.service-heading {
  font-size: 36px;
  color: #762d2f;
  text-transform: uppercase;
  display: table;
  margin-left: auto;
  margin-right: auto;
  max-width: calc(100% - 36px);
  padding-right: 15px;
  background: linear-gradient(#762d2f, #762d2f)  0 100% / calc(100% - 15px) 6px no-repeat,
              linear-gradient(#762d2f, #762d2f) 100% 100% / 10px 6px no-repeat;
}
<h2 class="service-heading" align="center"> Our Services</h2>

You can also leverage CSS variables to easily manage the styling.

h2.service-heading {
  --border-height: 6px;
  --second-border-width: 20px;
  --border-gap: 10px;
  font-size: 36px;
  color: #762d2f;
  text-transform: uppercase;
  display: table;
  margin-left: auto;
  margin-right: auto;
  max-width: calc(100% - 36px);
  padding-bottom: 5px; /* bottom distance of border */
  padding-right: calc(var(--second-border-width) + var(--border-gap));
  background: linear-gradient(#762d2f, #762d2f)  0 100% / calc(100% - (var(--second-border-width) + var(--border-gap))) var(--border-height) no-repeat,
              linear-gradient(#762d2f, #762d2f) 100% 100% / var(--second-border-width) var(--border-height) no-repeat;
}
<h2 class="service-heading" align="center"> Our Services</h2>

Answer №2

Encountering a similar issue, I faced a problem where the dropdown arrow for a menu item acting as a pseudoclass ::after was not functioning properly on IOS. See image here

To resolve this, I adjusted the SASS code snippet as follows:

.nav-link {
      border-top: 1px solid var(--color-white);
      color: var(--color-white);
      font-size: 18px;
      line-height: 22px;
      font-weight: 400;
      text-decoration: none;
      padding: 10px 15px 10px 0;

      &::after {
        content: " ";
        border: none;
        background-image: var(--arrow-down);
        background-position: center center;
        background-repeat: no-repeat;
        width: 40px;
        height: 20px;
      }
  }

The solution involved removing the arrows from the pseudoclass ::after and setting them as a background image for the menu item, like so:

.nav-link {
      display: block;
      border-top: 1px solid var(--color-white);
      color: var(--color-white);
      font-size: 18px;
      line-height: 22px;
      font-weight: 400;
      text-decoration: none;
      padding: 10px 15px 10px 0;
      background-image: var(--arrow-down);
      background-position: 98%;
      background-repeat: no-repeat;
      background: var(--arrow-down) no-repeat 98%;

      &::after {
        display: none;
      }
}

An observation made was that older versions of IOS such as IOS14.4 and below do not fully support background-image, requiring the use of the full form 'background' instead of just 'background-image':

background: var(--arrow-down) no-repeat 98%;

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

Transferring information from an HTML form to PHP

Attempting to transfer information from HTML to PHP. The following is the code in my HTML file: <div class="content"> <form action="email-script.php" method="post"> <div class="contact-form mar-top30"> <label> < ...

Updating the CSS link href in ASP.NET using code behind

I'm struggling with changing the CSS href in the code-behind of my .ASPX page. I've tried various methods but haven't found a solution that works as intended. HTML Markup: <link id="linkCSS" runat="server" href='/css/1.css' re ...

Searching within an iFrame for an element using the getElementById method

Hey, I'm working with an iframe and trying to reference a CSS element that is located on the source page. Here's the iframe code: <iframe id="CPHNavBar_TBDC081D1008_frameSticky" src="/stickyserviceavailabilitycheck"></iframe> I want ...

Establishing the footer within dompdf

This snippet demonstrates the specified behavior (jsfiddle). <!--Footer--> <div id="footer"> <span class="alignleft">$unique_ID</span> <span class="alignright"> Page <span class="pagenum"></span></span> < ...

The link in the navbar isn't functioning properly, which indicates that it's not redirecting to the specified ID on this one-page application

<!-- NAVBAR --> <nav class="navbar navbar-expand-lg py-3 sticky-top navbar-light bg-white"> <div class="container-fluid"> <a class="navbar-brand" href="#acasa"> <img class="logo" src="./assets/img/xxxxx_psiholog_logo. ...

What is the best way to align all of my content to the center in HTML?

In my web design class, I encountered an issue while creating a page. Currently, my page consists of a navigation bar and an image. I wanted to center both elements using CSS. display: block; margin-left: auto; margin-right: auto I applied this CSS to th ...

Padding causing links to break exclusively in Firefox

As a seasoned front-end developer, I recently encountered an issue that has stumped me. My main navigation bar has extensive right padding to ensure the hover dropdowns have ample space. The problem seems to be in this piece of code: HTML: <div id="h ...

I am seeking a way to conceal list elements according to a specified string input using JavaScript

Looking at the list items inside this div: <div class="container"> <h2>Vanishing Act Game</h2> <div> <li class="list-group-item go" id="item">Door#1</li> <li class="list-group-item go" id="it ...

I'm looking for a more efficient and meaningful method to showcase the items from my database in my store that will allow me to easily categorize and organize them in the future

As a beginner, I know it's not recommended to echo HTML code, but I haven't found a better way yet. Currently, I allow the user to change the SQL query to sort items, even though this leaves me vulnerable to SQL injections. I'm open to new s ...

Clicking again on the second onclick attribute

I have an image file named image1.png. When the button is clicked for the first time, I want it to change to image2.png. Then, when the button is clicked for a second time, I want it to change to yet another image, image3.png. So far, I've successful ...

Having trouble retrieving an HTML page using Node.js

I successfully displayed the home page index.html, however, the pages I want to open as links are not being displayed. Below is the code I used to display index.html: app.get('/', function(req, res){ res.sendFile(path.join(__dirname+'/ ...

Is there a way to position the image at the exact center of the column?

Currently, I am attempting to design a container that includes an image on the left, a title and description in the center, and a button on the right. However, I am facing difficulties centering the image in the first column and the button in the last colu ...

The ion-datetime in Ionic 4 ensures that the floating label always remains visible, even when the input

When an ion-datetime field in Ionic 4 has no value, the label always floats as shown below. Here is my code snippet: <form [formGroup]="statusHandlerForm"> <ion-item class="input-container " align-items-center no-padding> <ion-la ...

Troubleshooting a problem with the Bootstrap dropdown menu

Can anyone assist with an issue regarding Bootstrap 4.4.1? I am facing a problem where two consecutive dropdown links+menus are not displaying correctly. The second dropdown menu is showing the content of the previous link instead of its own, even though t ...

Troubleshooting Paths with Angular's NgFor Directive

Within my Angular project, I have implemented a basic ngFor loop to display logo images. Here is a snippet of the code: <div *ngFor="let item of list" class="logo-wrapper"> <div class="customer-logo"> & ...

Embed Text inside an HTML Canvas

As someone who is relatively new to working with html canvas, I am having a bit of trouble when it comes to containing text within the canvas area. Specifically, I am pulling text from a textarea and displaying it on the canvas, but it seems to stay as one ...

Ionic 5 experiences issues with loading customized SCCS components

I recently crafted a personalized feature in ionic 5, following these steps: Step 1: Initiate the component using ionic g component components/FlashCard Step 2: Develop a module for this specific component. Use ionic g module components/FlashCard Step 3 ...

Exploring the potential of HTML5, Canvas, and the FireFox

There are a few inquiries I have about the HTML5-Canvas code provided below. The text is not visible in Firefox 3.6 (though it shows up on Chrome.) In regards to the ctx variable (ctx = c.getContext("2d")), should this variable be reutilized multiple ...

The surprising way Next.js disabled the production build and transformed my rgba color into hsla

I created CSS code to display grid patterns like this: background-image { repeating-linear-gradient( 0deg, rgba(255, 255, 255, 0.43) 0px 1px, transparent 1px 20px ), repeating-linear-gradient( 90deg, rgba(255, 255, 255, 0.43) 0px 1px, transparent 1px 20 ...

Utilizing a for loop to add div elements

I have a HTML form in my code where the user fills out information, including entering a value in the "member" field and clicking a button to generate additional copies of the 'sector_prop' div. The form section is - Number of Sectors (L ...