⌚ CSS3 Essentials
- Background
- Background area: Underneath total area of element's content, padding, and border.
- The background doesn't covered under the margin.
- Background shorthand
- background: background-color | background-image | background-position | background-size | background-repeat | background-origin | background-clip | background-attachment | initial | inherit; -- Values position aren't fixed.
- All property values are optional.
- background: yellow linear-gradient(to bottom, red, #blue 50%, green) no-repeat 99% center;
- background-color
- Default background color transparent.
- <color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor.
- background-color: #f00;
- background-repeat
- The default value is repeat. Until background is filled the background image keep repeating.
- <no-repeat> | <repeat-x> | <repeat-y> | <repeat>
- background-image
- Invisible to assistive technologies like screen readers.
- background-image: url|none|initial|inherit
- background-image: url("../img/ept.jpg");
- background-image: url("star.gif"), url("background.tif");
- background-image:linear-gradient()
- Smooth color transitions across a background.
- Syntax: background-image: linear-gradient(direction, color-stop1, color-stop2, ...);[2]
- Direction:
- to bottom, to right, to bottom right, to bottom left, etc.
- 0deg is equivalent to top, 90deg is equivalent to to right, up to 360deg top again.
- Sample
- background-image: linear-gradient(red, green, blue);
- background-image: linear-gradient(to right, red , green);
- background-image: linear-gradient(to bottom right, yellow , blue);
- background-image: linear-gradient(to right, red, violet, orange, green, blue, yellow);
- background-image: linear-gradient(to right, rgba(255,0,1,0), rgba(255,0,10,1));
- background-image: linear-gradient(180deg, red 40%, blue);
- background-image: repeating-linear-gradient(to right, green, red 25px, blue 50px);
- background-position
- background-position
- Absolute values like pixels — for example background-position: 110px 29px.[1]
- Relative values like rems — for example background-position: 23rem 2.8rem.[1]
- Percentages — for example background-position: 97% 23%.[1]
- Keywords — for example background-position: right center. These two values are intuitive.
- <left> | <center> | <right> | <top> | <center> | <bottom>.
- Mix and match these values, for example background-position: 99% center.
- One value, that value will be assumed to be the horizontal value, and the vertical value will default to center. Single value (left, right, top, bottom ) or combination of two value. [background-position:center;] or [background-position:left center;].
- background-size
- <auto> : Default. Original size of image [background-size: auto].
- <length>: Static value [background-size: 200px 100px;].
- <percent>: Percent value [background-size: 200%;].
- <cover>: Widely used. Try to cover full container even stretch or cut any of the edge [background-size:cover;].
- <contain>: Show full image even resize is required but may not fit with the container[background-size:contain;].
- initial | inherit
- background-attachment
- When the content scrolls then background-attachment specifying how the backgrounds scroll.
- <scroll>
- This is default.
- The background image will scroll when content scrolls on the page.
- <fixed>
- The background image will not scroll when content scrolls on the page.
- The background is fixed relative to the viewport. [1]
- <local>
- The background is fixed relative to the element's contents. [1]
- Syntax: <background attachment> = scroll | fixed | local | mix()
- Multiple background-image
- Backgrounds are stacked on top of one another with the first appearing at the top, then the second below it, then the third, etc. [1]
- Off using background shorthand is a good practice.
- background-image: url("..."), url("..."), ...;
p { background-image: url("..."), url("..."); background-attachment: scroll, fixed; background-repeat: no-repeat, repeat-y; }
- background-clip
- Background color/image has extend to the edge of the border. This behavior can be changed using the background-clip property.
- <border-box>
- Start background form content's start point of border.
- Default value.
- #bg-border-box{ border: 5px dotted black; padding: 10px; background: yellow; background-clip: border-box; }
- padding-box
- Start background form content's start point of padding.
- #bg-padding-box{ border: 5px dotted black; padding: 10px; background: yellow; background-clip: padding-box; }
- content-box
- Start background form content's start point of content.
- #bg-padding-box{ border: 5px dotted black; padding: 10px; background: yellow; background-clip: content-box; }
- Ref:
- https://developer.mozilla.org
- https://www.w3schools.com/cssref/func_linear-gradient.asp
Much obliged for sharing the data, keep doing awesome...
ReplyDeletecss beautifier
Excellent
ReplyDelete