简体   繁体   中英

How to adjust space between items along the main axis in a flex cotainer

在此处输入图片说明 I am trying to decrease the margin between the (header__title-title) and the first item (header__title-symbol) in the flex container. I can't seem to get anything to work. Any suggestions? The main axis is vertical since I have the flex-direction set to column

<div class="header__title">
        <div class="header__title-symbol">
          <span class="span-one"><hr id="hr-one" /></span>
          <span id="symbol">&#11033;</span>
          <span class="span-two"><hr id="hr-two" /></span>
        </div>
        <div class="header__title-title">
          <h1>The Website title!</h1>
        </div>
      </div>


.header__title {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}


.header__title-title {
  letter-spacing: 4px;
  color: white;
  font-size: 2.5rem;
  text-shadow: 0 4px 4px #d19224;
  animation-name: moveInLeft;
  animation-duration: 1s;
  font-family: "Zen Kaku Gothic Antique", sans-serif;
}

.header__title-symbol {
  display: flex;
  flex-direction: row;
  align-items: center;
}

hr {
  width: 27rem;
  display: inline-block;
  height: 0.3rem;
  background-color: white;
}

I think your problem does not related to CSS flex property. you could add these lines in your CSS file:

 *, *::after, *::before { padding: 0; margin: 0; -webkit-box-sizing: border-box; box-sizing: border-box; }

This code resets the margin and padding of all elements in your html file. Then you can set each amount of margin or padding that you want to the .header__title-title class that is suitable for your design. for example:

 .header__title-title { padding-top: 20px; }

There are multiple ways by which you can achieve this.

  1. Add a margin-top or margin-bottom; to the ones you want to add space.
  2. When you add display: flex and flex-direction: column, then by using justify-content: space-between;

Hope this works for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM