{"id":13,"date":"2018-01-12T13:18:37","date_gmt":"2018-01-12T13:18:37","guid":{"rendered":"http:\/\/efelti.com\/tech\/?p=13"},"modified":"2020-11-11T22:03:00","modified_gmt":"2020-11-11T22:03:00","slug":"enhancing-styling-flexibility-by-using-css-for-html-files","status":"publish","type":"post","link":"https:\/\/efelti.com\/tech\/?p=13","title":{"rendered":"Enhancing Styling Flexibility by Using CSS for HTML files"},"content":{"rendered":"\n<p>There are a lot of talks how to make an HTML page more flexible to style by using CSS files without touching HTML file.<\/p>\n\n\n\n<p>This sample pages where for a same HTML page we have different kinds of styles from a competition to show the power of CSS:&nbsp;<a href=\"https:\/\/www.blogger.com\/blog\/post\/edit\/8516031187236147880\/2882807452470691350#\">CSS Zen Garden &#8211; Beauty of CSS Design<\/a>&nbsp;in the page you can display&nbsp;<a href=\"https:\/\/www.blogger.com\/blog\/post\/edit\/8516031187236147880\/2882807452470691350#\">all of designs<\/a>&nbsp;using same HTML file without changing it. Totally different styles which also includes responsive UI and animations.<\/p>\n\n\n\n<p>Is each HTML file always like this? There are some hints of do-s or don&#8217;t-s developers need to take care to avoid the rigidity of styling.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Avoid CSS inline style as much as possible<\/h2>\n\n\n\n<p>Inline style is not un-useful for simplicity e.g. if we want to style HTML e-mail, or a single static page where we does not have capability to include external styling file.<br>But once we plan to have dynamic styled page, we need to avoid it as possible (since the internet browser will prioritize inline style (embedded style) higher than CSS file style from external source).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Have HTML with Structural Semantic instead of Content Only<\/h2>\n\n\n\n<p>Instead of having unstructured content, in case there are structural concept of the page, structure it using structural semantic. If you are working with HTML5, use the semantic tags (main, sections, navigations, headings, headers, footers, figures, etc.). If you are using previous HTML versions use div and span semantics to structure the page.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Define Class(es) for Each of HTML Structural Section<\/h2>\n\n\n\n<p>Define class(es) of each structural section of the HTML pages make it more easier to select it within CSS instead of complex selection using tagging. It will make the code also more readable for the CSS files for the sections to be styled.<br>If I am talking about structural section, I did not mean only for section tag of HTML5 but also for div, span, table, li, nav, etc, anything related with structural semantic which are not content related (like paragraph, etc.).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Avoid of Using of br-tag for Styling Space<\/h2>\n\n\n\n<p>The br-tag is useful to create line break inside content. But br-tag should not be use for styling. Style the spaces using margin and padding feature in CSS instead.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Use Shadow DOM Selector in case of Working with Capsulated Components<\/h2>\n\n\n\n<p>In case you are working with components, e.g. using Angular Framework, React, etc. Your CSS inside the component seems to be un-editable. You might think you can&#8217;t edit it from parent component. However this is not true.<br>Components based frameworks use so called Shadow-DOM technology. You can still modify the HTML styles from parent using Shadow-DOM selector (:host etc.) without changing the HTML of the sub-components.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Useful Links<\/h2>\n\n\n\n<p>Other references:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>CSS<ul><li><a href=\"https:\/\/www.blogger.com\/blog\/post\/edit\/8516031187236147880\/2882807452470691350#\">CSS &#8211; w3.org<\/a><\/li><li><a href=\"https:\/\/www.blogger.com\/blog\/post\/edit\/8516031187236147880\/2882807452470691350#\">CSS &#8211; W3School<\/a><\/li><li><a href=\"https:\/\/www.blogger.com\/blog\/post\/edit\/8516031187236147880\/2882807452470691350#\">CSS Selector Reference<\/a><\/li><\/ul><\/li><li>HTML5 and new structural semantics<ul><li><a href=\"https:\/\/www.blogger.com\/blog\/post\/edit\/8516031187236147880\/2882807452470691350#\">HTML5<\/a><\/li><\/ul><\/li><li>Shadow DOM<ul><li><a href=\"https:\/\/www.blogger.com\/blog\/post\/edit\/8516031187236147880\/2882807452470691350#\">Shadow DOM &#8211; w3.org<\/a><\/li><li><a href=\"https:\/\/www.blogger.com\/blog\/post\/edit\/8516031187236147880\/2882807452470691350#\">Shadow DOM v1: Self-Contained Web Components<\/a><\/li><li><a href=\"https:\/\/www.blogger.com\/blog\/post\/edit\/8516031187236147880\/2882807452470691350#\">Shadow DOM &#8211; MDN Web Doc<\/a><\/li><\/ul><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>There are a lot of talks how to make an HTML page more flexible to style by using CSS files without touching HTML file. This sample pages where for a same HTML page we have different kinds of styles from a competition to show the power of CSS:&nbsp;CSS Zen Garden &#8211; Beauty of CSS Design&nbsp;in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":15,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[2,5],"class_list":["post-13","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-clean-code","tag-clean-code","tag-ui-ux"],"_links":{"self":[{"href":"https:\/\/efelti.com\/tech\/index.php?rest_route=\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/efelti.com\/tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/efelti.com\/tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/efelti.com\/tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/efelti.com\/tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":1,"href":"https:\/\/efelti.com\/tech\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":14,"href":"https:\/\/efelti.com\/tech\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions\/14"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/efelti.com\/tech\/index.php?rest_route=\/wp\/v2\/media\/15"}],"wp:attachment":[{"href":"https:\/\/efelti.com\/tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/efelti.com\/tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/efelti.com\/tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}