How to use Flex property in CSS?

This property is used to specify the length of the item, relative to the rest of the flexible items inside the same container. If the element is not a flexible item, the flex property has no effect.

The flex property is a shorthand for the flex-grow, flex-shrink, and flex-basis properties.

Syntax: –

Selector { flex: flex-grow flex-shrink flex-basis}

Ex: –

div { flex: 2 3;}

FlexBox or Flexible Box

What is it ?

–Its Layout mode a CSS 3 concept

Why we need it ?

–It helps to create responsive web pages

Flexbox Properties

  • flex-direction
  • flex-wrap
  • align-content
  • flex-flow
  • flow-grow
  • flow-shrink
  • flow-basis
  • flex

flex-direction

This property is used to set the direction of flexible items. If the element is not a flexible item, the flex-direction property has no effect. We can set this property to row (default), row-reverse, column, column-reverse.

Ex: –

div { flex-direction: column-reverse; }

  • row – This is used to display the flexible items horizontally as row
  • row-reverse – This is used to display the flexible items same as row, but in reverse order
  • column – This is used to display the flexible items vertically as column
  • column-reverse – This is used to display the flexible items same as column, but in reverse order

flex-wrap

This property is used to specify whether the flexible items should wrap or not. If the elements are not flexible items, the flex-wrap property has no effect. We can set this property to nowrap (default), wrap and wrap-reverse.

Ex: –

div { flex-wrap: wrap; }

  • nowrap – It specifies that the flexible items will not wrap
  • wrap – It specifies that the flexible items will wrap if necessary
  • wrap-reverse – It specifies that the flexible items will wrap, if necessary, in reverse order

flex-flow

It is a shorthand property for the flex-direction and the flex-wrap properties. If the elements are not flexible items, the flex-flow property has no effect.

Syntax: –

Selector { flex-flow: flex-direction flex-wrap;}

Ex: –

div { flex-flow: row-reverse wrap;}

  • Flex-direction values:
  • row (default)
  • row-reverse
  • Column
  • column-reverse.
  • Flex-wrap values:
  • nowrap (default)
  • wrap
  • wrap-reverse

flex-grow

This property is used to specify how much the item will grow relative to the rest of the flexible items inside the same container. If the element is not a flexible item, the flex-grow property has no effect. We can set this property to number (default 0).

Ex: –

div {flex-grow: 1;}

flex-shrink

This property is used to specify how the item will shrink relative to the rest of the flexible items inside the same container. If the element is not a flexible item, the flex-shrink property has no effect. We can set this property to number (default 1).

Ex: –

div {flex-shrink: 2;}

flex-basis

This property is used to specify the initial length of a flexible item. If the element is not a flexible item, the flex-basis property has no effect. We can set this property to number and auto (default).

Ex:

div {flex-basis: 3;}

  • number – A length unit, or percentage, specifying the initial length of the flexible item(s)
  • auto – The length is equal to the length of the flexible item. If the item has no length specified, the length will be according to its content
Tagged : / / / /

How to use box-sizing property in CSS?

The box-sizing property tells the browser what the sizing properties should include. We can set this property to content-box (default) or border-box.

The box-sizing property is used to include the padding and border in an element’s total width and height.

Ex:-

div { box-sizing: border-box;}

content-box-

The width and height properties (and min/max properties) include only the content. Border, padding, or margin are not included.

border-box-

The width and height properties (and min/max properties) include content, padding, and border, but not the margin.

box-size property usually uses in cards, images & fonts.

Tagged : / / / /

How does Attribute Selector work in CSS?

We can set style using attribute or its value.

Set Style using attribute : –

Syntax: –

Selector [attribute] { CSS ;}

Ex: –

div [id] { color: red; }

Set style using attribute and its value: –

Syntax: –

Selector [attribute = “value”] {  CSS  }

Ex: –

div[id=“data”] { color: red; }

Set Style using an attribute value containing a specified word.

Syntax: –

[attribute ~= “value”] { CSS }

Ex:-

[class ~= “game”] { color: red; }

game
supergame
game-super
gamesuper
super-game
game super
super game

Set Style using with the specified attribute starting with the specified value.

Syntax: –

[attribute |= “value”] { CSS }

Ex:-

[class |= “game”] {color: red;}

The value must be a whole word.

Ex: –

“game” or “game-super”

game
supergame
game-super
gamesuper
super-game
game super
super game

Set Style whose attribute value begins with a specified value.

Syntax: –

[attribute ^= “value”] { CSS }

Ex:-

[class ^= “game”] {color: red;}

game
supergame
game-super
gamesuper
super-game
game super
super game

It is not necessary that the value should be a whole word.

Set Style whose attribute value ends with a specified value.

Syntax: –

[attribute $= “value”] { CSS }

Ex:-

[class $= “game”] {color: red;}

game
supergame
game-super
gamesuper
super-game
game super
super game

It is not necessary that the value should be a whole word.

Tagged : / / / / /

Difference Between column-gap, column-span & column-fill in CSS

column-gap

This property is used to specify the gap between the columns. We can set this property to normal (default) and length.

Ex: –

div { column-gap: 30px;}

column-span

This property is used to specify how many columns an element should span across. We can set this property to none (default) and all.

Ex: –

div { column-span: all;}

column-fill

This property is used to specify how to fill columns, balanced or not. We can set this property to balance (default) and auto.

Ex: –

div { column-fill: auto;}

Tagged : / / /

Which properties are shorthand for the column-rule property?

column-rule

  • column-rule
  • column-rule-style
  • column-rule-width
  • column-rule-color

This is shorthand of other column-rule-* properties.

Syntax: –

Selector {column-rule: column-rule-width column-rule-style column-rule-color }

Ex: –

div { column-rule: 5px solid red;}

column-rule-style

This property is used to specify the style of the rule between columns. We can set this property to none (default), hidden, dotted, dashed, solid, double, groove, ridge, inset and outset.

Ex: –

div { column-rule-style: double;}

column-rule-width

This property is used to specify width of the rule between columns. We can set this property to medium (default), thin, thick and length.

Ex: –

div { column-rule-width: 5px;}

column-rule-color

This property is used to specify color of the rule between columns. We can set this property to color value.

Ex: –

div { column-rule-color: red;}

Tagged : / / / / / /

How to use Columns Property in CSS?

This property is used to define columns.

  • column-count
  • column-width
  • columns

column-count

This property is used to specify the number of columns an element should be divided into. We can set this property to number or auto (default).

Ex:-

div { column-count: 2;}

column-width

This property is used to specify width for the columns. We can set this property to length or auto (default).

Ex:-

div { column-count: 2; column-width: 100px; } div { column-width: 200px; }

columns

This is shorthand which is used to set column-width and column-count.

Syntax: –

Selector { columns: column-width column-count;}

Ex:-

div { columns: 200px 2;}

Tagged : / / / /

How to use Outline Property in CSS?

An outline is a line that is drawn around elements, outside the borders. Outlines never take up space, as they are drawn outside of an element’s content.

  • outline-color
  • outline-style
  • outline-width
  • outline

outline-style

This property is used to specify the style of an outline. We can set this property to none (default), hidden, dotted, dashed, solid, double, groove, ridge, inset, outset.

Ex: –

div { outline-style: solid;}

outline-color

This property is used to specify the color of an outline. We can set this property to invert (default) or color.

Ex: –

div { outline-style: solid; outline-color: red;}

outline-width

This property is used to specify width of an outline. We can set this property to medium (default), thin, thick, length.

Ex: –

div { outline-style: solid; outline-width: thin;}
div { outline-style: solid; outline-width: 5px;}

outline

This is shorthand of other outline properties.

Syntax: –

Selector {outline: outline-color outline-style outline-width;}

Ex: –

div { outline: red solid 3px;}

Tagged : / / / /

How to use Width & Height Property in CSS?

Width & Height Property usually uses in Images, Card, fonts, tables etc… for responsive & attractive design. So, in this blog, you can learn that how can use the width & height property in CSS?

Width

This property is used to set the width of an element. We can set this property to auto and length in the form of px, cm, % etc.

Ex:-

div { width: 100px; }

Height

This property is used to set the height of an element. We can set this property to auto and length in the form of px, cm, % etc.

Ex: –

div { height: 100px; }

Tagged : / / / /

How to use Transition property in CSS?

Transitions is used to change property values from one value to another, over a given duration. The transition effect will start when the specified CSS property changes value.

How to Use Transitions?

  • CSS property you want to add an effect to
  • Duration of the effect

Note: If the duration part is not specified, the transition will have no effect, because the default value is 0.

Transition

  • transition-timing-function
  • transition-property
  • transition-duration
  • transition-delay
  • transition

transition-property

This property is used to specify the name of the CSS property the transition effect is for (the transition effect will start when the specified CSS property changes). Always specify the transition-duration property, otherwise the duration is 0, and the transition will have no effect.

We can set this property to none, all and property.

Ex: –

div { transition-property: all; }

none – No property will get a transition effect
all – All properties will get a transition effect. This is Default value.
property – Defines a comma separated list of CSS property names the transition effect is for

When you use Cursor then the transition property will work.

transition-duration

This property is used to specify how many seconds or milliseconds a transition effect takes to complete. We can set this property to time in the form of seconds or milliseconds. The default value of this property is 0s which means there will be no effect.

Ex:-

div { transition-duration: 2s; }

div { transition-duration: 1000ms; }

transition-timing-function

This property is used to specify the speed curve of the transition effect. This property allows a transition effect to change speed over its duration. We can set this property to ease, linear, ease-in, ease-out, ease-in-out, step-start, step-end, steps(int, start or end), cubic-bezier(n, n, n, n).

Ex:-

div { transition-timing-function: ease-in; }

  • ease – It Specifies a transition effect with a slow start, then fast, then end slowly (equivalent to cubic-bezier(0.25, 0.1, 0.25, 1)). This is Default value.
  • linear – It specifies a transition effect with the same speed from start to end (equivalent to cubic-bezier(0, 0, 1, 1))
  • ease-in – It specifies a transition effect with a slow start (equivalent to cubic-bezier(0.42, 0, 1, 1))
  • ease-out – It specifies a transition effect with a slow end (equivalent to cubic-bezier(0, 0, 0.58, 1))
  • ease-in-out – It specifies a transition effect with a slow start and end (equivalent to cubic-bezier(0.42, 0, 0.58, 1))
  • step-start – Equivalent to steps(1, start)
  • step-end – Equivalent to steps(1, end)
  • steps(int, start or end) – Specifies a stepping function, with two parameters. The first parameter specifies the number of intervals in the function. It must be a positive integer (greater than 0). The second parameter, which is optional, is either the value “start” or “end”, and specifies the point at which the change of values occur within the interval. If the second parameter is omitted, it is given the value “end”
  • cubic-bezier(n,n,n,n) – Define your own values in the cubic-bezier function. Possible values are numeric values from 0 to 1

transition-delay

This property is used to specify when the transition effect will start. We can set this property to time in the form of seconds or milliseconds.

Ex:-

div { transition-delay: 2s; }
div { transition-delay: 1000ms; }

Tagged : / / / / / /

How to use text-decoration property in CSS?

This property is used to specify the decoration added to text.

  • text-decoration-line
  • text-decoration-style
  • text-decoration-color
  • text-decoration

text-decoration-line

This property is used to specify what type of line the decoration will have. We can set this property to none, underline, overline, line-through

We can combine more than one value, like underline and overline to display lines both under and over the text.

Ex:-

h1 { text-decoration-line: underline;}
h1 { text-decoration-line: underline overline;}

text-decoration-style

This property is used to specify how the line will display.

We can set this property to solid, double, dotted, dashed, wavy.

Ex:-

h1 { text-decoration-line: underline; text-decoration-style: dotted; }

text-decoration-color

This property is used to specify the color of the text-decoration-line.

Ex:-

h1 { text-decoration-line: underline; text-decoration-color: red; }

text-decoration

This is shorthand of all three text-decoration properties.

Syntax: –

Selector {text-decoration: text-decoration-line text-decoration-style text-decoration-color}

Ex:-

h1 {  text-decoration: underline dotted red ; }

Tagged : / / / / / /