Stack flex items on top of each other

user3760941

How can I simply display the h3 tag and p tag on separate lines, with the h3 tag on the top?

This code is part of a bigger project and I know there are other ways of positioning elements in the centre on separate lines, but I don't want to have to affect its parent elements (of the bigger project) and want to use a simpler flex box.

.hover-over-windows-style {
  height: 100%;
  background: red;
  /* Fails because h3 and p tags are not on separate lines */
  display: flex;
  align-items: center;
  /* padding-top of 25% nearly works but content isnt in centre of parent div */
}

#parent {
  height: 300px;
  width: 300px;
}
<div id="parent">
  <div class="hover-over-windows-style">
    <h3><a href="matches/blitz.html">H3 Tag on top</a></h3>
    <p>Paragraph here should be below the H3 tag, on a separate line. Not sure how to get this done. Setting 100% widths don't work and cannot display as block elements.</p>
  </div>
</div>

Vadim Ovchinnikov

Add flex-direction: column to place flex items in column. Note that align-items will center flex items horizontally in this case. To move elements to the center of flex container use justify-content: center.

.hover-over-windows-style {
  height: 100%;
  background: red;
  /* Fails because h3 and p tags are not on separate lines */
  display: flex;
  /* place flex items in column */
  flex-direction: column;
  /* move elements to the center of flex center */
  justify-content: center;
  /* padding-top of 25% nearly works but content isnt in centre of parent div */
}

#parent {
  height: 300px;
  width: 300px;
}
<div id="parent">
  <div class="hover-over-windows-style">
    <h3><a href="matches/blitz.html">H3 Tag on top</a></h3>
    <p>Paragraph here should be below the H3 tag, on a separate line. Not sure how to get this done. Setting 100% widths don't work and cannot display as block elements.</p>
  </div>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Stop flex items stacking on top of each other

CSS Flex Stacking Items on Top of Each Other

draggable items stack on top of each other in a sortable

How to stack items on top of each other?

Display first 2 flex items centered to each other and top aligned

News items stack in top of each other with CSS position

I want the flex items to stack on top of each other, but it doesn't happen. I already used flex-start for both the containers and children

Divs stack on top of each other

How can i stack buttons on top of each other using flex box

Why isnt my flex wrap actually stacking my items on top of each other?

How to stack flex children over each other

Make flex items closer to each other

R: "stack" columns on top of each other

Android Cardview elements stack on top of each other

android image stack on top of each other horizontally

Stack groups in a DataFrame on top of each other

How to Stack Divs on top of each other

How to Stack Arrays on top of Each Other

The Div's stack on top of each other

How to stack HTML elements on top of each other

CSS: navbar items on top of each other?

Owl Carousel - Items are stacking on top of each other

Flexbox: Two elements on top of each other in flex-direction: row

SCSS : display-flex stacks elements on top of each other

How can I put images on top of each other with display:flex?

How to align multiple flex boxes on top of each other?

Align two flex items vertically independent of each other

How to stack data frames on top of each other in Pandas

How can you stack buttons on top of each other in Manifest XML