{"id":139,"date":"2016-09-27T17:36:26","date_gmt":"2016-09-27T17:36:26","guid":{"rendered":"http:\/\/www.onlypsd2html.com\/blog\/?p=139"},"modified":"2016-09-27T17:53:52","modified_gmt":"2016-09-27T17:53:52","slug":"common-mistakes-in-css-at-convert-psd-to-html","status":"publish","type":"post","link":"https:\/\/www.onlypsd2html.com\/blog\/common-mistakes-in-css-at-convert-psd-to-html\/","title":{"rendered":"Common Mistakes in CSS At Convert PSD To HTML"},"content":{"rendered":"<p>There\u2019s more to writing good front-end code than knowing every HTML tag, CSS selector, or the latest front-end features and techniques.<\/p>\n<p>Using real-world examples found on several websites, let\u2019s take a look at common \u201cred flags\u201d to look for when writing code and evaluating its quality.<\/p>\n<p><strong>Complex, Overqualified Selectors<\/strong><\/p>\n<p>Look out for complex CSS selectors. For example:<\/p>\n<p>.wrapper .main .post a {&#8230;}<\/p>\n<p>These are one of the most \u201cexpensive\u201d selectors in CSS because browsers have to parse a lot of extra elements and selectors. Try to make your selectors as lean as possible:<\/p>\n<p>.post a {&#8230;}<\/p>\n<p>Instead of having an overly specific selector,\u00a0it\u2019s usually best to create a class for a particular element:<\/p>\n<p>.continue {&#8230;}<\/p>\n<p>Qualifiers in selectors should also be avoided, as they are not reusable, too specific, and create more work for the browser. The nav and p qualifiers in the following selectors are an example of this:<\/p>\n<p>nav.social {<\/p>\n<p>float: left;<\/p>\n<p>}<\/p>\n<p>p.intro {<\/p>\n<p>font-weight: bold;<\/p>\n<p>}<\/p>\n<p>What if at some point you need to use the .social class in a ul or the .intro class in a span? Avoid having to dig through your CSS to fix what you should have done correctly from the get-go, or worse, rewriting the rules unnecessarily.<\/p>\n<p><strong>Relying on Parent Selectors<\/strong><\/p>\n<p>A parent selector lowers the specificity of a child element. Sometimes you can\u2019t avoid them (with anchor elements, for example), but if you have selectors like the following:<\/p>\n<p>.sidebar {<\/p>\n<p>&#8230;<\/p>\n<p>}<\/p>\n<p>.sidebar .title {<\/p>\n<p>&#8230;<\/p>\n<p>}<\/p>\n<p>a better approach is using a namespace as a modifier.<\/p>\n<p>.sidebar {<\/p>\n<p>&#8230;<\/p>\n<p>}<\/p>\n<p>.sidebar-title {<\/p>\n<p>&#8230;<\/p>\n<p>}<\/p>\n<p>This keeps sidebar-title self-contained and modular \u2014\u00a0it doesn\u2019t rely on the parent selector and can be used anywhere.<\/p>\n<p><strong>Repeating CSS<\/strong><\/p>\n<p>Avoid repeating the same chunks of code. Look for property\/value pairs that are repeated multiple times throughout the stylesheet, then logically group them so that there\u2019s only one occurrence of that block of code.<\/p>\n<p>.label {<\/p>\n<p>display: inline-block;<\/p>\n<p>}<\/p>\n<p>.button {<\/p>\n<p>display: inline-block;<\/p>\n<p>border-radius: 10px;<\/p>\n<p>}<\/p>\n<p>.field {<\/p>\n<p>display: inline-block;<\/p>\n<p>border-radius: 10px;<\/p>\n<p>padding: 5px;<\/p>\n<p>}<\/p>\n<p>Always think \u201cDRY\u201d(Don\u2019t Repeat Yourself):<\/p>\n<p>.label,<\/p>\n<p>.button,<\/p>\n<p>.field {<\/p>\n<p>display: inline-block;<\/p>\n<p>}<\/p>\n<p>.button,<\/p>\n<p>.field {<\/p>\n<p>border-radius: 10px;<\/p>\n<p>}<\/p>\n<p>.field {<\/p>\n<p>padding: 5px;<\/p>\n<p>}<\/p>\n<p><strong>Resetting and Forcing CSS Values<\/strong><\/p>\n<p>Keep an eye out for rules where you are rewriting CSS properties or setting them back to their initial values. For example:<\/p>\n<p>h2 {<\/p>\n<p>font-size: 1.2em;<\/p>\n<p>font-weight: 700;<\/p>\n<p>padding-bottom: .5em;<\/p>\n<p>border-bottom: 1px solid;<\/p>\n<p>}<\/p>\n<p>h2 styles are then reset further down in another rule:<\/p>\n<p>.post h2 {<\/p>\n<p>font-weight: 500;<\/p>\n<p>padding-bottom: 0;<\/p>\n<p>border-bottom: none;<\/p>\n<p>}<\/p>\n<p>When adding new components, you shouldn\u2019t need to recode or undo patterns and problems you\u2019ve already solved with existing CSS. Instead, a better solution would be to create the following rules:<\/p>\n<p>h2 {<\/p>\n<p>font-size: 1.2em;<\/p>\n<p>}<\/p>\n<p>&#8230;<\/p>\n<p>.secondary-headline {<\/p>\n<p>font-weight: 700;<\/p>\n<p>padding-bottom: .5em;<\/p>\n<p>border-bottom: 1px solid;<\/p>\n<p>}<\/p>\n<p>.post-title {<\/p>\n<p>font-weight: 500;<\/p>\n<p>}<\/p>\n<p>Also, !important declarations should never be used to force a CSS value \u2013\u2013 avoid using them unless absolutely necessary.<\/p>\n<p>.last {<\/p>\n<p>border: none !important;<\/p>\n<p>}<\/p>\n<p>!important breaks the natural order of the cascade and, when abused, can lead to maintenance and specificity nightmares. There are few use cases for !important, for example: temporarily testing or debugging CSS issues, overriding certain inline styles when you have no control over the HTML, and aiding accessibility \u2013\u2013 just be careful with it.<\/p>\n<p><strong>Excessive Markup<\/strong><\/p>\n<p>Look for unnecessary use of HTML tags being used for layout:<\/p>\n<p>&lt;p&gt;&lt;h4&gt;UX &#8211; User Experience Design&lt;\/h4&gt;&lt;\/p&gt;<\/p>\n<p>There\u2019s no need to wrap the block-level h4 in a p. If you\u2019re using the &lt;p&gt; to give the &lt;h4&gt; extra margins or padding, that needs to be solved in the CSS instead.<\/p>\n<p><strong>IDs Instead of Classes<\/strong><\/p>\n<p>Avoid using an ID wherever you can use a class. IDs are heavy on specificity and cannot be reused. The nav ID shown below can only be used once in a page.<\/p>\n<p>&lt;ul id=&#8221;nav&#8221;&gt;<\/p>\n<p>&#8230;<\/p>\n<p>&lt;\/ul&gt;<\/p>\n<p>What if you need to add a nav component? Use classes instead:<\/p>\n<p>&lt;ul class=&#8221;main-nav\u00a0 nav&#8221;&gt;<\/p>\n<p>&#8230;<\/p>\n<p>&lt;\/ul&gt;<\/p>\n<p>&#8230;<\/p>\n<p>&lt;ul class=&#8221;footer-nav\u00a0 nav&#8221;&gt;<\/p>\n<p>&#8230;<\/p>\n<p>&lt;\/ul&gt;<\/p>\n<p>.nav a {<\/p>\n<p>display: block;<\/p>\n<p>color: white;<\/p>\n<p>padding: 5px;<\/p>\n<p>}<\/p>\n<p>.main-nav a {<\/p>\n<p>border-bottom: 1px solid;<\/p>\n<p>font-size: 1.1em;<\/p>\n<p>}<\/p>\n<p>.footer-nav a {<\/p>\n<p>border-bottom: 1px dotted grey<\/p>\n<p>font-size: .85em;<\/p>\n<p>}<\/p>\n<p>It\u2019s best to use IDs as JavaScript hooks or as fragment identifiers in a page. Certainly avoid using one ID for styling, JavaScript, and as a fragment identifier. Doing so will make your architecture fragile because you\u2019re setting up dependencies among CSS, JavaScript, and the fragment identifier.<\/p>\n<p><strong>Closing Thoughts<\/strong><\/p>\n<p>Front-end code that is poorly thought-out can be a strain on maintenance and development in the long run. When writing code, your goal should be making sure that it\u2019s reusable, maintainable, and scalable. Your CSS should also be predictable, so if you need to update or add new components, they shouldn\u2019t affect other parts of your site.<\/p>\n<p>Keep in mind that at some point your site or application will need to scale, which might require more developers working on and maintaining the code. That\u2019s why it\u2019s important to write code that can be easily managed by designers and developers who are looking at our code for the first time.<\/p>\n<p>Are You Looking For Best <a href=\"http:\/\/www.onlypsd2html.com\/psd-to-html.html\" target=\"_blank\">PSD To HTML<\/a> &amp; <a href=\"http:\/\/www.onlypsd2html.com\/psd-to-html5.html\" target=\"_blank\">PSD To HTML5<\/a> Conversion Service Than Visit Our Website<\/p>\n<p><a href=\"http:\/\/www.onlypsd2html.com\" target=\"_blank\">http:\/\/www.onlypsd2html.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"There\u2019s more to writing good front-end code than knowing every HTML tag, CSS [&hellip;]","protected":false},"author":1,"featured_media":141,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,7],"tags":[5,4,10,23],"class_list":["post-139","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-psd-to-bootstrap","category-psd-to-html","tag-convert-psd-to-html-bootstrap","tag-convert-psd-to-html-using-bootstrap","tag-psd-to-html","tag-psd-to-html5"],"_links":{"self":[{"href":"https:\/\/www.onlypsd2html.com\/blog\/wp-json\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.onlypsd2html.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.onlypsd2html.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.onlypsd2html.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.onlypsd2html.com\/blog\/wp-json\/wp\/v2\/comments?post=139"}],"version-history":[{"count":2,"href":"https:\/\/www.onlypsd2html.com\/blog\/wp-json\/wp\/v2\/posts\/139\/revisions"}],"predecessor-version":[{"id":143,"href":"https:\/\/www.onlypsd2html.com\/blog\/wp-json\/wp\/v2\/posts\/139\/revisions\/143"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.onlypsd2html.com\/blog\/wp-json\/wp\/v2\/media\/141"}],"wp:attachment":[{"href":"https:\/\/www.onlypsd2html.com\/blog\/wp-json\/wp\/v2\/media?parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.onlypsd2html.com\/blog\/wp-json\/wp\/v2\/categories?post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.onlypsd2html.com\/blog\/wp-json\/wp\/v2\/tags?post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}