- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
Understanding CSS Border-Bottom A Comprehensive Guide
Enhance your web design with this versatile property.
Introduction
The border-bottom property in CSS is a shorthand that sets the width, style, and color of an element’s bottom border. This property is useful for adding distinctive bottom borders to elements like headers, footers, or any other HTML elements, enhancing the overall look of your website.
Specification
The border-bottom property is defined in the CSS Backgrounds and Borders Module Level 3 specification. It combines the border-bottom-width, border-bottom-style, and border-bottom-color properties.
Syntax
border-bottom: border-width border-style border-color;Breakdown of Syntax
- border-width: Specifies the thickness of the border. You can use keywords like
thin,medium,thick, or specific lengths likepx,em, etc. - border-style: Defines the style of the border. Options include
none,hidden,dotted,dashed,solid,double,groove,ridge,inset, andoutset. - border-color: Sets the color of the border. You can use color names, hex values, RGB values, etc.
Examples
border-bottom: 1px solid black; /* 1px wide, solid black border */border-bottom: 2px dotted red; /* 2px wide, dotted red border */border-bottom: medium dashed blue; /* Medium-width, dashed blue border */Global Values
border-bottom: inherit; /* Inherits from parent element */border-bottom: initial; /* Sets to initial default */border-bottom: revert; /* Reverts to user agent's default */border-bottom: revert-layer; /* Reverts to user agent's default at specific layer */border-bottom: unset; /* Resets to natural value */Order of Values
The values (width, style, color) can be specified in any order, and one or two may be omitted:
border-bottom: 2px dashed; /* 2px wide, dashed border with default color */border-bottom: dashed blue; /* Dashed blue border with default width */Constituent Properties
The border-bottom property is a shorthand for:
-
border-bottom-width:
- Description: Sets the width of the bottom border.
- Values: Keywords (
thin,medium,thick) or lengths (px,em, etc.). - Default:
medium
-
border-bottom-style:
- Description: Sets the style of the bottom border.
- Values:
none,hidden,dotted,dashed,solid,double,groove,ridge,inset,outset. - Default:
none
-
border-bottom-color:
- Description: Sets the color of the bottom border.
- Values: Any CSS color value.
- Default:
currentcolor(current text color of the element)
Example
border-bottom: 2px solid green;This sets:
border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: green;Important Notes
- If any property is not specified, it defaults to its initial value.
- If
border-bottom-styleisnone, the border won’t be visible.
Values
The border-bottom property accepts various values for width, style, and color.
<border-width>
- Keywords:
thin,medium(default),thick - Length Values: Units like
px,em,rem, etc.
Example:
border-bottom: 2px; /* Sets width to 2px */<border-style>
- Values:
none(default),hidden,dotted,dashed,solid,double,groove,ridge,inset,outset
Example:
border-bottom: dashed; /* Sets style to dashed */<border-color>
- Values: Color names, hex values, RGB values, etc.
Example:
border-bottom: blue; /* Sets color to blue */Combining Values
border-bottom: 2px dashed blue; /* 2px wide, dashed blue border */border-bottom: thick solid green; /* Thick, solid green border */Global Values
border-bottom: inherit; /* Inherits from parent element */Important Notes
- If
border-styleis omitted or set tonone, the border won’t be visible. - At least one value must be specified for a visible border.
Formal Definition
The border-bottom property is a shorthand for setting the bottom border of an element. It combines border-bottom-width, border-bottom-style, and border-bottom-color.
Initial Value
- border-bottom-width:
medium - border-bottom-style:
none - border-bottom-color:
currentcolor
Applies To
All elements, including the ::first-letter pseudo-element.
Inherited
No, not inherited.
Computed Value
- border-bottom-width: Absolute length or
0ifborder-bottom-styleisnoneorhidden. - border-bottom-style: As specified.
- border-bottom-color: Resolved color.
Animation Type
- border-bottom-color: Animates as a color.
- border-bottom-style: Discrete animation.
- border-bottom-width: Animates as a length.
Formal Syntax
border-bottom = <line-width> [||] <line-style> [||] [<color>]
<line-width> = [<length>] | thin | medium | thick
<line-style> = none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outsetImportant Notes
- The order of values does not matter.
- If
border-bottom-styleis not specified or set tonone, the border won’t be visible.
Examples
Applying a Basic Bottom Border
HTML
<div class="example1">This box has a simple bottom border.</div>CSS
.example1 { border-bottom: 2px solid black; background-color: lightgray; padding: 20px; text-align: center;}Applying a Dashed Bottom Border
HTML
<div class="example2">This box has a dashed bottom border.</div>CSS
.example2 { border-bottom: 3px dashed red; background-color: lightblue; padding: 20px; text-align: center;}Applying a Double Bottom Border
HTML
<div class="example3">This box has a double bottom border.</div>CSS
.example3 { border-bottom: 5px double green; background-color: lightyellow; padding: 20px; text-align: center;}Applying a Bottom Border with Inheritance
HTML
<div class="parent"> <div class="child">This box inherits the bottom border style from its parent.</div></div>CSS
.parent { border-bottom: 4px solid blue;}
.child { border-bottom: inherit; background-color: lightcoral; padding: 20px; text-align: center;}Applying a Bottom Border with Global Values
HTML
<div class="example4">This box has a bottom border set to initial values.</div>CSS
.example4 { border-bottom: initial; background-color: lightpink; padding: 20px; text-align: center;}Browser Compatibility
The border-bottom property is widely supported across all major browsers, including:
- Google Chrome: Full support.
- Mozilla Firefox: Full support.
- Safari: Full support.
- Microsoft Edge: Full support.
- Internet Explorer: Full support from IE 4.0.
Ensure to test your web pages across different browsers to confirm consistent behavior.
Best Practices
- Use Consistent Styles: Keep your border styles consistent across your website for a cohesive look.
- Avoid Overuse: Overusing borders can make your design look cluttered. Use them sparingly to highlight important elements.
- Combine with Other Properties: Combine
border-bottomwith other CSS properties likepadding,margin, andbackground-colorto create well-structured layouts. - Test Across Browsers: Always test your web pages across different browsers to ensure consistent appearance.
Frequently Asked Questions
What is the default value for border-bottom?
The default values for the constituent properties are:
- border-bottom-width:
medium - border-bottom-style:
none - border-bottom-color:
currentcolor
Can I animate the border-bottom property?
Yes, you can animate the border-bottom property. The border-bottom-color property animates as a color, border-bottom-style animates discretely, and border-bottom-width animates as a length.
What happens if I omit the border-bottom-style?
If you omit the border-bottom-style, it defaults to none, making the border invisible.
Can I inherit the border-bottom property from a parent element?
Yes, you can use the inherit value to inherit the border-bottom property from a parent element.
By following these guidelines and understanding the border-bottom property, you can enhance the visual appeal and structure of your web pages effectively.
สร้างเว็บไซต์ 1 เว็บ ต้องใช้งบเท่าไหร่? เจาะลึกทุกองค์ประกอบ website development cost อยากสร้างเว็บไซต์แต่ไม่มั่นใจในเรื่องของงบประมาณ อ่านสรุปเจาะลึกตั้งแต่ดีไซน์, ฟังก์ชัน และการดูแล พร้อมตัวอย่างงบจริงจาก Till it’s done ที่แผนชัด งบไม่บานปลายแน่นอน
Next.js สอน 14 ขั้นตอนเบื้องต้น: สร้างโปรเจกต์แรกใน 30 นาที เริ่มต้นกับ Next.js ใน 14 ขั้นตอนเพียงแค่ 30 นาที พร้อม SSR/SSG และ API Routes ด้วยตัวอย่างโค้ดง่าย ๆ อ่านต่อเพื่อสร้างโปรเจ็กต์แรกได้ทันทีที่นี่
วิธีสมัคร Apple Developer Account เพื่อนำแอปขึ้น App Store ทีละขั้นตอน อยากปล่อยแอปบน App Store ระดับโลก มาอ่านคู่มือสมัคร Apple Developer Account พร้อมเคล็ดลับ TestFlight และวิธีอัปโหลดที่ง่ายในบทความเดียวนี้ได้เลย
TypeScript Interface คืออะไร? อธิบายพร้อมวิธีใช้และข้อแตกต่างจาก Type เรียนรู้วิธีใช้ TypeScript Interface เพื่อสร้างโครงสร้างข้อมูลที่ปลอดภัยและเข้าใจง่าย พร้อมเปรียบเทียบข้อดีข้อแตกต่างกับ Type ที่คุณต้องรู้ ถูกรวมเอาไว้ในบทความนี้แล้ว
Material-UI (MUI) คืออะไร อยากสร้าง UI สวยงามและเป็นมืออาชีพในเวลาอันรวดเร็วใช่ไหม มาทำความรู้จักกับ Material-UI (MUI) ที่ช่วยให้คุณพัฒนาแอปพลิเคชันบน React ได้ง่ายและดูดีในทุกอุปกรณ์
เปรียบเทียบ 3 วิธีติดตั้ง install node js บน Ubuntu: NVM vs NodeSource vs Official Repo แบบไหนดีที่สุด? เรียนรู้วิธีติดตั้ง Node.js บน Ubuntu ด้วย NVM, NodeSource หรือ Official Repo เลือกวิธีที่เหมาะกับความต้องการของคุณ พร้อมเปรียบเทียบ เพื่อการพัฒนาที่มีประสิทธิภาพ! พูดคุยกับซีอีโอ
We'll be right here with you every step of the way.
We'll be here, prepared to commence this promising collaboration.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.