translation

This is an AI translated post.

뚠뚠멍의 생각들

Basic CSS Rules (Normal flow, BFC, IFC)

Select Language

  • English
  • 汉语
  • Español
  • Bahasa Indonesia
  • Português
  • Русский
  • 日本語
  • 한국어
  • Deutsch
  • Français
  • Italiano
  • Türkçe
  • Tiếng Việt
  • ไทย
  • Polski
  • Nederlands
  • हिन्दी
  • Magyar

Summarized by durumis AI

  • Understanding block elements, inline elements, margin, and alignment is crucial when structuring CSS layouts. BFC (Block Formatting Context) is particularly useful for layout configuration.
  • BFC is the way block-level elements are stacked. It allows you to set width, height, margin, and padding, and is used for interactions with floats or handling margin collapsing.
  • IFC (Inline Formatting Context) is structured within block elements. It does not allow direct setting of width and height, and only horizontal padding and margin can be applied.


When drawing HTML CSS, the layout may not be organized as you think.

I've had a lot of experience asking Google.


Recently, I watched Zerocho's developer talk video and decided to learn about the basics of CSS.

- I want to understand block elements, inline elements, margins, and alignment.


I already know this empirically, but I need to organize it.

■ If you need to modify css, applying things empirically and implementing them as you see them will cause problems in responsive design or make it more complex to maintain later.


1. Normal Flow

- There's nothing special to think about. All elements are placed from top to bottom and from left to right.

* When you paste HTML tags into a durumis post, they disappear. Do you know how to solve this? ;;

 <div>
     <p>First paragraph</p>
     <p>Second paragraph</p>
     <span>Inline element 1</span>
     <span>Inline element 2</span>

- Two blocks are created with the p tag, and the span tag is drawn in one line.

 First paragraph
 Second paragraph



2. BFC (Block Formatting Context)

- It is mainly used to construct layouts. (Blocks are constructed, and inlines are constructed inside them.)

- It is the way block-level elements are stacked.

- Block-level elements are as follows:

<div>, <p>, <h1>~<h6>, <ul>, <ol>, <li>, <table>, <form>

- It takes up the entire width of the parent element regardless of the length of the content inside the element. (One line)

- You can put a block inside a block, or you can put an inline element inside it.

- You can set width, height, margin, and padding.

 <div style="padding :10px;"> 
     <h1>Title</h1>
     <p>This is a short paragraph.</p>

- Two lines are generated inside the div tag.

- BFC is created in the following cases. You can look it up whenever you need it.

  • If the float property is not none
  • If position is absolute or fixed
  • If display is inline-block, table-cell, table-caption, flex, inline-flex, grid, inline-grid
  • If overflow is not visible, etc.


3. IFC (Inline Formatting Context)

<p>
    Hello! <strong> durumis </strong> This is the second post!
    <span style="color: pink;">좋아요</button> Click the button.

- It is configured within a block element. (No line by line)

- You cannot set width and height directly. (It takes up the size of the content.)

- You can only apply horizontal padding and margins.

- You can only include inline elements within an inline element.

<span>, <a>, , <img>, <input>, etc.


So, when do you use it?

- bfc is used to handle float interactions or margin offsets.


1. float interaction

- If you apply a free-spirited style to a child, the parent cannot wrap it.

(float, position absolute, fixed, display inline-block, etc...)

- At this time, the layout is configured by giving the parent element a bfc.

(Apply display: inline-block, overflow: auto, float: left, etc. to the parent tag.)

<div class="parent" style="display: inline-block;">
    <div class="child" style="float: left;">...</div>


2. Margin offset

- css overlaps the top and bottom margins of two adjacent tags.

ex) The vertical space between the two div tags below is 100px, not 150px.

<div style="margin-bottom: 100px;">
..
</div>
<div style="margin-top: 50px;">
,,

- Add a new bfc element between the two tags in the situation above.


<div style="margin-bottom: 100px;"></div> 

<div style="overflow: auto;"></div> <!-- new bfc-->


ps. Do you know how to copy and paste durumis html? ;;

뚠뚠멍
뚠뚠멍의 생각들
뚠뚠멍의 생각들
뚠뚠멍
React - How to fix the 'kakao is not defined' error This article explains the solution and reasons for the error that occurs when integrating the Kakao Map API in a React 18, create-react-app environment. It also explains why React components do not directly access global objects, and provides an efficient

September 2, 2024

Writing my first post on durumis durumis is a platform that automatically translates articles into 18 languages and provides various formatting functions such as bold, italic, and underline. While it does not yet support adding spaces between code blocks and quotes, you can use Shift+Ent
이것저것 잡다한 이야기
이것저것 잡다한 이야기
이것저것 잡다한 이야기
이것저것 잡다한 이야기

April 14, 2024

The Complete Guide to CSS object-fit Property The CSS object-fit property allows you to consistently display images with varying sizes and aspect ratios when they are displayed on a web page. This property determines how the image is cropped or resized to fit the container size, making it an essentia
Meursyphus
Meursyphus
Meursyphus
Meursyphus

July 14, 2024

FAQ related to writing articles Check out frequently asked questions and answers when writing articles using the durumis AI blog writing tool. It includes explanations of various features such as line breaks, fonts, titles, image descriptions, preview articles, and more.
durumis official blog
durumis official blog
picture of FAQ
durumis official blog
durumis official blog

January 25, 2024

FAQ Collection Durumis is a free beta service that provides various features such as automatic translation, summarization, and topic generation after writing. Currently, writing is not supported on mobile devices, and features such as comments, scheduled publishing, and
durumis official blog
durumis official blog
Picture with FAQ written on it
durumis official blog
durumis official blog

January 24, 2024

Handy Tips for Editing Korean Documents: HWP (Hangul Word Processor) Open and edit HWP files online with Hancom Docs. This article introduces useful tips for using Korean documents, such as adjusting character spacing, dividing pages, and indenting paragraphs. Check out the main features of Hancom Docs, which you can use f
길리
길리
Open and edit HWP files online with Hancom Docs. This article introduces useful tips for using Korean documents, such as adjusting character spacing, dividing pages, and indenting paragraphs. Check out the main features of Hancom Docs, which you can use f
길리
길리

April 5, 2024

2024.01.25 (Fri) Operation Update This blog post introduces the recent website style modifications, SEO improvements, and writing-related changes. It covers various aspects, including addressing style issues occurring in mobile environments, fixing URL errors, shortening the blog name, im
durumis-release
durumis-release
durumis-release
durumis-release

January 29, 2024