Using full width of view window without allowing scrolling horizontally

I’ve been trying to build a style guide sample app:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
  <link rel="stylesheet" href="./css/main.css"/>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css2?family=Chivo+Mono:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&family=Satisfy&display=swap" rel="stylesheet">
  <title>StyleGuide</title>
</head>
<header>
  <div class="title">
    <h1>Style Guide</h1>
  </div>
</header>
<body>
<div class="content">
  <h1>Colours</h1>
  <div id="colour-container">
    <div class="colour-swatch timberwolf">
      <div class="colour-text">
        <h3 class="color-name">timberwolf</h3>
        <h4 class="color-hex">#D1D1D1</h4>
      </div>
    </div>
    <div class="colour-swatch platinum">
      <div class="colour-text">
        <h3 class="color-name">platinum</h3>
        <h4 class="color-hex">#DBDBDB</h4>
      </div>
    </div>
    <div class="colour-swatch light-sky-blue">
      <div class="colour-text">
        <h3 class="color-name">light sky blue</h3>
        <h4 class="color-hex">#85C7F2</h4>
      </div>
    </div>
    <div class="colour-swatch brg">
      <div class="colour-text">
        <h3 class="color-name">british racing green</h3>
        <h4 class="color-hex">#003E1F</h4>
      </div>
    </div>
    <div class="colour-swatch wenge">
      <div class="colour-text">
        <h3 class="color-name">wenge</h3>
        <h4 class="color-hex">#69585F</h4>
      </div>
    </div>
  </div>
</div>
<div class="content">
  <h1>Fonts</h1>
  <div id="font-container">
    <div class="font-box cormorant-garamond">
      <h2 class="underlined">Cormorant Garamond</h2>
      <p class="regular">The quick brown fox jumps over the lazy dog.</p>
      <p class="italic">The quick brown fox jumps over the lazy dog.</p>
      <p class="bold">The quick brown fox jumps over the lazy dog.</p>
    </div>
    <div class="font-box chivo-mono">
      <h2 class="underlined">Chivo Mono</h2>
      <p class="regular">The quick brown fox jumps over the lazy dog.</p>
      <p class="italic">The quick brown fox jumps over the lazy dog.</p>
      <p class="bold">The quick brown fox jumps over the lazy dog.</p>
    </div>
    <div class="font-box satisfy">
      <h2 class="underlined">Satisfy</h2>
      <p class="regular">The quick brown fox jumps over the lazy dog.</p>
      <p class="italic">The quick brown fox jumps over the lazy dog.</p>
      <p class="bold">The quick brown fox jumps over the lazy dog.</p>
    </div>
  </div>
</div>
</body>
<footer class="platinum">
  <div>
    <p class="satisfy">Created by coreblaster34846</p>
  </div>
</footer>
</html>
.title {
  margin: 0;
  position: fixed;
  top:0;
  display: block;
  background-color: #003E1F;
  height: 100px;
  width: 100%;
  text-align: center;
  z-index: 999;
}
.title h1 {
  color: #69585F;
  font-family: "American Typewriter", serif;
  font-size: 40px;
  text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}

body {
  padding-top: 100px;
  padding-bottom: 110px;
  margin: 0;
  width: 100%;
}

.content {
  position: relative;
  top: 10px;
  margin: 10px 10px;
  border: black 1px solid;
  border-radius: 10px;
}

.content h1 {
  font-family: "American Typewriter", serif;
  font-size: 25px;
  text-align: center;
}
#colour-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  padding: 10px;
}
.colour-swatch {
  position:relative;
  border: black 1px solid;
  border-radius: 50%;
  margin: 10px;
  padding: 10px;
  height: 150px;
  width: 150px;
  text-align: center;
}
.colour-text {
  position: relative;
  display: block;
  top: 10px;
  height: fit-content;
  margin: 20px;
}
.color-name, .color-hex{
  font-family: "Andale Mono", serif;
  font-size: 15px;
  background-color: white;
  border-radius: 5px;
  padding: 2px;
}

.timberwolf {
  background-color: #D1D1D1;
}

.platinum {
  background-color: #DBDBDB;
}

.light-sky-blue {
  background-color: #85C7F2;
}

.brg {
  background-color: #003E1F;
}

.wenge {
  background-color: #69585F;
}

#font-container {
  width: 100%;
  height: fit-content;
  justify-content: space-around;
  text-align: justify;
  padding: 0 20px;
}

#font-container h2 {
  font-size: 20px;
}

.font-box {
  display: inline-grid;
  padding: 10px 20px;
  width: 25%;
}

.regular {
  font-style: normal;
}

.italic {
  font-style: italic;
}

.bold {
  font-weight: 700;
}

.underlined {
  text-decoration: underline;
}

.cormorant-garamond {
   font-family: 'Cormorant Garamond', serif;
}
.chivo-mono {
  font-family: 'Chivo Mono', monospace;
}

.satisfy {
  font-family: 'Satisfy', cursive;
}

footer {
  position: fixed;
  bottom: 0px;
  height: 100px;
  width: 100%;
  text-align: center;
}

It’s mostly the way I was trying to get it, but I’ve noticed that rather than being the full width of the view window, the body with the content has a bit of horizontal scroll to it. What am I doing wrong here?

Hi there!

The horizontal scroll is occurring because of the padding on #font-container. The extra padding is added to the overall width of the container, causing it to overflow its container—thus the horizontal scroll.

To fix this, you can apply box-sizing to all elements with the * selector.

* {
  box-sizing: border-box;
}

border-box makes it so padding and border-width are included in the overall width of an element.

Perfect! Thanks for the tip!

1 Like