{"id":91,"date":"2019-03-08T11:34:19","date_gmt":"2019-03-08T11:34:19","guid":{"rendered":"https:\/\/www.samarthya.me\/wps\/?p=91"},"modified":"2019-08-23T09:21:16","modified_gmt":"2019-08-23T09:21:16","slug":"css-and-html-to-dom","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2019\/03\/08\/css-and-html-to-dom\/","title":{"rendered":"CSS and HTML to dom."},"content":{"rendered":"<figure id=\"attachment_150\" aria-describedby=\"caption-attachment-150\" style=\"width: 216px\" class=\"wp-caption alignright\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-150 size-medium\" src=\"https:\/\/www.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/IMG_20190815_143219-216x300.jpg\" alt=\"Fluttery shy bleeding\" width=\"216\" height=\"300\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/IMG_20190815_143219-216x300.jpg 216w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/IMG_20190815_143219-768x1066.jpg 768w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/IMG_20190815_143219-738x1024.jpg 738w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/IMG_20190815_143219.jpg 2029w\" sizes=\"(max-width: 216px) 100vw, 216px\" \/><figcaption id=\"caption-attachment-150\" class=\"wp-caption-text\"><span style=\"color: #0000ff;\">Happiness is not always straight lines<\/span>.<\/figcaption><\/figure>\n<div class=\"mceTemp\"><\/div>\n<p>Having worked on different technologies I never took HTML very seriously till a couple of years back. I started programming rather seriously programming when I was about 20 years old for a small startup then &#8211; FQSL. In those days, my primary responsibility was more around creating a middle &#8211; tier application which had a <em>management interface<\/em> and had the ability to spawn multiple threads to handle the incoming traffic and the main concern was to handle the load effectively and perform under pressure. This was all to be done in a native platform &#8220;Windows&#8221; and mostly in VC++ and MFC. Glad we are in <em>serverless<\/em> days now. \ud83d\ude42<\/p>\n<p>Jumping to today, and with the technology evolving every day; we have intelligent web-applications with very intuitive interface which makes it easier for the users (personas distinct) to manage their tasks in a smarter way. The things I used to do for native platforms is now effectively eased in a platform independent way (I like it so much).<\/p>\n<p>Many of my directs have been doing this for few years and I have been learning the new ways ever so eagerly. The subject that intrigued me the most was how this transformation is done. Hey don&#8217;t give me that look. I am coming from the background of Coding, Compiling, Linking and then executing \ud83d\ude00<\/p>\n<blockquote><p>How HTML is transformed from a markup language into this beautiful UI&#8217;s or DOM that the browser represents.<\/p><\/blockquote>\n<h2>What is CSS?<\/h2>\n<p>CSS is a language that allows the developer to define &#8211; how the document should be presented to the user.<\/p>\n<p>A browser applies this set of rules as defined in the CSS to the document to transform them into that beautiful document the designer has designed.<\/p>\n<h2>CSS Rule?<\/h2>\n<p>A rule is a simple condition like from left edge, I need my image to be few units away (Pixels, inches, or %)<\/p>\n<h2>CSS Building blocks<\/h2>\n<ol>\n<li>Properties<\/li>\n<li>Values<\/li>\n<li>Selectors ( A bigger topic )<\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline;\"><strong><em>Properties<\/em><\/strong><\/span> are the characteristic of the element you are specifying and the <span style=\"text-decoration: underline;\"><strong><em>values<\/em><\/strong><\/span> denotes the value that is being set for the element. Each property has an acceptable value list and each value presents a unique result.<\/p>\n<p>A property paired with a value is called <strong>a CSS declaration.<\/strong><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><strong>Ruleset <\/strong><\/p>\n<p style=\"text-align: center;\">CSS Declaration inside CSS Block { } separated by a semicolon and paired with a selector<\/p>\n<\/blockquote>\n<p>The <strong><em>CSS engine<\/em><\/strong> calculates which declarations apply to every single element of a page in order to appropriately lay it out and style it.<\/p>\n<blockquote><p>Property and value are both case sensitive.<\/p>\n<p>US spelling are preferred properties semantics<\/p>\n<p>In case of error or misspelling it will be ignored by the browser<\/p><\/blockquote>\n<figure id=\"attachment_156\" aria-describedby=\"caption-attachment-156\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"wp-image-156 size-large\" src=\"https:\/\/www.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/IMG_20190813_182605-1024x852.jpg\" alt=\"Follow guidelines\" width=\"1024\" height=\"852\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/IMG_20190813_182605-1024x852.jpg 1024w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/IMG_20190813_182605-300x250.jpg 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/IMG_20190813_182605-768x639.jpg 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption id=\"caption-attachment-156\" class=\"wp-caption-text\">CSS has a convention that allows you give structure the rules you define.<\/figcaption><\/figure>\n<h2>Selectors<\/h2>\n<p>Element that needs to be styled can be identified (distinctly or in bulk) by using these selectors. You target the HTML elements using selectors to style them.<\/p>\n<p>e.g.<\/p>\n<blockquote>\n<pre>p {\ncolor: black;\n}<\/pre>\n<\/blockquote>\n<h3>Categories of selectors<\/h3>\n<ol>\n<li>Simple selectors : Based on element type. (class or id)<\/li>\n<li>Attribute selectors: Based on attribute or attribute value.<\/li>\n<li>Pseudo classes: Based on the state<\/li>\n<li>Pseudo elements: Based on position<\/li>\n<li>Combinators: Combinations of selectos.<\/li>\n<li>Multiple selectors: comma separated.<\/li>\n<\/ol>\n<h4>Category 1 &#8211; Simple selector<\/h4>\n<p>Type selector<\/p>\n<blockquote><p>&lt;p&gt; Welcome &lt;\/p&gt;<\/p>\n<p>&lt;div&gt; I am a div &lt;\/div&gt;<\/p>\n<p>&lt;p&gt; Another Para &lt;\/p&gt;<\/p>\n<p>p {<\/p>\n<p>color: red;<\/p>\n<p>}<\/p><\/blockquote>\n<p>All p will be red here.<\/p>\n<h4>Class selector<\/h4>\n<blockquote><p>.myDiv {<\/p>\n<p>font-size: 2px;<\/p>\n<p>}<\/p><\/blockquote>\n<h2>How CSS works?<\/h2>\n<p>Browser is the window to the content the developer writes and the user consumes. When it displays the document (markup text file), it must combine the content with its style information.<\/p>\n<ol>\n<li>Converts HTML and CSS into a in-memory tree representation called DOM. Document Object model.<\/li>\n<li>Display the content.<\/li>\n<\/ol>\n<figure id=\"attachment_94\" aria-describedby=\"caption-attachment-94\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-medium wp-image-94\" src=\"https:\/\/www.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/Screenshot-2019-03-08-at-3.49.14-PM-300x126.png\" alt=\"\" width=\"300\" height=\"126\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/Screenshot-2019-03-08-at-3.49.14-PM-300x126.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/Screenshot-2019-03-08-at-3.49.14-PM-200x84.png 200w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2019\/03\/Screenshot-2019-03-08-at-3.49.14-PM.png 690w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-94\" class=\"wp-caption-text\">HTMLCSStoDOM<\/figcaption><\/figure>\n<h1>DOM<\/h1>\n<p>It is tree like structure where each element, attribute and the text in the markup becomes a DOM node in the structure.<\/p>\n<p>So it starts with parsing the HTML creates the DOM tree parses Style and applies it to each of the selected element.<\/p>\n<h2>How to apply CSS?<\/h2>\n<ol>\n<li>External Stylesheet. This is the most popular options that is recommended and is being used by the developers worldwide.<\/li>\n<\/ol>\n<blockquote><p>&lt;link rel=&#8221;stylesheet&#8221; href=&#8221;style.css&#8221;&gt;<\/p><\/blockquote>\n<p>2. Internal stylesheet<\/p>\n<blockquote><p>&lt;head&gt; &lt;style&gt; some style definitions &lt;\/style&gt; &lt;\/head&gt;<\/p><\/blockquote>\n<p>3. Inline style (This should be avoided)<\/p>\n<blockquote><p>&lt;h1 style=&#8221;&#8221;&gt;<\/p><\/blockquote>\n<p>We need to define how to tell our declaration blocks which elements they should be applied to and this is where we use the selectors.<\/p>\n<p>CSS rules are the most common statement one can see in a stylesheet, but there are other that one can define.<\/p>\n<ol>\n<li>@ rules : Used to convey the metadata or conditional information.<\/li>\n<\/ol>\n<h3>Example:<\/h3>\n<h4>Metadata<\/h4>\n<p>@charset<\/p>\n<p>@import &#8216;mywebsite.css&#8217; : Imports another CSS.<\/p>\n<h4>Conditional<\/h4>\n<p>@media: (Nested statements)<\/p>\n<blockquote><p>@media (min-width: 810 px) {<\/p>\n<p>body {<\/p>\n<p>margin: 5 auto;<\/p>\n<p>}<\/p><\/blockquote>\n<p>@document<\/p>\n<h2>Shorthand properties<\/h2>\n<p>Properties like font, margin are called shorthand properties, implying you can supply several values in a single line.<\/p>\n<blockquote>\n<pre class=\"brush: css line-numbers language-css\"><code class=\" language-css\"><span class=\"token property\">padding<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">10<\/span>px <span class=\"token number\">15<\/span>px <span class=\"token number\">15<\/span>px <span class=\"token number\">5<\/span>px<span class=\"token punctuation\">;<\/span><\/code><\/pre>\n<\/blockquote>\n<div class=\"mceTemp\"><\/div>\n<p>To be continued&#8230;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Having worked on different technologies I never took HTML very seriously till a couple of years back. I started programming rather seriously programming when I was about 20 years old for a small startup then &#8211; FQSL. In those days, my primary responsibility was more around creating a middle &#8211; tier application which had a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[11],"class_list":["post-91","post","type-post","status-publish","format-standard","hentry","category-others","tag-css"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/91","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=91"}],"version-history":[{"count":0,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/91\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}