Kế thừa là một từ khóa trong CSS. Cái nào được sử dụng để có được cùng một thuộc tính của bộ chọn cha đó cho bộ chọn con? . Nó được phép kế thừa tất cả các giá trị cha của nó cho phần tử con của nó. Chúng ta phải biết rằng một số thuộc tính được tự động kế thừa từ cha sang con do tính chất xếp tầng của CSS. Giả sử nếu chúng ta đặt màu văn bản của một phần tử thì nó sẽ tự động kế thừa tất cả thuộc tính màu cha thành thuộc tính con có cùng màu
Chúng ta sử dụng Thuộc tính kế thừa trong CSS ở đâu?
Khi chúng tôi muốn kế thừa cài đặt mặc định của máy khách thành giá trị thuộc tính phần tử của riêng chúng tôi thì chúng tôi phải sử dụng thuộc tính inherit
cú pháp
element1
{
color: value;
}
element2 element1
{
color: inherit;
}
ví dụ
Sau đây là các ví dụ được đưa ra dưới đây
Bắt đầu khóa học phát triển phần mềm miễn phí của bạn
Phát triển web, ngôn ngữ lập trình, kiểm thử phần mềm và những thứ khác
Gói phát triển phần mềm tất cả trong một[hơn 600 khóa học, hơn 50 dự án]
Giá
Xem các khóa học
Hơn 600 khóa học trực tuyến. hơn 50 dự án. Hơn 3000 giờ. Giấy chứng nhận có thể kiểm chứng. Truy cập trọn đời
4. 6 [86.697 xếp hạng]
Ví dụ #1 – Kế thừa thuộc tính Span
Mã số
div
{
color: maroon;
font-size: 18px;
}
span {
color: orange;
border: 2px solid maroon;
font-size: 22px;
}
.d1 span {
color: inherit;/*span all property styles applied to d1 div tag child element*/
}
h1
{
color: green;
text-align: center;
}
Inherit Span element properties to its child elements
The inherit is keyword in CSS. Which is used to acquire the same property of that parent selector to child selector. Specified the value of inherit for whatever CSS property
that is applicable to an element which will cause the element to get the parent's already existing value for child property.
The inherit is keyword in CSS. Which is used to acquire the same property of that parent selector to child selector. Specified the value of inherit for whatever CSS property
that is applicable to an element which will cause the element to get the parent's already existing value for child property.
The inherit is keyword in CSS. Which is used to acquire the same property of that parent selector to child selector. Specified the value of inherit for whatever CSS property
that is applicable to an element which will cause the element to get the parent's already existing value for child property.
đầu ra
Ví dụ #2 – Kế thừa thẻ Div cho đoạn văn
Mã số
.div {
background-color: lightgray;
color: fuchsia;
font-weight: bold;
font-size: 22px;
}
.p {
background-color: inherit;/*background color, color inherited from div to p tag*/
color: inherit;
font-weight: normal;
}
h1
{
color: blue;
text-align: center;
}
Inherit div element properties to its paragraph child elements
Hi, I am Paramesh
The inherit is keyword in CSS. Which is used to acquire the same property of that parent selector to child selector. Specified the value of inherit for whatever CSS property
that is applicable to an element which will cause the element to get the parent's already existing value for child property.
đầu ra
Ví dụ #3 – Kế thừa Div và Đoạn văn
Mã số
body {
color: blue;
font-size: 18px;
background-color: lightgray;
}
.mainDiv {
max-width: 650px;
margin: 30px auto;
}
.div1 {
padding: 22px;
color: brown;
border: 3px solid red;
}
.c {
margin-top: 22px;
padding: 22px;
border: inherit;
}
.div2 {
padding: 22px;
border: 3px solid orange;
margin-top: 32px;
}
.c2 {
padding: 22px;
margin-top: 22px;
border: 3px solid inherit;
}
h1 {
color: blue;
text-align: center;
}
Inherit Demo
The inherit is keyword in CSS. Which is used to acquire
the same property of that parent sdiv1ector to c sdiv1ector.
Specified the value of inherit for whatever CSS property that is
applicable to an div1ement which will cause the div1ement to get the
parent's already existing value for c property.which is blue, as
span div1ements are set to be
The inherit is keyword in CSS. Which is used to
acquire the same property of that parent sdiv1ector to c
sdiv1ector. Specified the value of inherit for whatever CSS property
that is applicable to an div1ement which will cause the div1ement to
get the parent's already existing value for
c property
.which is blue, as span div1ements are set to be
The inherit is keyword in CSS. The inherit is keyword in CSS.
Hi, I am
Paramesh
Hi, I am
Amardeep
Krishna
I am staying in Hyderabad.
Hello, How are you?
Where are you paramesh?
Hyderabad
đầu ra
Bài viết được đề xuất
Đây là hướng dẫn về Kế thừa CSS. Ở đây chúng ta cũng thảo luận về phần Giới thiệu và chúng ta sử dụng thuộc tính inherit một thuộc tính trong css ở đâu? . Bạn cũng có thể xem các bài viết sau để tìm hiểu thêm –