What makes the behavior of (display: flex) similar to that of an inherited property?

One thing that puzzles me is the behavior of the display property in CSS. Why is it that setting {display: flex} for a div will apply this style to all nested p elements within the div? It seems like {display: flex} might be an inherited property, but I'm not entirely sure. On the other hand, when I try to set {display: inline} for a div, the same cascading effect doesn't occur and the style only applies to the p elements directly inside the div. Can someone explain why this happens?

<div>
  <p>1</p>
  <p>2</p>
  <p>3</p>
</div>

CSS:

div {
  display: inline;
}

You can check out my code here: https://codepen.io/Eva255/pen/OJMNpBe

Answer №1

Have you ever wondered why using display:flex changes the layout of items from a row to a column? Let's explore the reason behind this interesting behavior.

By specifying display:flex, you are indicating to the browser that you wish to utilize the powerful flexbox layout for organizing the items within your div.

The flexbox layout was created with the intention of providing developers with a convenient way to arrange flexible boxes either in a row or a column, evenly distributed. Therefore, applying display:flex to a div will align its child p elements in a single row rather than a default column sequence.

In essence, the content of the paragraphs themselves remains unchanged; it is simply their arrangement that is affected by this CSS property.

If you're interested in delving deeper into the subject, I recommend checking out this resource: https://css-tricks.com/snippets/css/a-guide-to-flexbox/ (Be sure to read the background section for comprehensive insights).

I trust this explanation clarifies the concept for you!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I anchor a div Banner saying "Get 50% off our products" to the Navbar directly above it?

Bootstrap Question: How can I attach the div Banner ("50% off of our products") to the Navbar directly above it? The structure looks like this: <Navbar> </Navbar> <div> <span>Discount: 50% off of our products </span </di ...

Creating dynamic charts in Javascript using Firebase

My dad recently asked me to enhance our motor home by integrating an Arduino with Firebase to monitor the water and propane tanks. He's hoping to be able to check tank levels from his phone so he can see when they need refilling. I've successful ...

The application of position "absolute" to center content is ineffective

When I have an h1 element with position "absolute" inside a div with position "relative", setting h1's top:50% and left:50% places it in the middle of the viewport instead of the parent div. It seems that the nearest parent is being ignored for some r ...

Is there a way to dynamically disable an MVC Razor @Html.TextBoxFor depending on the selection made in a drop-down menu on the same page?

Consider the scenario where the following code is present. @Html.DropDownListFor(m => m.MyWebPage, Model.FruitsList, "Select", htmlAttributes: new { @class = "form-select detailsInfo" }) Within this dropdown menu, there is an option ...

Expanding a wrapper to fit the entire width of its content

I am facing an issue where the background color of a wrapper does not adjust to the overflowing content within it. How can I make sure that the background stretches behind all the content, regardless of its size? <div style="background-color: black;m ...

Can a low-opacity gradient be merged with a solid background color?

Can anyone help with this code snippet? Here's the link table { height: 200px; width: 200px; background-color: #444557; /* seems to be hidden by the gradient */ /* Here is the CSS for a gradient background */ /* Source: http://colorzilla ...

Using the linearGradient feature within an SVG to create a transitional effect on the Fill property

Looking to implement a stepper functionality, everything is working smoothly except for the transition on the fill. let step = 0; document.querySelector("button").addEventListener('click', () => { step++; document.querySelector("svg ...

Troubleshooting: Django project not functioning properly post transfer from Windows to Mac

Using Django 3.1.7 on a MacBook Pro now, I recently moved the Django project from a Windows 10 machine. Despite setting up the database and superuser again, running pipenv sync didn't result in serving any of my URLs or Admin page CSS styles. The serv ...

Generating a clickable link from information pulled from a database and utilizing the get() method

Currently experimenting with a form I created and everything is functioning smoothly. My current objective involves retrieving specific rows from my database and presenting them as a summary on a separate page. However, I want these rows to appear as hyper ...

Tips for Building Common Controller Logic in CakePHP

I am in the process of developing a website where I have set up dynamic content for the footer, which is retrieved from a database. I am looking to create a single controller logic code that can be used across all pages on the site. Any suggestions or gu ...

How can I prevent users from clicking the same link multiple times in HTML?

Is it possible to disable the href after one click using javascript or jquery? I need some assistance with this. Please help. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xml ...

Image Not Displayed on Page

I am facing an issue where I have a div class 'breadcam_bg' with an image url, but the image is not being displayed on the page even though the console detects the div. html <div class="bradcam_area breadcam_bg"> This div! & ...

Align the text in the center of the button vertically

Struggling to vertically center text on a button? I understand the frustration! I've been working on this issue for a whole day with no success. My setup involves NEXT.js and TailwindCSS. <main> <div class='flex justify-center ite ...

Show whether the day is even or odd with the JavaScript getDay object

I'm currently working on a task where I need to show the text "Even Day" if the day of the month is 2, 4, 6..., and "Odd Day" for days such as 1, 3, 5, and so on. I attempted to achieve this by setting up an array linked to the getDay object, but unfo ...

Exploring the Contrasts: AppBar vs Toolbar in MUI v5

Can you explain the variations between AppBar and Toolbar in MUI? I know that AppBar defaults to 'column' flex direction, while Toolbar defaults to 'row'. Are there any other distinctions? Additionally, why do MUI docs show examples of ...

Unable to view image stored as a blob

https://i.stack.imgur.com/8v90u.pngI have been studying these examples PHP display image BLOB from MySQL How to display an BLOB image stored in MySql database? They all demonstrate the same method of displaying images saved as blob. In my case, I ha ...

Execute the function when the element comes into view

Is there a way to create a function that will automatically attach itself to an element when it comes into view? I have multiple elements on my page - element1, element2, and element3. Instead of using a large if statement, I would like to write a functio ...

Material-UI Date Selectors: Show the Date in (Month, Day, Year) Format -> (April 17, 2019)

If you're using the Material-Ui Pickers library, check out this link for more information: It appears that you can display the date as a (Month Day) string or as a (MM/DD/YYYY) format. However, I'm wondering if there is an option to display the ...

What is the best way to stylize a date using Bootstrap-datepicker?

While this topic is well-known, I have a slightly more complex question regarding it. I have gone through the documentation here. My goal is to display the date in French format (dd/mm/yyyy) and save the value in US format (yyyy-mm-dd). Additionally, I nee ...

Angular Markdown Styling: A Guide

Currently, I am using Angular and Scully. I would like to add style to the image in a markdown file within Angular, but I am unsure of how to accomplish this task. The image is currently displaying too large. Can anyone provide me with useful advice on how ...