App style in pure CSS3 breaks while running on Android

Asked

Viewed 404 times

4

I’m making an app with Cordova + Sammy.js and CSS3 pure. I can make the app perfectly responsive and with all styles working on Chrome and Firefox.

It turns out that when I "build" on Ordova and open APK on Genymotion (running Android 4.4 +) 50% of styles break....

Things like container font size are not rendered in vw, some containers simply have their widths ignored and follow the default width (100% parent).

I want to know if there is any way (framework, library, engine or Preprocessor) that gives to fix the styles of the APP but allowing the same flexibility stylization of pure HTML5.

  • 1

    vw and vh are not supported by all browsers and probably webview (which in case is what is used to create the application) is not a newer version of webkit.

  • 1

    "webview (which in this case is what is used to create the application) is not a newer version of Webkit". You mean the browser Webkit I’m running the app is outdated?

  • 1

    No, I mean that CSS properties usually aren’t fully implemented as soon as they are released, even the most modern browsers don’t support everything.

  • 1

    @Guillhermenascimento, up to width?!

  • 1

    width: as %, px, pt, em are supported, vm probably not. Read my reply, have a list of supported browsers. Probably the engine of your webView is updated, but not the same version of Apple (which is much more updated) or Blink (which is also well updated).

2 answers

2


Reported: Units of measurement with View-port percentage

There are many CSS properties not yet implemented by all browsers, especially mobiles.

Some points to consider

  • It is not because a property is "thrown" that all rendering engines will be able to support it. When a new "functionality" is standardized by W3C (I believe they are currently defining CSS as well as HTML properties) all modern browsers will be able to support immediately. There are several functionalities not yet implemented and even if implemented they can cause BUGS.

  • Just because W3C has defined that a new functionality should work in a way, it does not mean that all browsers will have in their structure the "same code" that will run the process equally. What I mean by this is that many properties per rendering engine are subject to Bugs.

  • It is not because a new CSS property has been released that browsers will support in the same version as they are, that is when the support browser will be released a new version and you will have to do the "update".

  • As well as the browsers WebView uses a web engine, this engine is usually harder to update than a browser, in many cases depending on the version of the API may not even use more modern features.

This is the case for units of measures vh, vm, vmin and vmax which are probably not yet fully supported.

Note: In addition to the units of measurements, other CSS properties may not be supported and may cause problems you don’t know about (in addition to those you’ve already noticed).

Viewport measurement units support: vw, vh, vmin, Vmax

  • Internetexplorer 9+ to 11 (Partial support)
  • Firefox 34+
  • Chrome 31+
  • Safari 7.1+
  • Opera 26+
  • iOS Safari* 7.1+
  • Opera Mini* 8
  • Android Browser* 4.4+
  • Chrome for Android 40+

As the list, Android only supported view-port units in version 4.4, in other words, I believe that your application (which uses webView) will only run API Level 19 or superior.

Known bugs

  • Chrome does not support viewport drives for width border, column-gap, values of transform, box-shadow or calc()
  • Safari and iOS Safari (both 6 and 7) do not support viewport drives for width border, columns gaps, values of transform, box-shadow or calc()
  • iOS 7 Safari sets the unit value of the viewport to 0 if the page has left the page and returned after 60 seconds.
  • iOS 7 Safari recalculates widths set in vh as vw and heights defined with vw as vh, when orientation changes.
  • Internet Explorer 9 in print-mode interprets vh as pages. 30vh = 30 pages

Workaround

There is a project called Viewport Units Buggyfill™ that can help you.

Although it is a unique project to fix problems in Safari for iOS, it supports IE9+ and I believe it helps with Webkit (in your case Webview) for Android as well.

Solution with Jquery

In the Soen there is an answer with a solution that uses Jquery, example (The process is manual):

/*
 * CSS viewport units with jQuery
 * http://www.w3.org/TR/css3-values/#viewport-relative-lengths
 */
;(function( $, window ){

  var $win = $(window)
    , _css = $.fn.css;

  function viewportToPixel( val ) {
    var percent = val.match(/[\d.]+/)[0] / 100
      , unit = val.match(/[vwh]+/)[0];
    return (unit == 'vh' ? $win.height() : $win.width()) * percent +'px';
  }

  function parseProps( props ) {
    var p, prop;
    for ( p in props ) {
      prop = props[ p ];
      if ( /[vwh]$/.test( prop ) ) {
        props[ p ] = viewportToPixel( prop );
      }
    }
    return props;
  }

  $.fn.css = function( props ) {
    var self = this
      , update = function() {
          return _css.call( self, parseProps( $.extend( {}, props ) ) );
        };
    $win.resize( update ).resize();
    return update();
  };

}( jQuery, window ));

// Usage:
$('#test').css({
  height: '50vh',
  width: '50vw',
  marginTop: '25vh',
  marginLeft: '25vw',
  fontSize: '10vw'
});

$(window).resize(function() {
  $('#test').css({
    height: '50vh',
    width: '50vw',
    marginTop: '25vh',
    marginLeft: '25vw',
    fontSize: '10vw'
  });
});
#test {
  background: #ccc;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="test">test</div>

  • 1

    Is there a processor that can do a standardization? How frameworks like Topcoat, IONIC work?

  • 1

    @ropbla9 Outside the "Viewport Units Buggyfill™" I found a jquery code (quoted in the answer). Test both (one at a time). Another thing: your application has to be compiled for Androids older than 4.4? If you don’t try to compile in the Level 19 (or higher) API as I mentioned in the response. Please see that I edited the reply, please read again thank you.

  • 1

    I found something perfect for what I want > https://crosswalk-project.org.

  • 1

    @ropbla9 Good find, but note that only works "Android 4.0+".

  • Thanks again. I marked your answer as sure I live the effort and the clarifications.

  • 2

    @ropbla9 I appreciate it, but I don’t think I necessarily needed to mark mine as correct, just an up-vote would be fine. If your own answer is the right one for your problem, I think it would be good to mark it. You could add an example code of how to use the cross-wakl webView to your reply as well. Thank you.

  • soon I will edit the answer better

Show 2 more comments

1

That project provides a separate Webview for Android that contains the most up-to-date Chrome features. On it is possible to run recent Chrome Features for any Android version above 4.0.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.