Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I put viewport meta tag in jsfiddle

Tags:

html

css

jsfiddle

In jsFiddle I need to put viewport metatag in the head element. But since jsFiddle already includes html, head and body tags, it shows a warning: "No need for the HTML tag, it's already in the output."

Is there a way to put viewport metatag in the head?

<meta name="viewport" content="width=device-width, initial-scale=1" />
like image 955
Evgenii Avatar asked Jun 05 '13 00:06

Evgenii


People also ask

Where in the HTML document do we include the meta viewport tag?

Generally, meta elements (including viewport) should be placed in the document's <head> . CSS rules should either be added to a CSS stylesheet and referenced with a <link> element or, if you're not using stylesheets for some reason, in a <style> element (also in the document's <head> ).

What is meta viewport in HTML?

The viewport is the user's visible area of a web page. It varies with the device - it will be smaller on a mobile phone than on a computer screen. You should include the following <meta> element in all your web pages: <meta name="viewport" content="width=device-width, initial-scale=1.0">

Which tag is used to allow control over the viewport in HTML5?

HTML5 introduced a method to let web designers take control over the viewport, through the <meta> tag. This gives the browser instructions on how to control the page's dimensions and scaling.


1 Answers

One way to edit a jsFiddle's head tag is to use the CSS panel style hack.

If there is a need to edit the header, one can close the style element and access the header. After all modifications, please open the style tag again.

/* your custom CSS */
</style>
<!-- access to the HEAD element -->
<style>

Inserting the above code into the CSS panel will change the CSS section of the head to

<style type='text/css'>
/* your custom CSS */
</style>
<!-- access to the HEAD element -->
<style>
</style>

Alternatively, if you're a bit more flexible and are okay with editing the viewport after the page has been loaded, you may use JavaScript or jQuery.

JavaScript

var viewport = document.createElement("meta");
viewport.setAttribute('name', 'viewport');
viewport.setAttribute('content', 'width=device-width, initial-scale=1');
document.getElementsByTagName('head')[0].appendChild(viewport);

jQuery

$('head').append('<meta name="viewport" content="width=device-width, initial-scale=1" />');
like image 121
Saturnix Avatar answered Sep 26 '22 16:09

Saturnix