Passa al contingut principal

Default CSS Display Values for Different HTML Elements

Every element in an HTML document accepts a value for the CSS display property. The possible values you can use for display are many.


The three most commonly used values are none, block, and inline. But what if you don’t define a display value for an element? Well, all elements have an initial or default state for their display value. Let’s consider some of these and see some interesting things you might not have known.


Blocks and Text-flow Content


This one is pretty straightforward. I’ve covered block vs. inline before, but here’s a quick review.


Container-type elements (like <div>, <article>, <p>, etc.) will start out as block-level elements, so the computed value of the display property for these is “block”. All headers (<h1>, <h2>, etc.), even though they generally only contain text content, are likewise block elements by default.


On the other hand, elements that flow with text content are inline elements. That is, their computed display value is “inline”. These are elements like <span>, <em>,

and <cite>.


With both block and inline elements, you can (if you choose to) redefine their display value to something other than their default. Generally this is done in order to give an element a value of “none” or one of the alternate values (e.g. table). You can also change an inline element to block and vice-versa. But in most cases, this really is not the right choice. Instead, you’re better off using a different element altogether or otherwise rethinking what you’re trying to do.


Replaced Elements


In HTML, in addition to the elements already mentioned, there are also what are referred to as replaced elements. These include <img>, <input>, <select>, and <video>.


Although these are different from block and inline elements, they still have computed values for their display property. And they’re not always the same. For example, an <img> element, by default, is inline. Also, an <input> element is inline-block (which I’ve covered before).


Unknown Elements


Standards and accessibility advocates will hate me for telling you this, but the fact is, you don’t have to use any valid HTML5 elements in your documents. You could build an entire web page using your own made-up tags like <cookieMonster>, <potato>, and <sarcasm>.


So how would the browser read these foreign elements? Well, here’s a clue. Do you remember seeing this chunk of code in your CSS reset?



article,aside,details,figcaption,figure,
footer,header,hgroup,nav,section,summary {
display: block;
}

That’s added for older browsers (like IE6-8) that don’t recognize the new HTML5 elements. By default, in all browsers, all unknown elements have a computed display value of “inline”. Here’s a JS Bin that demonstrates this using a made-up element and then logging the display value of the element in the console.


And here’s another example with the same element given “block” status.


Invisible Elements


Here’s something you may not know is possible. HTML5 has a category of elements called document metadata. These include elements like <head>, <title>, and <style>. These elements, by default, are computed to display: none, as you can see by viewing the console in this JS Bin.


But, believe it or not, you can make them visible. Look at the screen shot taken below from the online version of Jeremy Keith’s HTML5 book:


Blocked title element on HTML5 for Web Designers


As shown in Chrome’s developer tools, the header for the site is styled by making the <title> element inside the <head> visible by means of display: block. In this case, both the <title> and <head> elements need to be blocked, not just the <title>.


This can also be done to make an element’s stylesheet editable by the user, as demonstrated in this JS Bin. We do this using the contenteditable attribute on the <style> element. In supporting browsers, with that attribute set to “true”, the user can make changes to the CSS and watch them take effect instantly.


Conclusion


Most of what I’ve discussed here has been covered, to some degree, before, so this might not all be new to everyone. If you know of any other interesting things about the default display values for various elements, or have any corrections/additions to anything I’ve said, I’d love to hear them.



Related posts:



  1. How is the DOM Affected by Improperly Nested HTML Elements?

  2. CSS3′s ‘space’ and ‘round’ Values for background-repeat

  3. How Do Browsers Render the Different CSS Border Style Values?








via Impressive Webs http://www.impressivewebs.com/default-css-display-values-html-elements/

Comentaris

Entrades populars d'aquest blog

10 alternativas a Cuevana para ver películas online

10 alternativas a Cuevana para ver películas online : Durante este último tiempo, en Cuevana se sucedieron varios “problemas” por los cuales hubo que ajustar algunas cosas antes de tiempo (como el rediseño del sitio), que dejaron a algunos usuarios ciertos problemas para acceder a las películas o series del portal. Pero realmente esto es algo que no incumbe a los usuarios y, como sabemos, existen muchas otras alternativas a Cuevana dando vueltas por Internet, que intentaremos presentar aquí mismo. Los sitios que repasaremos funcionan del mismo modo que Cuevana, mediante la instalación de un plugin que permite visualizar los videos de Megaupload o WUShare, entre otros servicios, en una calidad de imágen realmente excelente. Tal como sucede con el más popular servicio, todos ellos tienen publicidad que en algunos casos resulta insoportable, pero como dice Federico en DotPod “a caballo regalado no se le miran los dientes”. Alternativas a Cuevana 1. Moviezet Posiblemente el mejor clon d...

Learn Composition from the Photography of Henri Cartier-Bresson

“Do you see it?” This question is a photographic mantra. Myron Barnstone , my mentor, repeats this question every day with the hopes that we do “see it.” This obvious question reminds me that even though I have seen Cartier-Bresson’s prints and read his books, there are major parts of his work which remain hidden from public view. Beneath the surface of perfectly timed snap shots is a design sensibility that is rarely challenged by contemporary photographers. Henri Cartier-Bresson. © Martine Franck Words To Know 1:1.5 Ratio: The 35mm negative measures 36mm x 24mm. Mathematically it can be reduced to a 3:2 ratio. Reduced even further it will be referred to as the 1:1.5 Ratio or the 1.5 Rectangle. Eyes: The frame of an image is created by two vertical lines and two horizontal lines. The intersection of these lines is called an eye. The four corners of a negative can be called the “eyes.” This is extremely important because the diagonals connecting these lines will form the breakdown ...

Más de 50 de las mejores herramientas online para profesores

No es una exageración afirmar que hay ciento de aplicaciones educativas por ahí por la red, para todos los gustos y de todos los colores, por lo que es difícil tratar de recogerlas todas en un listado. Sin embargo, algunas destacan más que otras por su innovación y por su capacidad para conseguir adeptos, y esas son las que protagonizan la presente recopilación. Son 50 interesantes herramientas online basadas en las recopilaciones de EduArea , las muchas ya tratadas en Wwwhat’s new y las destacadas por la experiencia. 1. Dropbox : Un disco duro virtual con varios GB gratuitos y al que se accede desde casi cualquier dispositivo. Sin embargo, es muchísimo más que eso, de hecho ya comentamos 20 razones . 2. Google Drive : La evolución de Google Docs que suma a sus múltiples herramientas de creación de documentos, un considerable espacio virtual gratuito. 3. CloudMagic : Una extensión y una app multidispositivo para buscar información simultáneamente en Gmail, Twitter, Facebook, Evernote ...