{"id":88,"date":"2025-03-21T16:45:00","date_gmt":"2025-03-21T16:45:00","guid":{"rendered":"https:\/\/kingstatue.com\/?p=88"},"modified":"2025-03-21T16:45:00","modified_gmt":"2025-03-21T16:45:00","slug":"css","status":"publish","type":"post","link":"https:\/\/www.kingstatue.com\/?p=88","title":{"rendered":"CSS"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><strong>What is CSS?<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>CSS (Cascading Style Sheets)<\/strong> is a stylesheet language used to control the presentation and layout of HTML documents. It defines how elements appear on a webpage, including their colors, fonts, spacing, and positioning.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why Use CSS?<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Separation of Content &amp; Design:<\/strong> Keeps HTML clean by separating structure from styling.<\/li>\n\n\n\n<li><strong>Consistency:<\/strong> Ensures uniform styling across multiple pages.<\/li>\n\n\n\n<li><strong>Efficiency:<\/strong> A single CSS file can style multiple HTML documents.<\/li>\n\n\n\n<li><strong>Responsive Design:<\/strong> Adapts layouts for different screen sizes (mobile, tablet, desktop).<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Types of CSS<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Inline CSS:<\/strong> Applied directly within an HTML tag using the <code>style<\/code> attribute.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;p style=\"color: blue; font-size: 18px;\"&gt;<\/code>\n      <code>This is inline CSS.<\/code>\n<code>&lt;\/p&gt;\n<\/code>\n<strong>Pros:<\/strong> Quick and applies to a single element.\n<strong>Cons:<\/strong> Not reusable and clutters HTML.\n\n<strong>Internal <\/strong>CSS: Defined within the &lt;style&gt; tag inside the HTML &lt;head&gt;.\n&lt;style&gt;\n    p {\n        color: green;\n        font-size: 20px;\n    }\n&lt;\/style&gt;\nPros: Useful for styling a single page.\nCons: Not reusable across multiple pages.\n\n<strong>External <\/strong>CSS: Stored in a separate .css file and linked to an HTML file.\n&lt;link rel=\"stylesheet\" href=\"styles.css\"&gt;\nContent of file style.css\np {\n    color: red;\n    font-size: 22px;\n}\nPros: Best for large projects, reusable, and maintains clean HTML.\nCons: Requires an external file, which needs to be loaded.<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Key CSS Properties<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Text Styling:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>body {<br>    font-family: Arial, sans-serif;<br>    font-size: 16px;<br>    color: black;<br>}<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Backgrounds &amp; Colors:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>body {<br>    background-color: lightgray;<br>}<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Box Model (Margin, Padding, Border, Width, Height):<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>div {<br>    width: 200px;<br>    height: 100px;<br>    padding: 10px;<br>    margin: 20px;<br>    border: 2px solid black;<br>}<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Positioning &amp; Layout:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>.container {<br>    display: flex;<br>    justify-content: center;<br>    align-items: center;<br>}<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Responsive Design (Media Queries):<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>@media (max-width: 600px) {<br>    body {<br>        background-color: yellow;<br>    }<br>}<\/code><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<pre class=\"wp-block-code\"><code>width: 200px;  <br>height: 100px;  <br>padding: 10px;  <br>margin: 20px;  <br>border: 2px solid black;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1.&nbsp;<code>width: 200px;<\/code><\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Sets the&nbsp;<strong>content width<\/strong>&nbsp;of the element to&nbsp;<strong>200 pixels<\/strong>.<\/li>\n\n\n\n<li>It&nbsp;<strong>does not include<\/strong>&nbsp;padding, margin, or border.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2.&nbsp;<code>height: 100px;<\/code><\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Sets the&nbsp;<strong>content height<\/strong>&nbsp;to&nbsp;<strong>100 pixels<\/strong>.<\/li>\n\n\n\n<li>Like&nbsp;<code>width<\/code>, it does not include padding, margin, or border.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3.&nbsp;<code>padding: 10px;<\/code><\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Adds&nbsp;<strong>space inside<\/strong>&nbsp;the element, between the content and the border.<\/li>\n\n\n\n<li>It&nbsp;<strong>increases the total size<\/strong>&nbsp;of the element.<\/li>\n\n\n\n<li>Example: If&nbsp;<code>width: 200px<\/code>&nbsp;and&nbsp;<code>padding: 10px<\/code>, the actual width becomes&nbsp;<strong>220px<\/strong>&nbsp;(<code>200px + 10px left + 10px right<\/code>).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4.&nbsp;<code>margin: 20px;<\/code><\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Adds&nbsp;<strong>space outside<\/strong>&nbsp;the element, creating separation from other elements.<\/li>\n\n\n\n<li>It does&nbsp;<strong>not affect the element\u2019s actual size<\/strong>, only its position.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5.&nbsp;<code>border: 2px solid black;<\/code><\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Adds a&nbsp;<strong>2-pixel thick<\/strong>&nbsp;solid&nbsp;<strong>black<\/strong>&nbsp;border around the element.<\/li>\n\n\n\n<li>The border adds to the element\u2019s total size.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Total Element Size (Box Model Calculation)<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By default, the&nbsp;<strong>content-box model<\/strong>&nbsp;is used, meaning the total size is calculated as:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Total Width<\/strong>&nbsp;=&nbsp;<code>width + left padding + right padding + left border + right border<\/code><br><strong>Total Height<\/strong>&nbsp;=&nbsp;<code>height + top padding + bottom padding + top border + bottom border<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For the given example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Width<\/strong>&nbsp;=&nbsp;<code>200px + 10px + 10px + 2px + 2px = 224px<\/code><\/li>\n\n\n\n<li><strong>Height<\/strong>&nbsp;=&nbsp;<code>100px + 10px + 10px + 2px + 2px = 124px<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If&nbsp;<code>box-sizing: border-box;<\/code>&nbsp;is applied, then&nbsp;<code>width<\/code>&nbsp;and&nbsp;<code>height<\/code>&nbsp;include padding and border, keeping the total size fixed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">.box {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp; width: 200px;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp; height: 100px;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp; padding: 10px;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp; margin: 20px;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp; border: 2px solid black;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp; background-color: black;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udccc This will create a box with:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">black background<br>200px width and 100px height (content area)<br>10px padding inside<br>20px margin outside<br>2px solid black border<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">CSS is essential for designing modern websites, improving user experience, and ensuring responsive layouts. By using external CSS, following best practices, and leveraging properties effectively, you can create visually appealing and accessible web pages.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is CSS? CSS (Cascading Style Sheets) is a stylesheet language used to control the presentation and layout of HTML documents. It defines how elements appear on a webpage, including&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-88","post","type-post","status-publish","format-standard","hentry","category-cascading-style-sheet"],"_links":{"self":[{"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=\/wp\/v2\/posts\/88","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=88"}],"version-history":[{"count":0,"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=\/wp\/v2\/posts\/88\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kingstatue.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}