hitjethva
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # A Complete Guide to CSS fundamentals ## Introduction When we talk about CSS, it's feel really hard and it's too much of a hassle to learn. Because some people think CSS is not any programming language. So it will be easily to learn and understand concepts. But, ultimately it's not that easy to get master, there is lot of CSS fundamentals that you should know about. I am going to explore some of the important parts of CSS that we used on our daily basis. ## CSS Fundamentals Here, I am going to explore some of the most important CSS Fundamentals which is required for our daily works. ## CSS syntax There are three important parts of CSS - selectors, properties, and values. 1. **Selectors** - the elements are being selected 2. **Properties** - the elements that are being styled 3. **Values** - the styles that are used **Example:-** ``` selector { properties:value; } ``` ## CSS Selector Here, are the one of the most important types of selector:- * [Universal Selector](https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors):- it selects all the elements. * [Type Selector](https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors):- it targets a particular elements by using HTML Tag. * [Class selector](https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors), [Attribute Selector](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors):- you can target a particular elements by using class or attributes. * [ID selector](https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors):- it lets you target element by using ID. ``` * { /* Universal selector */ } tag { /* Type selector of the HTML tag */ } tag::before { /* Type selector */ } .class { /* Class selector */ } .class:hover { /* Class selector */ } [attr] { /* Attribute selector */ } #id { /* ID selector */ } ``` ## CSS Properties Here is a list of all the CSS attributes that, in my opinion, are a must-know. These are properties will able todo anything. ``` padding, margin, border background color, font-family, font-weight, font-size, line-height width, height, max-width, max-height ``` **Layouts** ``` position, z-index, top, right, bottom, left display, flex, align-items, justify-content @media ``` ## Box Model CSS displays everything as a box. So, one of the fundamental building blocks of CSS is understanding how the CSS Box Model functions. Based on their display value, predetermined size, and inside content, boxes behave differently. Additional boxes created by child components or simple text content might make up this content. In any case, the size of the box will be impacted by this content by default. Use extrinsic sizing to take control over this, or use intrinsic sizing to continue letting the browser decide depending on the size of the content. Boxes are composed of separate box model sections, each of which performs a specialised function. ![box-model](https://i.imgur.com/PR5HUAY.jpg) Here, is the explanation for the box model. * **Content** - The content of the box, where text and images appear * **Padding** - Clears an area around the content. The padding is transparent * **Border** - A border that goes around the padding and content * **Margin** - Clears an area outside the border. The margin is transparent. ## Flexbox Flexbox is a layout tool created for arranging collections of things in a single dimension. Use this module to learn how to use it. A sidebar that is positioned inline with certain content is a design element that might be challenging in responsive design. This pattern works well when there is room in the viewport, but when there isn't much room, the inflexible design can cause issues. For one-dimensional content, the Flexible Box Layout Model (flexbox) is a layout model. It excels at returning the optimal arrangement for a collection of things with varying sizes. **What is a flex layout good for?** 1. They can show up as either a row or a column. 2. They respect the document's style of writing. 3. By default, they are single lines, but you can request that they wrap onto more than one line. 4. The layout's elements can have their visual order changed such that it differs from the DOM's order. 5. The distribution of space allows the objects to change in size in accordance with the volume of their parent. 6. Using the Box Alignment settings, space can be added around the elements and flex lines in a wrapped layout. 7. On the cross axis, the elements themselves can be oriented. **Flex Contanier Reference:** | Property | Values | | -------- | -------- | | flex-direction | row, column, row-reverse, column-reverse | | flex-wrap | wrap, nowrap | | align-items | flex-start, flex-end, center, stretch, baseline | | justify-content | start, center, end, space-between, space-around, space-evenly | ### Creating a Flex Container We already know that a bunch of default block elements will stack each other: ``` <section> <div>div 1</div> <div>div 2</div> <div>div 3</div> <div>div 4</div> </section> ``` ![flex_Container](https://i.imgur.com/4tHPwik.png) So Know, how we can able to make elements side-by-side, this can happen using flex container. ``` <section class="flex-container"> <div>div 1</div> <div>div 2</div> <div>div 3</div> <div>div 4</div> </section> ``` ``` .flex-container { display: flex; } ``` ![flex_conatiner1](https://i.imgur.com/3hKYxSo.png) Here, you can see that inner elements are aligned in a horizontally. By default, a flex container is set to `flex-direction:row`. you can also update the inner elements in a column wise using `flex-direction: column` Know, let's take an example to demonstrate the Flex. so, here we are going to create navigation bar with flex. Here, are the list what navigation bar will look like:- 1. Logo name to the left hand side 2. nav links to the right hand side 3. all items vertically centered ``` <nav> <div>Brand name</div> <div> <a href="#!">About</a> <a href="#!">Contact</a> </div> </nav> ``` ``` nav { background: blue; height: 80px; } ``` Here, how the layout will looks. ![flex-3](https://i.imgur.com/cTKS3Vc.png) We'll make the navbar flex, so the brand name and nav links will be horizontal. ``` nav { display: flex; } ``` ![flex-4](https://i.imgur.com/1Oi9Tzk.png) Now we want everything to be vertically aligned. With `align-items: center`, we can vertically align items within a flex container. ``` nav { display: flex; align-items: center; } ``` ![flex-5](https://i.imgur.com/NNCTEbh.png) Now we want the brand and links to be on opposite ends of the navbar. With `justify-content: space-between`, we can tell the items in the flex container to be spaced apart as far as possible. ``` nav { display: flex; align-items: center; justify-content: space-between; } ``` ![flex-6](https://i.imgur.com/0WKJl7m.png) After that just little padding and having a proper navbar with good spacing. ![flex-7](https://i.imgur.com/ALLcxr2.png) ## Grid CSS Grid Layout provides a two dimensional layout system, controlling layout in rows and columns. In this module discover everything grid has to offer. It's crucial to comprehend the vocabulary before delving into the principles of Grid. If you don't initially commit to memory the definitions provided by the Grid specification for the terminology used in this context, it's easy to confuse them with one another because they are all conceptually quite similar. But fear not—they are few in number. 1. **Grid Container**:- The element on which display: grid is applied. It’s the direct parent of all the grid items. In this example container is the grid container. 2. **Grid Item**:- The children (i.e. direct descendants) of the grid container. Here the item elements are grid items, but sub-item isn’t. 3. **Grid Line**:- The dividing lines that make up the structure of the grid. They can be either vertical (“column grid lines”) or horizontal (“row grid lines”) and reside on either side of a row or column. Here the yellow line is an example of a column grid line. 4. **Grid Cell**:- The space between two adjacent row and two adjacent column grid lines. It’s a single “unit” of the grid. ### Creating Grid A gallery frequently contains a number of cards or images that ought to be arranged in a repeating grid. The horizontal items in a flex container will always be horizontal by default. ``` <section class="flex-container"> <div>div 1</div> <div>div 2</div> ... </section> ``` ``` .flex-container { display: flex; } ``` ![grid](https://i.imgur.com/4IKdjny.png) We can make the grid repeat onto as many lines as necessary with flex-wrap. ``` .flex-container { display: flex; flex-wrap: wrap; } ``` ![grid-wrap](https://i.imgur.com/LPvWOPQ.png) ## Responsive: Media Queries If you want to make your websites responsive use media queries. because it helps to adapt your websites through mutliple screen size. With the help of media query you let CSS to handle your screen size below on a certain width or above certain width. ``` @media screen and (min-width: 800px) { /* styles to any device screen sizes above 800px wide */ } ``` ``` @media screen and (max-width: 800px) { /* styles to any device screen sizes below 800px wide */ } ``` If you've ever heard of the phrase "mobile-first," it means constructing a website first for mobile devices and adding` min-width` media queries as needed as screen sizes increase. ``` @media screen and (min-width: 800px) { /* styles go here */ } ``` >**Note:**- @media queries can be nested inside a selector. In this example, an h1 has font size of 38px by default, but 22px on larger screen sizes. ``` h1 { font-size: 38px; @media screen and (min-width: 800px) { font-size: 22px; } } ``` **Example:** media enquiries can help to include a breakpoint where specific components of the design will act differently on either side. ``` <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> * { box-sizing: border-box; } .row::after { content: ""; clear: both; display: block; } [class*="col-"] { float: left; padding: 15px; } html { font-family: "Lucida Sans", sans-serif; } .header { background-color: #9933cc; color: #ffffff; padding: 15px; } .menu ul { list-style-type: none; margin: 0; padding: 0; } .menu li { padding: 8px; margin-bottom: 7px; background-color: #33b5e5; color: #ffffff; box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); } .menu li:hover { background-color: #0099cc; } .aside { background-color: #33b5e5; padding: 15px; color: #ffffff; text-align: center; font-size: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); } .footer { background-color: #0099cc; color: #ffffff; text-align: center; font-size: 12px; padding: 15px; } /* For desktop: */ .col-1 {width: 8.33%;} .col-2 {width: 16.66%;} .col-3 {width: 25%;} .col-4 {width: 33.33%;} .col-5 {width: 41.66%;} .col-6 {width: 50%;} .col-7 {width: 58.33%;} .col-8 {width: 66.66%;} .col-9 {width: 75%;} .col-10 {width: 83.33%;} .col-11 {width: 91.66%;} .col-12 {width: 100%;} @media only screen and (max-width: 768px) { /* For mobile phones: */ [class*="col-"] { width: 100%; } } </style> </head> <body> <div class="header"> <h1>Tourist Place</h1> </div> <div class="row"> <div class="col-3 menu"> <ul> <li>The Flight</li> <li>The City</li> <li>The Island</li> <li>The Food</li> </ul> </div> <div class="col-6"> <h1>The City</h1> <p>Sydney is the capital of the Australia region on the island of Crete. The city can be divided in two parts, the old town and the modern city.</p> </div> <div class="col-3 right"> <div class="aside"> <h2>What?</h2> <p>Sydney is a city on the island of Crete.</p> <h2>Where?</h2> <p>Crete is a Greek island in the Mediterranean Sea.</p> <h2>How?</h2> <p>You can reach Sydney airport from all over Europe.</p> </div> </div> </div> <div class="footer"> <p>Resize the browser window to see how the content respond to the resizing.</p> </div> </body> </html> ``` Here, is the output for the responsive as shown below. 1) Desktop Mode ![dekstop_mode](https://i.imgur.com/HtuYxVd.png) 2) Mobile Mode ![mobile_mode](https://i.imgur.com/zl1EzQ7.png) ## Conclusion Read the theory of CSS first to understand what it is, how it functions in browsers, and the fundamental syntax and usage. Because getting fundamentals understanding better will lead you to understand any library easily. In order to better understand CSS foundations, I have attempted to keep this in mind. I think this will be very helpful to you. Gratitude for reading.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully