What is causing the align content property to not function as expected in this situation?

Is it expected for the flex items of the .center-section-container to be closer together when using this property? They do not seem to be affected at all. I have applied flex wrap so the items are now in different lines but too far away from each other, I would prefer them to be closer on the cross axis.

This is my current implementation:

body {
  border: solid orange;
  width: 100vw;
  height: 100vh;
  color: lightgrey;
}

.main-container {
  border: solid black;
  width: 100%;
  max-width: 840px;
  margin: 0;
  display: flex;
}

.main-container>* {
  border: solid pink;
}

.square {
  min-height: 154.53px;
  min-width: 171.53px;
  border-radius: 10px;
  background-color: #555;
}

/**Here lies the issue**/
.center-section-container {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
}

.center-section-container>* {
  border: solid yellow;
}

.text1 {
  color: black;
}

.subtext {
  flex-basis: 60%;
}

.button-grey,
.button-white {
  border-radius: 5px;
  flex-basis: 40%;
  height: 50px;
}

.button-grey {
  background-color: grey;
  color: white;
}

.button-white {
  border: solid grey;
  background-color: white;
  color: inherit;
}

.aside {
  width: 200px;
}
<article class=main-container>
  <div class="square"></div>

  <section class="center-section-container">
    <h1 class="text1">Centro de Fisioterapia Guzmán Fernandez </h1>
    <h4 class="subtext">Fisioterapia general </h2>
      <button class="button-grey" type="button" name="button">Reservar                         
           </button>
      <button class="button-white" type="button" name="button">Pedir
           </button>
  </section>

  <aside class="aside">

    <h3 class="valoraciones"> 24 valoraciones </h3>
    <div class="number-container">
      <div class="number">8,9</div>
    </div>

    <a class="comentarios" href="#"> ver comentarios</a>

    <a class="estrella" href="#"> <img src="images/star.svg" alt="votación estrella" width="20px" height="20px" title="simbolo estrella">
    </a>


  </aside>
</article>

Answer №1

One way to reduce the vertical distance between flex items is by eliminating the default margin of the h1 and h4 tags (note that there is a typo in the closing h2/h4 tag).

.center-section-container {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
}

.center-section-container>* {
  border: solid yellow;
  margin: 0;
}

Setting margin: 0 on the child elements will bring them closer together. To vertically align the flex items in the middle, adjust the align-content: center; property for the container as well. Hope this helps!

body {
  border: solid orange;
  width: 100vw;
  height: 100vh;
  color: lightgrey;
}

.main-container {
  border: solid black;
  width: 100%;
  max-width: 840px;
  margin: 0;
  display: flex;
}

.main-container>* {
  border: solid pink;
}

.square {
  min-height: 154.53px;
  min-width: 171.53px;
  border-radius: 10px;
  background-color: #555;
}

/**here I have the problem**/
.center-section-container {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
}

.center-section-container>* {
  border: solid yellow;
    margin: 0;
}

.text1 {
  color: black;
}

.subtext {
  flex-basis: 60%;
}

.button-grey,
.button-white {
  border-radius: 5px;
  flex-basis: 40%;
  height: 50px;
}

.button-grey {
  background-color: grey;
  color: white;
}

.button-white {
  border: solid grey;
  background-color: white;
  color: inherit;
}

.aside {
  width: 200px;
}
<article class=main-container>
  <div class="square"></div>

  <section class="center-section-container">
    <h1 class="text1">Centro de Fisioterapia Guzmán Fernandez </h1>
    <h4 class="subtext">Fisioterapia general </h4>
      <button class="button-grey" type="button" name="button">Reservar                         
           </button>
      <button class="button-white" type="button" name="button">Pedir
           </button>
  </section>

  <aside class="aside">

    <h3 class="valoraciones"> 24 valoraciones </h3>
    <div class="number-container">
      <div class="number">8,9</div>
    </div>

    <a class="comentarios" href="#"> ver comentarios</a>

    <a class="estrella" href="#"> <img src="images/star.svg" alt="votación estrella" width="20px" height="20px" title="simbolo estrella">
    </a>


  </aside>
</article>

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

What is the best method for animating a display table to none or reducing its height to

My goal is to animate a header whenever the class collapseTest is applied. After some trial and error, I have come up with the following solution: http://jsfiddle.net/robertrozas/atuyLtL0/1/. A big shoutout to @Hackerman for helping me get it to work. The ...

What is the best method to customize CSS in ExtJS 5.0 by overriding a function?

Is there a way to dynamically add a rule to existing CSS using code, particularly in overrides? For example: var sheets = document.styleSheets; // Some code omitted for simplicity var sheet = sheets[sheets.length - 1]; sheet.insertRule('.overlay {flo ...

What is the reason behind receiving a CSS warning stating "Expected color but found '0' " when using Phaser's setText() function?

Here's how I created my text object: statusBarHP.text = game.add.text(0, 0, '', { font:"16px Arial", fill:"#ffffff", stroke:"#000000", strokeThickness:2 }); For the object that holds the text: statusBarHP = game.add.sprite ...

What is the best way to reset an event back to its original state once it has been clicked on again

As a newcomer to web development, I'm currently working on creating my own portfolio website. One of the features I am trying to implement is triangle bullet points that can change direction when clicked - kind of like an arrow. My idea is for them to ...

Arranging 2 divs side by side

As a beginner, I'm struggling to find the answer because I have no idea what search terms to use. Now, I have a form <form action="#" method="POST"> <div id="labels"> <label>CMS System</label><p> ...

Unable to align divs horizontally

On my webpage, I have set up two divs - Box1 and Box2. Within Box2, there are two nested divs called Box2-1 and Box2-2. However, when I view the page, Box1 and Box2 do not align side-by-side as expected. Instead, Box1 moves downwards and lines up with the ...

Unable to alter or eliminate the grey background using material-ui

Struggling with a React application that incorporates material-ui. Despite my efforts, I can't seem to get rid of an unwanted grey background in one section of the app. Attempted solutions: body { background-color: #ffffff !important; } * { b ...

Fuzzy division following a CSS transformation/animation

I have been working on a content slider, using the guidelines from this demonstration However, I have encountered an issue where my content, which consists of a few divs, appears slightly blurry after the CSS transition completes. This problem only seems ...

What is the best way to create a responsive design that positions an element between two others?

There are two types of elements in my project: Type "A" - a text block Type "B" - a graphical block I am looking to create a responsive layout for these elements. On small resolution screens, I want them to be arranged like this: "A" "A" "B" ...

Automatically adjusting the top margin of the main content section depending on the variable height of a fixed header

Visit our mobile site here (mobile view) Currently, I have set the margin-top of .main-content based on sticky-animation, which keeps the header fixed at the top on mobile. However, there is a div with a close button (X) that alters its height dynamically ...

Newcomers to Visual Studio Code facing a problem with images not displaying

As a beginner in all aspects, I am currently facing an issue with displaying an image on Visual Studio Code. The problem arose when I tried to create a separate folder for the image, which resulted in a cascade of subfolders that only made things worse eac ...

Issues with iOS 7's absolute positioning not functioning properly within a table-responsive container

I successfully implemented fixing the first two left columns in my tables by following the instructions on . The columns are only fixed when the screen size is less than 768px, making the table scrollable (check it out on jsFiddle). This functionality work ...

How can you center a webpage and make it occupy 60% of the screen?

I was attempting to design a website where the main content takes up 60% of the body. This is what I tried initially: body { align-items: center; text-align: left; justify-content: center; width: 60%; } Unfortunately, this approach did not work ...

The use of the display property with inline-block is not functioning correctly on mobile devices

Can anyone help me figure out why my divs are displaying differently on PC versus phone? They line up well on the computer, but on the phone, the last div is on a new line. Here is a snippet of my code and screenshots for reference. Thank you in advance fo ...

Using percentages for sizing and margins in CSS

Looking to create a visually appealing page that always fills the entire screen? Check out this code snippet that does just that: #posts{ width:100%; height:auto; background:#666; } .entry{ float:left; margin-left: 4%; margin-top:10 ...

Creating a multiline textarea with ellipsis using ReactJS

Looking to create a component with a multiline textfield that displays ellipsis (...) for text overflow beyond 2 lines. How can I achieve this through CSS only without modifying the actual stored text? Utilizing the React component found at: link Appreci ...

Is there a way in JQuery to apply the CSS of one element to another selected element?

I'm curious if there is a JQuery function available that can be used to transfer the exact CSS styles from one element to another. I want all the CSS properties to be applied without any additional inheritance. For example: <div id="d1"> &l ...

In the desktop view, padding, margins, and shadows mysteriously vanish, yet magically reappear when inspected. This bug stubbornly remains

Currently, I am working on a prototype portfolio site for a school project. My strength lies in the front end development area. Interestingly, when I check the site normally, there seems to be no padding or margin visible. However, upon using inspect eleme ...

individual elements displayed sequentially within the same block with variable naming

My code caters to both mobile and desktop versions, with the same elements in the FORM. However, only one block of code is visible at a time depending on the screen size, with one set to display: none. <div id="desktop"> <div id="content"> ...

What is the best way to achieve a seamless CSS transition for my sticky navigation bar?

Looking to create a sticky bar with a smooth CSS transition instead of the current rough effect. Any tips or hints would be greatly appreciated! For reference, I found the exact animation I'm aiming for on this website: https://css-tricks.com/ Here i ...