search

Home  >  Q&A  >  body text

How to remove the space below each line on the Tic-Tac-Toe board in Next.js using CSS?

Why is there a space below each line? (CSS)

I'm trying to make a Next.js tic-tac-toe app to test my skills. However, I'm having issues with css. There seems to be a padding issue under each row of boards - there is a small space under each row. Attached is a picture.

I tried setting padding and margin to 0 almost everywhere. This is my CSS.

body {
    background-color: black;
    height: 100vh;
    width: 100vw;
    margin: 0;
    padding: 0;
}

* {
    box-sizing: border-box;
}

h1, h2, h3, h4, h5, h6, p {
    margin-top: 0;
    padding: 0;
}

.square {
    height: 30vmin;
    width: 30vmin;
    font-size: 25vmin;
    border: 2px solid white;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: black;
    color: white;
    float: left;
    margin-top: -1px;
    margin-right: -1px;
    line-height: 30vmin;
    padding: 0;
}

.squareContainer {
    display: inline-block;
}

.boardContainer {
    border: 2px solid white;
    display: inline-block;
    margin: 0;
}

.container {
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
}

.boardRow:after {
    clear: both;
    content: '';
    display: table;
    padding: 0;
  }

This is the JSX of the motherboard:

<div className={styles.boardContainer}>
            <div className={styles.boardRow}>
                <Square value={squares[0]} onSquareClick={() => handleClick(0)}/>
                <Square value={squares[1]} onSquareClick={() => handleClick(1)}/>
                <Square value={squares[2]} onSquareClick={() => handleClick(2)}/>
            </div>
            <div className={styles.boardRow}>
                <Square value={squares[3]} onSquareClick={() => handleClick(3)}/>
                <Square value={squares[4]} onSquareClick={() => handleClick(4)}/>
                <Square value={squares[5]} onSquareClick={() => handleClick(5)}/>
            </div>
            <div className={styles.boardRow}>
                <Square value={squares[6]} onSquareClick={() => handleClick(6)}/>
                <Square value={squares[7]} onSquareClick={() => handleClick(7)}/>
                <Square value={squares[8]} onSquareClick={() => handleClick(8)}/>
            </div>
        </div>

For square:

<div className={styles.squareContainer}>
            <button className={styles.square} onClick={onSquareClick}>
                <p>
                    { value }
                </p>
            </button>
        </div>

I don’t know what the problem is, please help.

P粉004287665P粉004287665233 days ago1557

reply all(1)I'll reply

  • P粉828463673

    P粉8284636732024-04-06 10:55:58

    Must guess the HTML. Hope it matches yours. Commenting out the display: inline-block; rule of .squareContainer can solve this problem. Still, this css/html is overkill for this purpose. You can simplify it significantly.

    body {
        background-color: black;
        height: 100vh;
        width: 100vw;
        margin: 0;
        padding: 0;
    }
    
    * {
        box-sizing: border-box;
    }
    
    h1, h2, h3, h4, h5, h6, p {
        margin-top: 0;
        padding: 0;
    }
    
    .square {
        height: 30vmin;
        width: 30vmin;
        font-size: 25vmin;
        border: 2px solid white;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: black;
        color: white;
        float: left;
        margin-top: -1px;
        margin-right: -1px;
        line-height: 30vmin;
        padding: 0;
    }
    
    .squareContainer {
        /* display: inline-block;  */
    }
    
    .boardContainer {
        border: 2px solid white;
        display: inline-block;
        margin: 0;
    }
    
    .container {
        height: 100vh;
        width: 100vw;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    .boardRow:after {
        clear: both;
        content: '';
        display: table;
        
        padding: 0;
      }
    <body>
      <div class="container">
        <div class="boardContainer">
          <div class="boardRow">
            <div class="squareContainer">
              <div class="square"></div>
              <div class="square"></div>
              <div class="square"></div>        
            </div>
          </div>
          <div class="boardRow">
            <div class="squareContainer">
              <div class="square"></div>
              <div class="square"></div>
              <div class="square"></div>        
            </div>
          </div>
          <div class="boardRow">
            <div class="squareContainer">
              <div class="square"></div>
              <div class="square"></div>
              <div class="square"></div>        
            </div>
          </div>
        </div>
      </div>
    </body>

    reply
    0
  • Cancelreply