Misc CSS Properties

🧰 Misc Properties

Filter Clip-path Object-fit Outline List-style Styling Children @import

Assignment

Assignment 1 Assignment 2
📝 filter – Apply Visual Effects
Definition: Applies graphical effects like blur, brightness, contrast, grayscale, and more to elements. Filters can be combined for complex effects and work on images, backgrounds, and all content. This is GPU-accelerated in modern browsers for better performance than pixel-manipulation alternatives. Perfect for creating image effects without editing source files. Can be animated in transitions and keyframes.
Default Value: none
Values: blur() | brightness() | contrast() | drop-shadow() | grayscale() | hue-rotate() | invert() | opacity() | saturate() | sepia() | url() | and combinations

✦ filter: blur()

Blurs content - higher value = more blur

img {
  filter: blur(8px);
}

✦ filter: brightness()

Controls brightness (1.0 = original, > 1 = brighter, < 1=darker)

brightness(0.5)
brightness(1) - Original
brightness(1.5)
.darker { filter: brightness(0.5); }
.brighter { filter: brightness(1.5); }

✦ filter: contrast()

Increases or decreases color contrast

contrast(0.5)
contrast(2)
.low-contrast { filter: contrast(0.5); }
.high-contrast { filter: contrast(2); }

✦ filter: grayscale()

Converts to grayscale (0% = color, 100% = full grayscale)

Original Color
grayscale(100%)
img {
  filter: grayscale(100%);
}

✦ filter: sepia() & hue-rotate()

Sepia tone and color shift effects

sepia(80%)
hue-rotate(120deg)
.sepia { filter: sepia(80%); }
.color-shift { filter: hue-rotate(120deg); }

✦ filter: invert() & saturate()

Invert colors and adjust saturation

invert(100%)
saturate(200%)
.inverted { filter: invert(100%); }
.vibrant { filter: saturate(200%); }

✦ Combining Multiple Filters

Stack multiple filter effects

img {
  filter: grayscale(100%) brightness(1.1) contrast(1.2);
}

✦ Filter Hover Effect

Animate filters on hover

Hover to see color!
img {
  filter: grayscale(100%);
  transition: filter 0.3s ease;
}

img:hover {
  filter: grayscale(0%);
}


📝 clip-path – Create Custom Shapes
Definition: Clips element content to a specific shape. Supported shapes include circle, ellipse, polygon, inset, and path. Removes (hides) any content outside the defined shape boundary. Works on images, text, background, and all elements. Useful for creative designs, image masks, and decorative shapes without needing image files. Animatable between different shapes.
Default Value: none
Values: circle() | ellipse() | polygon() | inset() | path() | url()

✦ clip-path: circle()

Creates circular clipping
div {
  width: 200px;
  height: 200px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  clip-path: circle(50%);
}

✦ clip-path: ellipse()

Creates ellipse shape with width and height radii
div {
  width: 300px;
  height: 150px;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  clip-path: ellipse(50% 25%);
}

✦ clip-path: polygon()

Creates polygon shapes with multiple coordinate points
/* Star shape */
.star {
  clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
}

/* Bracket shape */
.bracket {
  clip-path: polygon(0% 0%, 25% 0%, 25% 25%, 75% 25%, 75% 0%, 100% 0%, 100% 100%, 0% 100%);
}

✦ clip-path: inset()

Clips from all sides by distances (top, right, bottom, left)
div {
  width: 200px;
  height: 200px;
  clip-path: inset(30px 40px);
  /* Hides 30px top/bottom, 40px left/right */
}

✦ clip-path: inset() with border-radius

Creates rounded rectangle clipping
div {
  width: 250px;
  height: 150px;
  background: linear-gradient(135deg, #a78bfa 0%, #9333ea 100%);
  clip-path: inset(0px round 25px);
}

✦ clip-path on Images

Clip image content to custom shape
img {
  clip-path: circle(40%);
}

✦ Multiple Clip Shapes

Different shapes in a row
/* Triangle */
.triangle { clip-path: polygon(50% 0%, 100% 100%, 0% 100%); }

/* Trapezoid */
.trapezoid { clip-path: polygon(25% 0%, 75% 0%, 100% 100%, 0% 100%); }

/* Octagon */
.octagon { clip-path: polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%); }
📝 object-fit – Scale Images in Containers
Definition: Controls how media content (images, videos) fills its container while maintaining aspect ratio. Determines whether content should be stretched, cropped, or padded. Essential for responsive images that need consistent container sizes without distortion. Works with `object-position` to customize alignment. Different values suit different use cases: cover for backgrounds, contain for full visibility, fill for stretching.
Default Value: fill
Values: fill | contain | cover | scale-down | none

✦ object-fit: fill (Default)

Stretches image to fill container, may distort aspect ratio
img {
  width: 250px;
  height: 150px;
  object-fit: fill; /* stretches */
}

✦ object-fit: cover

Fills container while maintaining aspect ratio (may crop)
img {
  width: 250px;
  height: 150px;
  object-fit: cover; /* fills, crops edges */
}

✦ object-fit: contain

Shows entire image while maintaining aspect ratio (may have empty space)
img {
  width: 250px;
  height: 150px;
  object-fit: contain; /* shows full image */
  background: #f0f0f0; /* shows empty space */
}

✦ object-fit: scale-down

Uses the smaller size of contain or none
img {
  width: 250px;
  height: 150px;
  object-fit: scale-down;
}

✦ object-fit: none

Shows original image size, may overflow or not fill container
img {
  width: 250px;
  height: 150px;
  object-fit: none; /* original size */
}

✦ object-fit with object-position

Combine with object-position to control alignment
object-position: top
object-position: center
object-position: bottom
img {
  width: 150px;
  height: 150px;
  object-fit: cover;
  object-position: center; /* or top, bottom, left, right */
}

✦ Multiple Comparisons

All object-fit values side by side
fill
cover
contain
scale-down
/* Gallery with consistent sizing */
.gallery-img {
  width: 200px;
  height: 200px;
  object-fit: cover;
  object-position: center;
}
📝 outline – Border Outside Element Edge
Definition: Creates a line outside the border that doesn't take up space in the layout. Unlike border, outline doesn't affect element dimensions or positioning. Used primarily for focus states (accessibility), decorative borders, and highlighting. Outlines never round with border-radius. Can be customized with width, style, color, and offset properties.
Default Value: none
Values: outline-width outline-style outline-color | outline-offset: length

✦ outline-width

Controls outline thickness
1px
thin
3px
medium
5px
thick
.thin { outline: 1px solid white; }
.medium { outline: 3px solid white; }
.thick { outline: 5px solid white; }

✦ outline-style

Different outline styles (solid, dashed, dotted, double, ridge, groove)
solid
dashed
dotted
double
.solid { outline-style: solid; }
.dashed { outline-style: dashed; }
.dotted { outline-style: dotted; }
.double { outline-style: double; }

✦ outline-color & outline-offset

Customize color and gap between element and outline
offset: 0px
offset: 5px
green 8px
div {
  outline: 2px solid #d63031;
  outline-offset: 5px; /* space between */
}

✦ outline vs border

Outline doesn't affect layout, border does
With outline
No space change
With border
Adds to size
/* Outline adds no width */
.with-outline {
  outline: 3px solid #f39c12;
  outline-offset: 2px;
}

/* Border adds to width */
.with-border {
  border: 3px solid #f39c12;
}

✦ Outline on Focus (Accessibility)

Default focus outline for interactive elements
Tab to this button to see blue outline
button {
  outline: 2px solid #0066cc;
  outline-offset: 2px;
}

/* Often customized for better UX */
button:focus {
  outline: 3px solid #0066cc;
}

✦ Removing Outline (Be Careful!)

Using outline: none - important for accessibility
Has outline
No outline ⚠
/* ⚠ Removing outline breaks focus visibility! */
button:focus {
  outline: none; /* DON'T DO THIS */
}

/* Better: customize instead */
button:focus {
  outline: 3px solid #0066cc;
  outline-offset: 2px;
}
list-style – Change list bullets
<div> <ul style="list-style-type: square;"> <li> Item One </li> <li> Item Two </li> </div>
👶 Styling Children with CSS
You can target specific child elements using CSS selectors like :first-child or :nth-child(). This is very useful for styling lists or grids without adding classes to every item.

Example

<style> ul li { color: blue; /* Styles all list items as blue */ } ul li:first-child { color: red; /* Overrides the first list item to be red */ font-weight: bold; } </style> <ul> <li>This is the first item (red and bold)</li> <li>This is the second item (blue)</li> <li>This is the third item (blue)</li> </ul>
@import – Import CSS
Definition: The @import rule is used to import style rules from other style sheets. This allows you to break down your CSS into smaller, more manageable files. It must be placed at the very top of the CSS file.

✦ Example

Importing multiple CSS files into one main file.
/* main.css */ @import url("header.css"); @import url("footer.css"); @import url("variables.css"); body { font-family: Arial, sans-serif; }
More Extra Properties
<button style="cursor:pointer;padding:10px 20px;background:#6c5ce7;color:#fff;border:none;border-radius:10px;"> Hover Me </button>