"I am Saqib Jahangir. A passionate vlogger, software engineer, and avid traveler with a deep love for exploring the hidden gems of our beautiful planet. With a strong foundation in Application Development, Application Architecture & Database Design and Product Management, I bring over a decade of hands-on experience building secure, scalable, and resilient web applications for a diverse range of industries."

Backgrounds and Borders

 

๐ŸŽจ Backgrounds and Borders

In CSS, backgrounds and borders are used to visually style elements and give your web pages structure and aesthetics.


๐Ÿ”ฒ Background Properties

CSS allows you to control the background of an element using several properties:

selector {
  background-color: #f0f0f0; /* Sets background color */
  background-image: url('image.jpg'); /* Sets background image */
  background-repeat: no-repeat; /* Prevents image from repeating */
  background-position: center center; /* Positions background */
  background-size: cover; /* Scales image to cover element */
  background-attachment: fixed; /* Fixes background when scrolling */
}

Shorthand:

background: #f0f0f0 url('image.jpg') no-repeat center center / cover fixed;

๐Ÿงฑ Border Properties

CSS borders add lines around elements.

selector {
  border-width: 2px;        /* Thickness */
  border-style: solid;      /* solid, dashed, dotted, double, none */
  border-color: #333;       /* Color of the border */
}

Shorthand:

border: 2px solid #333;

You can also style individual sides:

border-top: 1px dashed red;
border-right: 2px solid blue;
border-bottom: none;
border-left: 3px dotted green;

๐Ÿ”„ Border Radius

To make rounded corners:

border-radius: 10px; /* Applies to all corners */
border-radius: 10px 5px 15px 0; /* top-left, top-right, bottom-right, bottom-left */

๐Ÿงช Example

<div style="
  background: #eee url('pattern.png') repeat;
  border: 2px solid #444;
  border-radius: 10px;
  padding: 20px;">
  This box has a background, border, and rounded corners.
</div>

 

Popular Posts

Setting Up Your First Project Folder and Installing XAMPP or WAMP

Frontend vs Backend vs Full Stack