CSS before

Created By: chatGPT

CSS ::before is a pseudo-element that allows you to insert content before an HTML element's content. This is particularly useful for adding decorative elements or icons without modifying the markup. The ::before pseudo-element can be styled and controlled using CSS properties. To use it effectively, it is crucial to understand how to apply it correctly.
selector::before {
    content: 'YourContent';
    // other styles
}
To create a ::before pseudo-element, you need to specify the content property. Without the content property, the pseudo-element will not be displayed. You can also use Unicode characters, images, or anything else as the content.
h1::before {
    content: '\2022'; // adds a bullet before the heading
    font-size: 20px;
    color: red;
    margin-right: 10px;
}
In addition to content, you can style the ::before element in the same way as you would style a regular element. You can apply backgrounds, borders, padding, and more.
p::before {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    background-color: blue;
    margin-right: 5px;
}
You can also use this pseudo-element to create visual effects such as icons or decorative frames without cluttering your HTML. This approach is great for maintaining clean and semantic HTML while enhancing the visual presentation.
a::before {
    content: '\f007'; // FontAwesome user icon
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    margin-right: 5px;
}
Introduction And SetupSelectorsType SelectorClass SelectorId SelectorAttribute SelectorsUniversal SelectorGrouping SelectorsCombinatorsDescendant CombinatorChild CombinatorAdjacent Sibling CombinatorGeneral Sibling CombinatorPseudo ClassesHoverNth ChildNth Of TypeFocusVisitedActiveFirst ChildLast ChildOnly ChildPseudo ElementsBeforeAfterFirst LetterFirst LineBox ModelMarginPaddingBorderWidthHeightBox SizingPositioningStaticRelativeAbsoluteFixedStickyZ IndexDisplayInlineBlockInline BlockFlexGridNoneFloatClearTypographyFont FamilyFont SizeFont WeightFont StyleLine HeightLetter SpacingText AlignText DecorationText TransformVertical AlignOverflowOverflow XOverflow YVisibilityClip PathBackgroundsBackground ColorBackground ImageBackground SizeBackground PositionBackground RepeatBackground AttachmentGradientsBordersBorder WidthBorder ColorBorder StyleBorder RadiusShadowsBox ShadowText ShadowFlexboxFlex DirectionJustify ContentAlign ItemsAlign SelfFlex GrowFlex ShrinkFlex BasisOrderGridGrid Template ColumnsGrid Template RowsGrid GapGrid Auto FlowAlign ContentCss VariablesCustom PropertiesAnimationKeyframesTransitionTransformRotateScaleTranslateSkewMedia QueriesMin WidthMax WidthOrientationAspect RatioUnitsPxEmRemVhVwPercentages