Display Types Are Overridden By Unknown Source
Solution 1:
There is a great discussion already on Stack Overflow on the difference between flex and inline-flex. It is an important read and will help in this discussion.
Basically, inline-flex
means the container will be inline, whereas flex
means the container will be block-level. Here's the key, in both cases, the children are flex-items
. They will behave in a certain way with certain defaults in place to fit the flex model. You have to style them differently, in some ways, than regular block or inline elements.
See the snippet below for an example.
.first_image {
display: inline-block;
height: 20px;
width: 20px;
}
.first_div {
width: 100%;
display: inline-block;
}
.first_div_expanding {
flex: 1;
}
.second_div {
width: 52px !important;
height: 40px !important;
display: inline-block;
background-color: #3798D4;
}
.container {
display: inline-flex;
}
.flex-container {
display: flex;
}
.set-sized-flex-container {
display: inline-flex;
width: 75%;
}
<h1>Inline-flex</h1>
<p>The flex container only takes up as much space as it needs and will not force a new line.</p>
<div class='container'>
<img src="https://via.placeholder.com/20x20" class="first-image">
<div class="first_div">No expansion</div>
<div class="second_div"></div>
</div>
<hr>
<h1>Flex</h1>
<p>The flex container will take the full-width of the screen</p>
<div class='flex-container'>
<img src="https://via.placeholder.com/20x20" class="first-image">
<div class="first_div">I expand full-width</div>
<div class="second_div"></div>
</div>
<hr>
<h1>Expanding first_div with Inline-Flex</h1>
<div class='set-sized-flex-container'>
<img src="https://via.placeholder.com/20x20" class="first-image">
<div class="first_div_expanding">I expand to take up remaining space</div>
<div class="second_div"></div>
</div>
Solution 2:
You wrote:
The issue is that 1. displays as
flex
although it should beinline-flex
, 2., 3., and 4. display asblock
although they should beinline-block
... Also, the property is not crossed out, so it doesn't seem to be overridden.
So let's clarify:
Element #1 (
.container
) is a flex container. You're saying the problem is that you declareddisplay: inline-flex
, but the browser is rendering the element asdisplay: flex
.Elements #2, #3 and #4 are the in-flow children of #1. This means they are flex items. You're saying the problem is that you've set these items to
display: inline-block
, but the browser is rendering them asdisplay: block
.
Okay. Let's cover these two points one-by-one.
Why is display: inline-flex
computing to display: flex
?
Because that's what the flexbox specification requires.
§ 3. Flex Containers: the
flex
andinline-flex
display valuesIf an element’s specified
display
isinline-flex
, then itsdisplay
property computes toflex
in certain circumstances: the table in CSS 2.1 Section 9.7 is amended to contain an additional row, withinline-flex
in the "Specified Value" column andflex
in the "Computed Value" column.
So inline-flex
computes to flex
in certain situations, as described in the table linked to in the excerpt above. That's what is happening in your code. Technically, it is not an override, which is why you're not seeing inline-flex
crossed out.
Why is display: inline-block
computing to display: block
on flex items?
Again, because that's what the flexbox specification requires.
The
display
value of a flex item is blockified: if the specifieddisplay
of an in-flow child of an element generating a flex container is an inline-level value, it computes to its block-level equivalent.
Also note that you cannot control the display
value of flex items. Once you make an element a flex container, the display
property on flex items is controlled by the flex algorithm. Attempts to set a display
rule on flex items are ignored by the browser. That's what you're seeing in your code: display: inline-block
is being ignored (but, again, technically not overridden, which is why inline-block
is not crossed out).
Post a Comment for "Display Types Are Overridden By Unknown Source"