Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Rachel Bird
11,968 PointsBorder-shadow quiz question
There's a question on the border-shadow quiz that asks: "If a box shadow color is not specified, the browser will render it according to the element’s color property. True or false?"
It requires the answer true but on www.w3schools.com the description for color is: "Optional. The color of the shadow. The default value is black." I thought the answer to this question therefore had to be false.
2 Answers
Gary Mann
8,639 PointsSuppose I have a div .box with the following css styling:
.box {
height: 300px;
width: 300px;
margin: 200px auto;
padding: 40px;
border: 10px solid blue;
background: orange;
box-shadow: 20px 20px;
}
No color has been defined for the div. Any text in the div will be the color it inherits. If no color has been defined at all, then the text color will be the default black.
Same goes with the box-shadow. In this example, the box-shadow would default to black.
Now suppose I add a color declaration to the .box div:
.box {
color: red;
height: 300px;
width: 300px;
margin: 200px auto;
padding: 40px;
border: 10px solid blue;
background: orange;
box-shadow: 20px 20px;
}
Now the color of any text in the box is red, and the default box-shadow color becomes red as well.
Now, you might ask why I'm getting so wordy for a simple answer. Here's why: What if we remove the color declaration from the .box div but add one to a parent element.
body {
color: green;
}
.box {
height: 300px;
width: 300px;
margin: 200px auto;
padding: 40px;
border: 10px solid blue;
background: orange;
box-shadow: 20px 20px;
}
Any text in the .box div will be?
green
and the box-shadow will be?
green
So it is TRUE that "if a box shadow color is not specified, the browser will render it according to the element’s color property."
And if no color property is declared at all, then the box-shadow will default to black.
except in Safari, I suppose, where (according to your link) color is required to be declared in the box-shadow declaration or the box-shadow won't appear.
Rachel Bird
11,968 PointsThanks for such a thorough answer, Gary. =)