Rectangle 27 145

CSS and Javascript

Consider the following link to minify Javascript/CSS files: https://github.com/mrclay/minify

Tell Apache to deliver HTML with GZip - this generally reduces the response size by about 70%. (If you use Apache, the module configuring gzip depends on your version: Apache 1.3 uses mod_gzip while Apache 2.x uses mod_deflate.)

Use the following snippet to remove white-spaces from the HTML with the help ob_start's buffer:

<?php

function sanitize_output($buffer) {

    $search = array(
        '/\>[^\S ]+/s',     // strip whitespaces after tags, except space
        '/[^\S ]+\</s',     // strip whitespaces before tags, except space
        '/(\s)+/s',         // shorten multiple whitespace sequences
        '/<!--(.|\s)*?-->/' // Remove HTML comments
    );

    $replace = array(
        '>',
        '<',
        '\\1',
        ''
    );

    $buffer = preg_replace($search, $replace, $buffer);

    return $buffer;
}

ob_start("sanitize_output");

?>

This is a good function but be wary of it if you use PRE tags, sometimes newlines will be removed there.

Where should this code be, at the top of your script or the bottom?

$content = \Minify_HTML::minify($content);

This also breaks inline JavaScript (i.e. in <script> tags) that doesn't have ; at the end of every statement or has comments that use //

this will remove spaces from textarea, pre, input, img also this breaks inline javascripts. if someone is not happy to use bulky class with DOM parsing this solution based on regexp works great

How to minify php page html output? - Stack Overflow

php html minify
Rectangle 27 7

CSS and JavaScript:

<style type="text/css">
.scrolloff iframe   {
    pointer-events: none ;
}
</style>

<script type="text/javascript">
function scrollOn() {
    $('#map').removeClass('scrolloff'); // set the pointer events true on click

}

function scrollOff() {
    $('#map').addClass('scrolloff'); 

}
</script>
<div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" >
function scrollOn() {
    $('#map').removeClass('scrolloff'); // set the pointer events true on click
   
}

function scrollOff() {
    $('#map').addClass('scrolloff'); // set the pointer events true on click
    
}
.scrolloff iframe   {
        pointer-events: none ;
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" ><iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d23845.03946309692!2d-70.0451736316453!3d41.66373705082399!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x89fb159980380d21%3A0x78c040f807017e30!2sChatham+Tides!5e0!3m2!1sen!2sus!4v1452964723177" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe></div>

Hope this helps anyone looking for a simple solution.

scrollwheel - Disable mouse scroll wheel zoom on embedded Google Maps ...

google-maps scrollwheel
Rectangle 27 7

CSS and JavaScript:

<style type="text/css">
.scrolloff iframe   {
    pointer-events: none ;
}
</style>

<script type="text/javascript">
function scrollOn() {
    $('#map').removeClass('scrolloff'); // set the pointer events true on click

}

function scrollOff() {
    $('#map').addClass('scrolloff'); 

}
</script>
<div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" >
function scrollOn() {
    $('#map').removeClass('scrolloff'); // set the pointer events true on click
   
}

function scrollOff() {
    $('#map').addClass('scrolloff'); // set the pointer events true on click
    
}
.scrolloff iframe   {
        pointer-events: none ;
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" ><iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d23845.03946309692!2d-70.0451736316453!3d41.66373705082399!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x89fb159980380d21%3A0x78c040f807017e30!2sChatham+Tides!5e0!3m2!1sen!2sus!4v1452964723177" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe></div>

Hope this helps anyone looking for a simple solution.

scrollwheel - Disable mouse scroll wheel zoom on embedded Google Maps ...

google-maps scrollwheel
Rectangle 27 7

CSS and JavaScript:

<style type="text/css">
.scrolloff iframe   {
    pointer-events: none ;
}
</style>

<script type="text/javascript">
function scrollOn() {
    $('#map').removeClass('scrolloff'); // set the pointer events true on click

}

function scrollOff() {
    $('#map').addClass('scrolloff'); 

}
</script>
<div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" >
function scrollOn() {
    $('#map').removeClass('scrolloff'); // set the pointer events true on click
   
}

function scrollOff() {
    $('#map').addClass('scrolloff'); // set the pointer events true on click
    
}
.scrolloff iframe   {
        pointer-events: none ;
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" ><iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d23845.03946309692!2d-70.0451736316453!3d41.66373705082399!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x89fb159980380d21%3A0x78c040f807017e30!2sChatham+Tides!5e0!3m2!1sen!2sus!4v1452964723177" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe></div>

Hope this helps anyone looking for a simple solution.

scrollwheel - Disable mouse scroll wheel zoom on embedded Google Maps ...

google-maps scrollwheel
Rectangle 27 7

CSS and JavaScript:

<style type="text/css">
.scrolloff iframe   {
    pointer-events: none ;
}
</style>

<script type="text/javascript">
function scrollOn() {
    $('#map').removeClass('scrolloff'); // set the pointer events true on click

}

function scrollOff() {
    $('#map').addClass('scrolloff'); 

}
</script>
<div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" >
function scrollOn() {
    $('#map').removeClass('scrolloff'); // set the pointer events true on click
   
}

function scrollOff() {
    $('#map').addClass('scrolloff'); // set the pointer events true on click
    
}
.scrolloff iframe   {
        pointer-events: none ;
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" ><iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d23845.03946309692!2d-70.0451736316453!3d41.66373705082399!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x89fb159980380d21%3A0x78c040f807017e30!2sChatham+Tides!5e0!3m2!1sen!2sus!4v1452964723177" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe></div>

Hope this helps anyone looking for a simple solution.

scrollwheel - Disable mouse scroll wheel zoom on embedded Google Maps ...

google-maps scrollwheel
Rectangle 27 193

The answer is to gzip the CSS and JavaScript files. Yes, you read that right.

gzip -9 production.min.css

This will produce production.min.css.gz. Remove the .gz, upload to S3 (or whatever origin server you're using) and explicitly set the Content-Encoding header for the file to gzip.

It's not on-the-fly gzipping, but you could very easily wrap it up into your build/deployment scripts. The advantages are:

  • It requires no CPU for Apache to gzip the content when the file is requested.
gzip -9
  • You're serving the file from a CDN.

Assuming that your CSS/JavaScript files are (a) minified and (b) large enough to justify the CPU required to decompress on the user's machine, you can get significant performance gains here.

Just remember: If you make a change to a file that is cached in CloudFront, make sure you invalidate the cache after making this type of change.

After reading your link, I must say that the blog author is uninformed. "However, if the user does have a browser that does not support gzip encoding, your sites zipped stylesheets and javascripts simply will not work for that user." This browser would likely be too old to run your stylesheets and script files anyway. These users make up a fraction of a percent.

UPDATE: I worked it out. The reason it wasn't displaying was that I'd forgotten to set Content-Type to text/css. If you do that, you're fine, although for some reason it seems you can't add an "Accept-Encoding: Vary" header in S3 (which would help with the Google Speed rating) for the reasons described here: [link]. Also, I set Cache-control to cache the asset, but it doesn't seem to be caching it...

Just found this via Google, and I'm sorry to have to say this isn't that good advice. While <1% of desktop browsers can't handle gzipped content, quite many mobile browsers cannot. How many depends on which target audience you're looking at; but most older Nokia S40's have buggy gzip compression for example. The proper way is a "Custom Origin", which points to an Apache/IIS webserver which does content compression and serves the proper HTTP headers. Here is one blog post that describes the gist of it: nomitor.com/blog/2010/11/10/

How's the situation now, in early 2015? Are the links posted by @JesperMortensen and Simon Peck still relevant?

Amazon announced support for gzip compression in December of 2015, so this is now irrelevant just upload the basic file and it will work. aws.amazon.com/blogs/aws/

Serving gzipped CSS and JavaScript from Amazon CloudFront via S3 - Sta...

javascript css amazon-s3 gzip amazon-cloudfront
Rectangle 27 64

Custom Tooltips with pure CSS - no JavaScript needed:

As an alternative to the default title attribute tooltips, you can make your own custom CSS tooltips using :before/:after pseudo elements and HTML5 data-* attributes.

Using the provided CSS, you can add a tooltip to an element using the data-tooltip attribute.

You can also control the position of the custom tooltip using the data-tooltip-position attribute (accepted values: top/right/bottom/left).

For instance, the following will add a tooltop positioned at the bottom of the span element.

<span data-tooltip="Custom tooltip text." data-tooltip-position="bottom">Custom bottom tooltip.</span>

You can display the custom tooltips with pseudo elements by retrieving the custom attribute values using the attr() function.

[data-tooltip]:before {
    content: attr(data-tooltip);
}

In terms of positioning the tooltip, just use the attribute selector and change the placement based on the attribute's value.

Full CSS used in the example

[data-tooltip] {
    display: inline-block;
    position: relative;
    cursor: help;
    padding: 4px;
}
/* Tooltip styling */
[data-tooltip]:before {
    content: attr(data-tooltip);
    display: none;
    position: absolute;
    background: #000;
    color: #fff;
    padding: 4px 8px;
    font-size: 14px;
    line-height: 1.4;
    min-width: 100px;
    text-align: center;
    border-radius: 4px;
}
/* Dynamic horizontal centering */
[data-tooltip-position="top"]:before,
[data-tooltip-position="bottom"]:before {
    left: 50%;
    -ms-transform: translateX(-50%);
    -moz-transform: translateX(-50%);
    -webkit-transform: translateX(-50%);
    transform: translateX(-50%);
}
/* Dynamic vertical centering */
[data-tooltip-position="right"]:before,
[data-tooltip-position="left"]:before {
    top: 50%;
    -ms-transform: translateY(-50%);
    -moz-transform: translateY(-50%);
    -webkit-transform: translateY(-50%);
    transform: translateY(-50%);
}
[data-tooltip-position="top"]:before {
    bottom: 100%;
    margin-bottom: 6px;
}
[data-tooltip-position="right"]:before {
    left: 100%;
    margin-left: 6px;
}
[data-tooltip-position="bottom"]:before {
    top: 100%;
    margin-top: 6px;
}
[data-tooltip-position="left"]:before {
    right: 100%;
    margin-right: 6px;
}

/* Tooltip arrow styling/placement */
[data-tooltip]:after {
    content: '';
    display: none;
    position: absolute;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
}
/* Dynamic horizontal centering for the tooltip */
[data-tooltip-position="top"]:after,
[data-tooltip-position="bottom"]:after {
    left: 50%;
    margin-left: -6px;
}
/* Dynamic vertical centering for the tooltip */
[data-tooltip-position="right"]:after,
[data-tooltip-position="left"]:after {
    top: 50%;
    margin-top: -6px;
}
[data-tooltip-position="top"]:after {
    bottom: 100%;
    border-width: 6px 6px 0;
    border-top-color: #000;
}
[data-tooltip-position="right"]:after {
    left: 100%;
    border-width: 6px 6px 6px 0;
    border-right-color: #000;
}
[data-tooltip-position="bottom"]:after {
    top: 100%;
    border-width: 0 6px 6px;
    border-bottom-color: #000;
}
[data-tooltip-position="left"]:after {
    right: 100%;
    border-width: 6px 0 6px 6px;
    border-left-color: #000;
}
/* Show the tooltip when hovering */
[data-tooltip]:hover:before,
[data-tooltip]:hover:after {
    display: block;
    z-index: 50;
}

This was great except doesn't work in IE10 :/

Yes I just tested it and also wasn't surprised it didn't work .Good old IE! ;)

@JoshCrozier it helped a lot

html - How do I add a tool tip to a span element? - Stack Overflow

html css
Rectangle 27 64

Custom Tooltips with pure CSS - no JavaScript needed:

As an alternative to the default title attribute tooltips, you can make your own custom CSS tooltips using :before/:after pseudo elements and HTML5 data-* attributes.

Using the provided CSS, you can add a tooltip to an element using the data-tooltip attribute.

You can also control the position of the custom tooltip using the data-tooltip-position attribute (accepted values: top/right/bottom/left).

For instance, the following will add a tooltop positioned at the bottom of the span element.

<span data-tooltip="Custom tooltip text." data-tooltip-position="bottom">Custom bottom tooltip.</span>

You can display the custom tooltips with pseudo elements by retrieving the custom attribute values using the attr() function.

[data-tooltip]:before {
    content: attr(data-tooltip);
}

In terms of positioning the tooltip, just use the attribute selector and change the placement based on the attribute's value.

Full CSS used in the example

[data-tooltip] {
    display: inline-block;
    position: relative;
    cursor: help;
    padding: 4px;
}
/* Tooltip styling */
[data-tooltip]:before {
    content: attr(data-tooltip);
    display: none;
    position: absolute;
    background: #000;
    color: #fff;
    padding: 4px 8px;
    font-size: 14px;
    line-height: 1.4;
    min-width: 100px;
    text-align: center;
    border-radius: 4px;
}
/* Dynamic horizontal centering */
[data-tooltip-position="top"]:before,
[data-tooltip-position="bottom"]:before {
    left: 50%;
    -ms-transform: translateX(-50%);
    -moz-transform: translateX(-50%);
    -webkit-transform: translateX(-50%);
    transform: translateX(-50%);
}
/* Dynamic vertical centering */
[data-tooltip-position="right"]:before,
[data-tooltip-position="left"]:before {
    top: 50%;
    -ms-transform: translateY(-50%);
    -moz-transform: translateY(-50%);
    -webkit-transform: translateY(-50%);
    transform: translateY(-50%);
}
[data-tooltip-position="top"]:before {
    bottom: 100%;
    margin-bottom: 6px;
}
[data-tooltip-position="right"]:before {
    left: 100%;
    margin-left: 6px;
}
[data-tooltip-position="bottom"]:before {
    top: 100%;
    margin-top: 6px;
}
[data-tooltip-position="left"]:before {
    right: 100%;
    margin-right: 6px;
}

/* Tooltip arrow styling/placement */
[data-tooltip]:after {
    content: '';
    display: none;
    position: absolute;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
}
/* Dynamic horizontal centering for the tooltip */
[data-tooltip-position="top"]:after,
[data-tooltip-position="bottom"]:after {
    left: 50%;
    margin-left: -6px;
}
/* Dynamic vertical centering for the tooltip */
[data-tooltip-position="right"]:after,
[data-tooltip-position="left"]:after {
    top: 50%;
    margin-top: -6px;
}
[data-tooltip-position="top"]:after {
    bottom: 100%;
    border-width: 6px 6px 0;
    border-top-color: #000;
}
[data-tooltip-position="right"]:after {
    left: 100%;
    border-width: 6px 6px 6px 0;
    border-right-color: #000;
}
[data-tooltip-position="bottom"]:after {
    top: 100%;
    border-width: 0 6px 6px;
    border-bottom-color: #000;
}
[data-tooltip-position="left"]:after {
    right: 100%;
    border-width: 6px 0 6px 6px;
    border-left-color: #000;
}
/* Show the tooltip when hovering */
[data-tooltip]:hover:before,
[data-tooltip]:hover:after {
    display: block;
    z-index: 50;
}

This was great except doesn't work in IE10 :/

Yes I just tested it and also wasn't surprised it didn't work .Good old IE! ;)

@JoshCrozier it helped a lot

html - How do I add a tool tip to a span element? - Stack Overflow

html css
Rectangle 27 2006

How about a non CSS - no javascript/jQuery answer?

<select>
    <option value="" disabled selected>Select your option</option>
    <option value="hurr">Durr</option>
</select>

Firefox (10) doesn't show a disabled option as the default selection (placeholder). It shows the next one by default, in this case "Durr".

<select> <option value="" disabled selected>Select your option</option> </select>

The reason this isn't the correct answer is because (I believe) the asker wants the select to be gray until another value has been selected. This answer makes the option gray in the drop down; but not the select element.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

html - How do I make a placeholder for a 'select' box? - Stack Overflo...

html css html5 html-select placeholder
Rectangle 27 2006

How about a non CSS - no javascript/jQuery answer?

<select>
    <option value="" disabled selected>Select your option</option>
    <option value="hurr">Durr</option>
</select>

Firefox (10) doesn't show a disabled option as the default selection (placeholder). It shows the next one by default, in this case "Durr".

<select> <option value="" disabled selected>Select your option</option> </select>

The reason this isn't the correct answer is because (I believe) the asker wants the select to be gray until another value has been selected. This answer makes the option gray in the drop down; but not the select element.

html - How do I make a placeholder for a 'select' box? - Stack Overflo...

html css html5 html-select placeholder
Rectangle 27 2006

How about a non CSS - no javascript/jQuery answer?

<select>
    <option value="" disabled selected>Select your option</option>
    <option value="hurr">Durr</option>
</select>

Firefox (10) doesn't show a disabled option as the default selection (placeholder). It shows the next one by default, in this case "Durr".

<select> <option value="" disabled selected>Select your option</option> </select>

The reason this isn't the correct answer is because (I believe) the asker wants the select to be gray until another value has been selected. This answer makes the option gray in the drop down; but not the select element.

html - How do I make a placeholder for a 'select' box? - Stack Overflo...

html css html5 html-select placeholder
Rectangle 27 2006

How about a non CSS - no javascript/jQuery answer?

<select>
    <option value="" disabled selected>Select your option</option>
    <option value="hurr">Durr</option>
</select>

Firefox (10) doesn't show a disabled option as the default selection (placeholder). It shows the next one by default, in this case "Durr".

<select> <option value="" disabled selected>Select your option</option> </select>

The reason this isn't the correct answer is because (I believe) the asker wants the select to be gray until another value has been selected. This answer makes the option gray in the drop down; but not the select element.

html - How do I make a placeholder for a 'select' box? - Stack Overflo...

html css html5 html-select placeholder
Rectangle 27 1997

How about a non CSS - no javascript/jQuery answer?

<select>
    <option value="" disabled selected>Select your option</option>
    <option value="hurr">Durr</option>
</select>

Firefox (10) doesn't show a disabled option as the default selection (placeholder). It shows the next one by default, in this case "Durr".

<select> <option value="" disabled selected>Select your option</option> </select>

The reason this isn't the correct answer is because (I believe) the asker wants the select to be gray until another value has been selected. This answer makes the option gray in the drop down; but not the select element.

html - How do I make a placeholder for a 'select' box? - Stack Overflo...

html css html5 html-select placeholder
Rectangle 27 215

It uses a helper-div and some custom css. No javascript or jQuery required.

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Launch demo modal</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="vertical-alignment-helper">
        <div class="modal-dialog vertical-align-center">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>

                    </button>
                     <h4 class="modal-title" id="myModalLabel">Modal title</h4>

                </div>
                <div class="modal-body">...</div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>
</div>
.vertical-alignment-helper {
    display:table;
    height: 100%;
    width: 100%;
    pointer-events:none; /* This makes sure that we can still click outside of the modal to close it */
}
.vertical-align-center {
    /* To center vertically */
    display: table-cell;
    vertical-align: middle;
    pointer-events:none;
}
.modal-content {
    /* Bootstrap sets the size of the modal in the modal-dialog class, we need to inherit it */
    width:inherit;
    max-width:inherit; /* For Bootstrap 4 - to avoid the modal window stretching full width */
    height:inherit;
    /* To center horizontally */
    margin: 0 auto;
    pointer-events: all;
}

With this solution, because of the height: 100%; and width: 100%; you can't close the modals by clicking out of the modals. Can you think of a fix for this @Rens de Nobel?

Ok this solution appears to work great (except that it stops me from closing the modals by clicking out of them). But somehow it makes some of my e2e tests with protractor fail (and I can't find the reason why, it does not feel like it is a bug on this). Anyway I'm going back to the javascript answer so I don't lose more time on this. But like I said, this appears to work fine, just warning people doing e2e tests with protractor to watch out.

@pcatre, thanks for the tip ! I've updated the code with a fix for this. Setting pointer-events:none; on the alignment-classes does the trick. Tested in IE11, Latest Chrome and Firefox and iOS Safari.

Not sure if this has been updated since the comments of users saying it doesn't work, on click of inside modal elements, but this is 100% working for me as of now, using the example in the Fiddle above. Thanks so much for your help and all the comments above.

javascript - Vertically centering Bootstrap modal window - Stack Overf...

javascript twitter-bootstrap bootstrap-modal
Rectangle 27 211

It uses a helper-div and some custom css. No javascript or jQuery required.

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Launch demo modal</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="vertical-alignment-helper">
        <div class="modal-dialog vertical-align-center">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>

                    </button>
                     <h4 class="modal-title" id="myModalLabel">Modal title</h4>

                </div>
                <div class="modal-body">...</div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>
</div>
.vertical-alignment-helper {
    display:table;
    height: 100%;
    width: 100%;
    pointer-events:none; /* This makes sure that we can still click outside of the modal to close it */
}
.vertical-align-center {
    /* To center vertically */
    display: table-cell;
    vertical-align: middle;
    pointer-events:none;
}
.modal-content {
    /* Bootstrap sets the size of the modal in the modal-dialog class, we need to inherit it */
    width:inherit;
    max-width:inherit; /* For Bootstrap 4 - to avoid the modal window stretching full width */
    height:inherit;
    /* To center horizontally */
    margin: 0 auto;
    pointer-events: all;
}

With this solution, because of the height: 100%; and width: 100%; you can't close the modals by clicking out of the modals. Can you think of a fix for this @Rens de Nobel?

Ok this solution appears to work great (except that it stops me from closing the modals by clicking out of them). But somehow it makes some of my e2e tests with protractor fail (and I can't find the reason why, it does not feel like it is a bug on this). Anyway I'm going back to the javascript answer so I don't lose more time on this. But like I said, this appears to work fine, just warning people doing e2e tests with protractor to watch out.

@pcatre, thanks for the tip ! I've updated the code with a fix for this. Setting pointer-events:none; on the alignment-classes does the trick. Tested in IE11, Latest Chrome and Firefox and iOS Safari.

Not sure if this has been updated since the comments of users saying it doesn't work, on click of inside modal elements, but this is 100% working for me as of now, using the example in the Fiddle above. Thanks so much for your help and all the comments above.

javascript - Vertically centering Bootstrap modal window - Stack Overf...

javascript twitter-bootstrap bootstrap-modal
Rectangle 27 141

Styling file inputs is notoriously difficult, as most browsers will not change the appearance from either css or javascript.

Even the size of the input will not respond to the likes of:

<input type="file" style="width:200px">
<input type="file" size="60" />

For any styling more sophisticated than that (e.g. changing the look of the browse button) you will need to look at the tricksy approach of overlaying a styled button and input box on top of the native file input. The article already mentioned by rm at www.quirksmode.org/dom/inputfile.html is the best one I've seen.

Just found a jquery solution based on this script here: blog.vworld.at/2008/08/21/

@TLK Ryan's answer won't work in IE when trying to do iframe uploads. It gives you an access denied error. For normal uploads, I agree it is the easiest though!

A much simpler solution than quirksmode's is explained here. Just putting that link here, since this answer is basically a link-only answer anyway.

For anyone interested in a modern approach, i'd suggest looking at this answer. It doesn't require JavaScript like some of the other answers either.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

html - Styling an input type="file" button - Stack Overflow

html css file-io
Rectangle 27 141

Styling file inputs is notoriously difficult, as most browsers will not change the appearance from either css or javascript.

Styling file inputs is notoriously difficult, as most browsers will not change the appearance from either css or javascript.

Even the size of the input will not respond to the likes of:

Even the size of the input will not respond to the likes of:

<input type="file" style="width:200px">
<input type="file" style="width:200px">
<input type="file" size="60" />
<input type="file" size="60" />

For any styling more sophisticated than that (e.g. changing the look of the browse button) you will need to look at the tricksy approach of overlaying a styled button and input box on top of the native file input. The article already mentioned by rm at www.quirksmode.org/dom/inputfile.html is the best one I've seen.

For any styling more sophisticated than that (e.g. changing the look of the browse button) you will need to look at the tricksy approach of overlaying a styled button and input box on top of the native file input. The article already mentioned by rm at www.quirksmode.org/dom/inputfile.html is the best one I've seen.

Just found a jquery solution based on this script here: blog.vworld.at/2008/08/21/…

Just found a jquery solution based on this script here: blog.vworld.at/2008/08/21/

@TLK Ryan's answer won't work in IE when trying to do iframe uploads. It gives you an access denied error. For normal uploads, I agree it is the easiest though!

@TLK Ryan's answer won't work in IE when trying to do iframe uploads. It gives you an access denied error. For normal uploads, I agree it is the easiest though!

A much simpler solution than quirksmode's is explained here. Just putting that link here, since this answer is basically a link-only answer anyway.

A much simpler solution than quirksmode's is explained here. Just putting that link here, since this answer is basically a link-only answer anyway.

For anyone interested in a modern approach, i'd suggest looking at this answer. It doesn't require JavaScript like some of the other answers either.

For anyone interested in a modern approach, i'd suggest looking at this answer. It doesn't require JavaScript like some of the other answers either.

html - Styling an input type="file" button - Stack Overflow

html css file-io
Rectangle 27 141

Styling file inputs is notoriously difficult, as most browsers will not change the appearance from either css or javascript.

Even the size of the input will not respond to the likes of:

<input type="file" style="width:200px">
<input type="file" size="60" />

For any styling more sophisticated than that (e.g. changing the look of the browse button) you will need to look at the tricksy approach of overlaying a styled button and input box on top of the native file input. The article already mentioned by rm at www.quirksmode.org/dom/inputfile.html is the best one I've seen.

Just found a jquery solution based on this script here: blog.vworld.at/2008/08/21/

@TLK Ryan's answer won't work in IE when trying to do iframe uploads. It gives you an access denied error. For normal uploads, I agree it is the easiest though!

A much simpler solution than quirksmode's is explained here. Just putting that link here, since this answer is basically a link-only answer anyway.

For anyone interested in a modern approach, i'd suggest looking at this answer. It doesn't require JavaScript like some of the other answers either.

html - Styling an input type="file" button - Stack Overflow

html css file-io
Rectangle 27 6

Is the recommendation to include CSS before JavaScript invalid?

Is the recommendation to include CSS before JavaScript invalid?

Not if you treat it as simply a recommendation. But if your treat it as a hard and fast rule?, yes, it is invalid.

Not if you treat it as simply a recommendation. But if your treat it as a hard and fast rule?, yes, it is invalid.

Stylesheet loads block script execution, so if you have a <script> after a <link rel="stylesheet" ...> the page will not finish parsing - and DOMContentLoaded will not fire - until the stylesheet is loaded.

Stylesheet loads block script execution, so if you have a <script> after a <link rel="stylesheet" ...> the page will not finish parsing - and DOMContentLoaded will not fire - until the stylesheet is loaded.

It appears that you need to know what each script relies on and make sure that execution of the script is delayed until after the right completion event. If the script relies only on the DOM, it can resume in ondomready/domcontentloaded, if it relies on images to be loaded or stylesheets to be applied, then if I read the above reference correctly, that code must be deferred until the onload event.

It appears that you need to know what each script relies on and make sure that execution of the script is delayed until after the right completion event. If the script relies only on the DOM, it can resume in ondomready/domcontentloaded, if it relies on images to be loaded or stylesheets to be applied, then if I read the above reference correctly, that code must be deferred until the onload event.

I don't think that one sock size fits all, even though that is the way they are sold and I know that one shoe size does not fit all. I don't think that there is a definitive answer to which to load first, styles or script. It is more a case by case decision of what must be loaded in what order and what can be deferred until later as not being on the "critical path".

I don't think that one sock size fits all, even though that is the way they are sold and I know that one shoe size does not fit all. I don't think that there is a definitive answer to which to load first, styles or script. It is more a case by case decision of what must be loaded in what order and what can be deferred until later as not being on the "critical path".

To speak to the observer that commented that it is better to delay the users ability to interact until the sheet is pretty. There are many of you out there and you annoy your counterparts that feel the opposite. They came to a site to accomplish a purpose and delays to their ability to interact with a site while waiting for things that don't matter to finish loading are very frustrating. I am not saying that you are wrong, only that you should be aware that there is another faction that exists that does not share your priority.

To speak to the observer that commented that it is better to delay the users ability to interact until the sheet is pretty. There are many of you out there and you annoy your counterparts that feel the opposite. They came to a site to accomplish a purpose and delays to their ability to interact with a site while waiting for things that don't matter to finish loading are very frustrating. I am not saying that you are wrong, only that you should be aware that there is another faction that exists that does not share your priority.

This question particularly applies to all of the ads being placed on web sites. I would love it if site authors rendered just placeholder divs for the ad content and made sure that their site was loaded and interactive before injecting the ads in an onload event. Even then I would like to see the ads loaded serially instead of all at once because they impact my ability to even scroll the site content while the bloated ads are loading. But that is just one persons point of view.

This question particularly applies to all of the ads being placed on web sites. I would love it if site authors rendered just placeholder divs for the ad content and made sure that their site was loaded and interactive before injecting the ads in an onload event. Even then I would like to see the ads loaded serially instead of all at once because they impact my ability to even scroll the site content while the bloated ads are loading. But that is just one persons point of view.

  • Know your users and what they value.
  • Know your users and what they value.
  • Know your users and what browsing environment they use.
  • Know your users and what browsing environment they use.
  • Know what each file does, and what its pre-requisites are. Making everything work will take precedence over both speed and pretty.
  • Know what each file does, and what its pre-requisites are. Making everything work will take precedence over both speed and pretty.
  • Use tools that show you the network time line when developing.
  • Use tools that show you the network time line when developing.
  • Test in each of the environments that your users use. It may be needed to dynamically (server side, when creating the page) alter the order of loading based on the users environment.
  • Test in each of the environments that your users use. It may be needed to dynamically (server side, when creating the page) alter the order of loading based on the users environment.
  • When in doubt, alter the order and measure again.
  • When in doubt, alter the order and measure again.
  • It is possible that intermixing styles and scripts in the load order will be optimal; not all of one then all of the other.
  • It is possible that intermixing styles and scripts in the load order will be optimal; not all of one then all of the other.
  • Experiment not just what order to load the files but where. Head? In Body? After Body? DOM Ready/Loaded? Loaded?
  • Experiment not just what order to load the files but where. Head? In Body? After Body? DOM Ready/Loaded? Loaded?
  • Consider async and defer options when appropriate to reduce the net delay the user will experience before being able to interact with the page. Test to determine if they help or hurt.
  • Consider async and defer options when appropriate to reduce the net delay the user will experience before being able to interact with the page. Test to determine if they help or hurt.
  • There will always be trade offs to consider when evaluating the optimal load order. Pretty vs. Responsive being just one.
  • There will always be trade offs to consider when evaluating the optimal load order. Pretty vs. Responsive being just one.

The linked article no longer claims "Stylesheet loads block script execution". Is that no longer true?

@Greg - It's still true. Scripts need to be able to query DOM .style attributes, so stylesheets still block script execution. They might not block script loading, if they're smart, but they will block script.onLoad events.

Is the recommendation to include CSS before JavaScript invalid? - Stac...

javascript css performance
Rectangle 27 6

Is the recommendation to include CSS before JavaScript invalid?

Not if you treat it as simply a recommendation. But if your treat it as a hard and fast rule?, yes, it is invalid.

Stylesheet loads block script execution, so if you have a <script> after a <link rel="stylesheet" ...> the page will not finish parsing - and DOMContentLoaded will not fire - until the stylesheet is loaded.

It appears that you need to know what each script relies on and make sure that execution of the script is delayed until after the right completion event. If the script relies only on the DOM, it can resume in ondomready/domcontentloaded, if it relies on images to be loaded or stylesheets to be applied, then if I read the above reference correctly, that code must be deferred until the onload event.

I don't think that one sock size fits all, even though that is the way they are sold and I know that one shoe size does not fit all. I don't think that there is a definitive answer to which to load first, styles or script. It is more a case by case decision of what must be loaded in what order and what can be deferred until later as not being on the "critical path".

To speak to the observer that commented that it is better to delay the users ability to interact until the sheet is pretty. There are many of you out there and you annoy your counterparts that feel the opposite. They came to a site to accomplish a purpose and delays to their ability to interact with a site while waiting for things that don't matter to finish loading are very frustrating. I am not saying that you are wrong, only that you should be aware that there is another faction that exists that does not share your priority.

This question particularly applies to all of the ads being placed on web sites. I would love it if site authors rendered just placeholder divs for the ad content and made sure that their site was loaded and interactive before injecting the ads in an onload event. Even then I would like to see the ads loaded serially instead of all at once because they impact my ability to even scroll the site content while the bloated ads are loading. But that is just one persons point of view.

  • Know your users and what they value.
  • Know your users and what browsing environment they use.
  • Know what each file does, and what its pre-requisites are. Making everything work will take precedence over both speed and pretty.
  • Use tools that show you the network time line when developing.
  • Test in each of the environments that your users use. It may be needed to dynamically (server side, when creating the page) alter the order of loading based on the users environment.
  • When in doubt, alter the order and measure again.
  • It is possible that intermixing styles and scripts in the load order will be optimal; not all of one then all of the other.
  • Experiment not just what order to load the files but where. Head? In Body? After Body? DOM Ready/Loaded? Loaded?
  • Consider async and defer options when appropriate to reduce the net delay the user will experience before being able to interact with the page. Test to determine if they help or hurt.
  • There will always be trade offs to consider when evaluating the optimal load order. Pretty vs. Responsive being just one.

The linked article no longer claims "Stylesheet loads block script execution". Is that no longer true?

@Greg - It's still true. Scripts need to be able to query DOM .style attributes, so stylesheets still block script execution. They might not block script loading, if they're smart, but they will block script.onLoad events.

Is the recommendation to include CSS before JavaScript invalid? - Stac...

javascript css performance