Debugging a UI on mobile devices is made easier if we can highlight the elements which cause horizontal scrolling - this can be done easily enough with the following line of CSS, which uses the universal selector:
* { border: 1px solid #f00 !important; }
Works nice, but to turn it on and off we need to recompile sass, or step outside of our defined process... or find a nice JS solution.
We have a handy BootStrap breakpoint viewer and it makes sense to add a click action to this to apply the CSS rule - On / Off, so we can save some time and give a good UX to the UI developers..
So, first goes are not working well, we can't use addClass
and then removeClass
as the selector is not named..
Also, we've tried a few variants of the following to apply to css rule globally, but they are not working yet:
// click to add debug borders ##
jQuery('#bs_helper').click(function(e){
// console.log( 'Clicked BS..' );
jQuery( document ).find("*").css( "border", "1px solid #f00 !important" );
});
Also, did not work with:
jQuery( "*" ).css( "border", "1px solid #f00 !important" );
Any hints? We need a single click to add and another to remove the rule.
Thanks!
UPDATE - this works, but perhaps there is a better way?
var $bs_helper_css = false;
// click to add debug borders ##
jQuery('#bs_helper').click(function(e){
if( ! $bs_helper_css ) {
var html = "<style id='bs_helper_css'>* { border: 1px solid #f00 !important; }</style>";
console.log( 'Add: '+html );
jQuery('body').append(html);
// tracker ##
$bs_helper_css = true;
} else {
console.log( 'Remove CSS' );
jQuery('#bs_helper_css').remove();
// tracker ##
$bs_helper_css = false;
}
return true;
});