Search code examples
htmlcssresponsiveword-break

Text overlapping when screen size is to small


I am currently making my study project page. I want it to be responsive as it is a part of it. However, when the screen size is to small words in head, section and body are overlapping. I can't make the words go to another line if there is not enough space for all of them (for whole sentence). I've tried using word-break, but it didn't work. Does anyone have idea what can I do to change it?

<html lang="pl-PL">
  <head>
    <meta charset="UTF-8"/>
    <link rel="stylesheet" type="text/css" href="css.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="My hobby page.">
    <meta name="keywords" content="books, hobby">
    <meta name="author" content="Bogna Gondek">
    <link rel="stylesheet" href="css.css">
    <script type="text/javascript" src="js.js"></script>
    <title>Książki Moje Hobby | Witamy</title>
  </head>
<body>
    <header>
         <h1>Książki Moje Hobby</h1>
         <nav>
           <ul>
             <li><a class="aktywny" href="strona_główna.html">Strona Główna</a></li>
             <li><a href="kontakt.html">Kontakt</a></li>
           </ul>
         </nav>
    </header>
    <div id="wnętrze">
      <section>
      <h2>„Bajki są więcej niż prawdą: nie dlatego, że mówią nam, że smoki istnieją, ale dlatego, że mówią, że smoki można pokonać.”</h2>
      <h3>― Neil Gaiman, „Coraline"</h3>
    </section>
    </div>
    <footer>
    Książki Moje Hobby, Copywright &copy; 2019
    </footer>
  </body>
</html>

body
{
font-family: Times, Courier, Verdana, Comic, Arial;
font-size: 20px;
line-height: 2px;
padding:0;
margin: 0;
background-color: white;
}

header
{
  width: 100%;
  margin: auto;
  overflow: hidden;
  padding-top: 20px;
  min-height: 70px;
  background-color: #404040;
}

header h1
{
  margin-left: 20px;
  float:left;
  color: #f2f2f2;
}

header nav
{
  float:right;
  margin-top:10px;
  margin-right: 20px;
  margin-bottom: 20px;
}

header li
{
  float:left;
  display:inline;
  padding: 0 20px 0 20px;
}
header a
{
  text-decoration: none;
  color: #f2f2f2;
  font-size: 22px;
}
header a:hover
{
  font-weight: bold;
}
header .aktywny
{
  color:  #b3b3b3;
}
div#wnętrze
{
  max-width:100%;
  height: 100%;
  margin: auto;
  overflow: hidden;
  background:url("obrazki/glownyobrazek.jpg") no-repeat 0;

  color: #f2f2f2;

  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

section
{
  background-color: red;
  max-width: 80%;
  word-wrap: break-all !important;
}
footer
{
  padding: 20px;
  margin-top: auto;
  background-color: #404040;
  text-align: center;
  color: #f2f2f2;
}

Solution

  • The issue is the line-height you have set on the body.

    body
    {
    font-family: Times, Courier, Verdana, Comic, Arial;
    font-size: 20px;
    line-height: 1;
    padding:0;
    margin: 0;
    background-color: white;
    }