padding-right on :first-line using CSS - html

I was reading through MDN's page for history.pushState() on my phone and noticed what I thought was a textual error: there should be a comma after the [ in the final argument of the syntax.
I went to edit the page, and discovered the comma does exist; it's hidden by the 📋 Copy to Clipboard button. (Oddly, despite white-space: pre, Chrome iOS treats it like pre-wrap, while Chrome desktop does not.)
The ideal solution for this (barring a fix to Chrome iOS) would be a CSS style that sets the padding-right of the first line.
#media screen and (max-width: /* ... */) {
/* or some other way to determine we're in a mobile browser */
.code-example pre:first-line {
padding-right: 41px;
}
}
This, however, seems to be ignored. Am I doing something wrong or--as I suspect--is this simply impossible?
Another, easier if inelegant, solution would be to set the Copy to Clipboard button's style to
.code-example .copy-icon {
display: block;
margin-right: -16px;
margin-top: -16px;
float: right;
}
and move the <button> inside the <pre>. But, much like <table> en lieu of display: grid, float is out of vogue.
Plus, without a conditional check for mobile browsers, this change would alter the behavior of desktop/non-buggy mobile browsers:
Despite white-space: pre; overflow: auto, the browser is rendering line-wrap.
Assuming :first-line { padding-right } is unsupported, is there another way to achieve the same effect with either CSS or a JavaScript hack?
Note: I did search for a duplicate question, but every result was about indenting the first line of a paragraph, the solution to which is :first-line { text-indent }.
Update
I suppose given any solution that detects the browser must, by definition, detect the browser, we could just detect buggy browsers using navigator.userAgent, and then manipulate the DOM and apply float: right to the button. Kinda nasty, though.

Inspecting the MDN page you've referred to, I noticed there is a <code> element inside the <pre>. Hence, you could do the following:
#media screen and (max-width: /* ... */) {
/* or some other way to determine we're in a mobile browser */
.code-example pre code {
display: block;
max-width: 90%;
}
}
That way, the Copy to Clipboard button wouldn't overlap the code.

Related

Why do these two snippets render differently using display:table/table-cell/table-row?

In writing some CSS using display: table/table-row/table-cell, I ran into some behaviour I don't understand, but is consistent across Chrome and Firefox. I reduced it to the following two snippets highlighting the difference:
https://codepen.io/anon/pen/YavWJJ
https://codepen.io/anon/pen/XEYKxg
The styling rules are very simple:
* { box-sizing: border-box; border: none; margin: 0; }
.stack, .flow {
width: 100%;
display: table;
}
.stack > * {
display: table-row;
}
.flow > * {
display: table-cell;
}
.w-100 { width: 100%; }
The html is rougly:
<div class="flow">
<div>L</div>
<input type="text"class="w-100" placeholder="M" />
<div>R</div>
</div>
The only difference in the second link is that the last div with the R is replaced by <button> (input also shows the same behaviour). Both should render as a table-cell wrapped in an anonymous table-row, and I think it should look like the first snippet regardless. I must be missing something obvious to explain this difference, so can anyone explain why these two snippets render differently?
Interestingly enough, Edge renders them exactly the same as I initially expected.
Edit: If you constrain the L and R elements to be fixed size, and the row as a whole is set to 100%, the M/middle cell should expand to fit the whole width, but it doesn't work as expected either in Chrome. These two snippets are also rendered differently for some inexplicable reason:
https://codepen.io/anon/pen/aYKmbY
https://codepen.io/anon/pen/PRaGoY
It seems the rendering only works consistently if all of the elements used as table-cell are divs, like so: https://codepen.io/anon/pen/mxKreZ
This behavior with buttons is a known issue affecting both browsers (issue for Chrome and for Firefox). The explanation given by both vendors is the special rendering of buttons owing to their nature as form elements. There are no plans by either vendor to fix this, at least not until the css-display-3 and/or css-tables-3 specs have matured.
As you've observed, Edge renders your snippets as expected, because Edge (and in fact IE11) does support rendering buttons as table-cells.

Remove the 'X' (clear button) from the input type date and change the font family in Firefox

I have an input type field in my form, but in Firefox I am not able to remove the X icon (clear button) that appears when I have a date value set inside the input.
Moreover, I cannot change the font family in that input. It seems to be the Courier font family instead of the Arial font family, which is currently set as default in the whole website.
It is not possible to remove the clear button in FireFox. The ::ms-clear feature is only for Microsoft browsers, as described in the MDN documentation.
X or clear button
Even though the class referring to the clear button can be found through Shadow DOM inspection (i.e. .datetime-reset-button from datetimebox.css):
And direct changes in the inspector/devtools work (e.g. add display: none to the class), shadow root access and shadow elements manipulation/attachment is not allowed in <input> tags, leading to a "DOMException: Operation is not supported" if myInput.attachShadow({mode: 'open'}) is attempted (e.g. :host-context MDN example).
An alternative/workaround is to place an overlay image/background on the input's container through ::after:
#-moz-document url-prefix() { /* apply rules only to Firefox */
.my-datetime-input-container::after {
content: "";
position: absolute;
top: 42%;
right: 0.25rem;
background: url(/images/overlay.svg) white no-repeat;
/* or simply use background: white; */
background-size: 1rem;
width: 1rem;
height: 1rem;
}
}
This overlay prevents clicks/taps on the Shadow DOM clear button because it's literally covering it (needs an opaque background to completely hide it).
Font family issues
Changing the input's font, may be a specificity issue, attempting a more specific selector may be enough to apply the rule:
.my-datetime-input-container input[type="date"].my-specific-class {
font-family: inherit;
}
Where:
<div class="my-datetime-input-container">
<input type="date" class="my-specific-class" />
</div>
I think you could try this :
input[type=text]::-ms-clear {
display: none;
}
But the documentation warn about the ::-ms-clear CSS pseudo-element.
Non-standard This feature is non-standard and is not on a standards
track. Do not use it on production sites facing the Web: it will not
work for every user. There may also be large incompatibilities between
implementations and the behavior may change in the future.
Check this : https://developer.mozilla.org/en-US/docs/Web/CSS/%3A%3A-ms-clear

css target IE and Microsoft Edge

What is the proper way to target IE and Microsoft Edge to apply for specific css?
This is my general css:
.details-list {
font-size: 13px;
font-style: italic;
display: table;
margin: 0 auto;
}
so, lets say that I want to increase font-size only for Microssft Edge and IE.
What is the preferable way to do say(sass is set up- if that helps)?
Any help is welcome!
Browser-specific CSS should usually be avoided, but if your really need to, you're having various possibilities. These should be the most common ones:
use conditional comments in the html to target specific IE-versions:
https://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
use css hacks by writing syntactically wrong CSS, which is (due to autocorrection) still applied in some browsers/versions.
http://browserhacks.com/ is a quite good collection for this
Use JavaScript to set a CSS-Class like is-internet-explorer, which is then used in the css to target only such browsers. As userAgent evaluation is quite difficult and browsers often pretend to be another browser, you should use a JavaScript-Library for this tedious task (e.g. https://github.com/DamonOehlman/detect-browser)
Use some Server-Side Logic to deliver an extra CSS-Filer or set an extra class. This is basically the same as #3, but on the server side.
If there is a specific CSS statement you are looking for (like object-fit:cover), use feature detection. This has a few benefits, including also working if the browser implements the property down the line.
#supports (object-fit:cover) {
.element {
height: 100%;
object-fit:cover;
}
}
Otherwise you can use CSS Hacks, here is a SASS mixin for that:
/**
Applies for all Internet Explorer and Edge versions
**/
#mixin worstBrowsers() {
/* all IE versions <= 11 */
#media screen and (-ms-high-contrast: none) {
#content;
}
/* all edge versions */
#supports (-ms-ime-align:auto) {
#content;
}
}
.element {
#include worstBrowsers {
font-size: .6em;
}
}

IE filters don't display on duplicated element text

I have been wracked for days trying to find why I can't use the MS blur & glow filters to generate a drop shadow in Internet Explorer as appearing on this page:
http://kilianvalkhof.com/uploads/ieshadow.html
Here, a second text element is positioned under the first element, offset a bit, and the filters applied. My layout is using the same technique, for a drop shadow on the H1 element at the top, which shows fine in standards-compliant browsers, but the filtered element is not showing in IE8 or IE9:
http://a11.cosd.com
My markup uses a <span> like the working example:
<h1>AREA11<span class="IEshadow">AREA11</span></h1>
with CSS the same except for the selectors:
#headerContainer header h1 span.IEshadow {
display: none;
}
.lt-ie10 #headerContainer header h1 span.IEshadow {
display: block;
position: absolute;
left: -4px;
top: -4px;
z-index: -1;
zoom: 1;
filter: progid:DXImageTransform.Microsoft.Glow(Color=#000000,Strength=2) progid:DXImageTransform.Microsoft.blur(pixelradius=5,enabled='true');
-ms-filter: "progid:DXImageTransform.Microsoft.Glow(Color=#000000,Strength=2) progid:DXImageTransform.Microsoft.blur(pixelradius=5,enabled='true')";
}
But in my layout the filters aren't applied at all, even though I can see the filter: properties are listed in IE8 and IE9 with the (F12) Developer Tools. This isn't the first time I've used Visual Filters in a design, but in this case I've copied the code character by character.
One odd thing: when I view the filter: property in IE8 developer tools, it shows the other properties lumped together on the same line, though they appear normally in IE9 where the problem is still happening.
I have tried everything I can imagine, including disabling all other Javascripts from the page and simplifying the markup and CSS, as well as avoiding font-face and putting the <span> in IE conditional comments as in the working example... no change. (I need to avoid the IE conditional comments to eventually implement this in jQuery.)
There must be something very basic I am missing here about why MS filters won't work in this context. I will absolutely summarise any progress & findings here if my layout changes in the course of testing.
This is a z-index issue. The .IEshadow is positioned behind the background.
Give your h1 a z-index of 10 and it should work.
#headerContainer header h1 {
...
z-index: 10;
}
You might also want to change the color of .IEshadow
.lt-ie10 #headerContainer header h1 span.IEshadow {
...
color: #000000;
...
}

HTML 5 required message being cropped

I am currently migrating a site to HTML 5 and taking advantage of the new input types and attributes - using JavaScript as a fallback when a type or attribute is not implemented. My issue is that when the required message is triggered in FireFox the message is being cropped due to it overlapping the boundary of the containing div as below:
Demo: http://jsfiddle.net/f8b7D/2/
Is there a way to trigger the display of the message to shift to use the space available further left where it would not be cropped? I know that the message box cannot be selected using CSS and I would prefer not to rely on a JS solution as we have a number of users who have JavaScript disabled.
Additional Info:
In Chrome the default message for a select element overlaps the message bubble, although it is fully visible.
In Opera it displays correctly.
IE doesn't support the required attribute.
Fixed in Firefox 29 - apparently due to some dead code from 2002 that was removed once someone called their attention to it.
https://bugzilla.mozilla.org/show_bug.cgi?id=647813
I'm afraid that there is no way (and perhaps never will be a way) to style the message bubble for HTML5. I'm afraid that Javascript is your best bet. Here's some context.
HTML5 Required input styling
After some further playing around I found that the width of the message box is the same as the width of the select element. By setting the min-width of the select to the width of the message box (230px) the cropping can be prevented.
select{min-width: 230px;}
This solution is definitely a hack and should only be used if your site style will not be ruined by wide select elements. If you only have options with short text values e.g. Yes, No, Maybe then the required width of the select may look peculiar so only use this solution with care.
Unfortunately this does nothing about the appearance in Chrome.
I found a solution of sorts to this clipping of html5 form error messages. Its caused by a width being used in our css for a select element. If you increase the width the popup error message also increases in width. This also only seems to affect Firefox.
So I wrapped the 'select' in a span and gave that a position relative. I then gave the select a wider width (to accommodate the error message), but then also gave it a negative left margin. You'll need to play with your own px widths for your situation, but this solved the issue. I avoided having a default value for the first 'option' but I'm guessing you can use text-align right on the 'option' elements.
This solution then creates another issue! The red outline which Firefox uses for its invalid states will outline the entire 'hidden' area of the select which looks odd and different to other elements, so the answer was to simply turn off the borders, but I used css for the valid and invalid states to simply add a background icon (check/cross) to indicate when form fields were valid/invalid. I also used x:-moz-any-link in my css to filter these styles only for firefox and no other browsers. Heres my css...
/* start styles for Firefox clipping of validation msgs */
form fieldset > span, x:-moz-any-link {position: relative; }
form select, x:-moz-any-link {width: 230px; margin-left: -82px; }
form select option, x:-moz-any-link {width: 220px; margin-right: -20px; text-align: center; }
form input, form select, x:-moz-any-link {border: solid 1px transparent; box-shadow: none; }
form input:-moz-placeholder, form select:-moz-placeholder, x:-moz-any-link {box-shadow: none !important; }
form input:invalid, form select:invalid, x:-moz-any-link {box-shadow:0 0 3px transparent; }
/* end styles for Firefox clipping of validation msgs */
input:valid {background: #fff url("forms-check.png") no-repeat 130px center; }
input:focus:invalid {background: #fff url("forms-cancel.png") no-repeat 130px center; }
Its all a lot easier than I've made it sound?!
Hope its useful.