Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I ensure the text stays within the container and doesn't overflow?
#4
Why does the text inside my <h1> tag exceed its container's width and overflow to the next line? I want the text to stay within the container without any overflow. Here's my HTML and CSS code:


HTML:

Code:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>

<div class="container">
 <h1>Welcome to My Website with a Long Title</h1>
</div>

</body>
</html>

CSS (styles.css):

Code:
.container {
 width: 300px;
 border: 1px solid #ccc;
 padding: 20px;
}

h1 {
 font-size: 24px;
 margin: 0;
 padding: 0;
}
I expected the <h1> text to automatically adjust its size to fit within the container's width, but it overflows. How can I ensure the text stays within the container and doesn't overflow?
Reply


Messages In This Thread
How can I ensure the text stays within the container and doesn't overflow? - by tom22 - 08-17-2023, 01:22 AM

Possibly Related Threads...
Thread Author Replies Views Last Post
  Communism doesn't work? Shocking state of $29m government-run supermarket in KC LevelUP 15 3,198 07-30-2025, 11:39 PM
Last Post: NotJoeBiden
  Family Moves to Russia to Escape Woke LGBTQ Ideology, But It Doesn't Go Very Well Jonathan Whatley 4 3,213 07-25-2024, 09:29 AM
Last Post: Charles Fout
  Text Neck Pro - FREE bjcheung77 1 1,635 12-29-2020, 05:07 PM
Last Post: SweetsugarNL
  Straighterline Text books Tasman 5 2,513 11-20-2010, 11:20 PM
Last Post: burbuja0512

Forum Jump:


Users browsing this thread: 1 Guest(s)