Struggling with Text Wrapping in HTML and CSS

Hello, I am completely new to the world of HTML and CSS and I am currently working on creating a small website for a project. Unfortunately, I have hit a roadblock when it comes to text wrapping.

The problem arises when the length of the window is smaller than the text itself and the text wraps to the next line. At this point, it doesn't follow the margins that I have set, and I am unsure how to resolve this issue or even what to search for in order to find a solution.

For reference, here is a screenshot showcasing the problem: Text wrapping issue.

body {
  color: white;
  background-color: #131516
}

.headerblock {
  padding: 10px;
  background-color: black;
  margin-top: 0px;
  margin-left: 0px;
  color: #5b5b5b;
  font-size: 30px;
  transition: 0.2s;
  box-sizing: border-box;
  text-align: center;
  width: 100%;
}

.headerblock:hover {
  color: white;
  transition: 0.2s;
}

help {
  padding: 20px;
  word-break: normal;
  width: fit-content;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aecc... 

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>

<div class="headerblock">
  DEEZ NUTZ
</div>

<body>
  <help>
    Welcome to my webpage. This is where I post things that I want on my webpage. Anything I post will appear here on my webpage.
  </help>

Answer №1

If you find that your text is not getting the right padding when resizing the screen, consider tweaking your CSS a bit. Adding 'display: flex;' can help ensure that the padding stays consistent even as the text moves to the next line.

help {
  display:flex;
    padding-left: 20px;
    word-break: normal;
}

Flexbox is handy when you need to arrange items in a specific direction and control their dimensions or spacing. It's great for fine-tuning the layout of elements in a row or column.

Answer №2

To ensure your text remains tidy and contained within an element, the most effective method is to utilize the <p> (paragraph) element. This element automatically wraps your text, providing spacing above and below it. By adding some additional padding, you can maintain a more organized appearance and keep paragraph text properly contained.

.help {
  padding: 20px;
}
<p class='help'>
  Welcome to my site. Here I share content that I wish to display. Any posts will be showcased here on this page.
</p>

Answer №3

In case word-wrap isn't functioning as expected, consider using text-wrap: pretty;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

exclude the last item in flexbox from wrapping using the nowrap property

I have implemented flexbox nowrap on my container and I am wondering if it is possible to use CSS, without JavaScript, to push the last item in the container onto a new line at a specific width. This should be done using media queries and I am open to us ...

Apply a specific class using JavaScript/jQuery when a user selects a specific timezone from the user interface

Currently, I am coding in HTML with the code below extracted from this website link. The listings under timezone ET are all correct as they align with the accurate dates; however, for other timezones (PT, MT, CT, AT, NT) some shows seem to be on incorrect ...

I'm struggling with creating animations for the bootstrap cards as a newbie. It seems quite complex for me. Can anyone provide guidance on how to achieve this

Explore this template for bootstrap cards here The provided link features a template for bootstrap cards with horizontal sliding animations. I attempted to incorporate only the card properties into my code but encountered issues where the cards overshadow ...

Is there a way to deactivate the previous button for today's date?

I need assistance with disabling the previous button on today's date in my calendar. It is crucial that users are only able to select the start date from today onwards. I am currently utilizing moment.js for my Datepicker. Any help would be greatly ap ...

How to Create a Dynamic CSS Mobile Menu Animation

After checking out some online tutorials, I managed to get a hamburger menu working. However, I encountered an issue with the X icon not being symmetrical after the animation from 3 bars to an X. Here is the comparison: Before: https://gyazo.com/351864d8 ...

Modifying the appearance of InputText through CSS encapsulation

I'm a newbie to using Blazor and I'm currently experimenting with changing the style of InputText by utilizing css isolation. Interestingly, I've managed to successfully change the style when setting it inline or internally, however, things ...

What is the best way to position an element in the center of the screen

What is the best way to vertically center a button within a div? Click here for an image of the issue I recently started learning HTML & CSS and I am struggling to align a button in the vertical center of a div. Text-align:center doesn't seem to be ...

What is the best way to achieve a full-width navbar with the scrollbar positioned below it?

I have a similar code to what's shown here The menu is fixed, but the scrollbar seems to be appearing from the right of the navbar What I want is for the scrollbar to start below the menu instead see image example here ...

The checkbox event listener becomes dysfunctional when the innerHTML of its container is modified

My current challenge involves creating checkboxes with a blank line inserted after each one. I also need these checkboxes to trigger a function when changed. This is my code snippet: var div = document.getElementById("test"); var cb1 = document.createEl ...

Methods for Deactivating an Individual HTML Button

I have a situation in my HTML page where there are 6 buttons with values ranging from 1 to 5, and the sixth button has the value "disable". What I am trying to achieve is the ability to disable a specific button by clicking the "disable" button using jQuer ...

What is the best way to align the Storefront Menu in the center?

If you want to reproduce the issue I'm facing, visit the demo page of the storefront here: then remove the node <ul id="site-header-cart" class="site-header-cart menu"></ul> that contains the cart box (located next to the menu) so that on ...

Ensuring the correct width for a .png image in an email newsletter for Outlook 2013

After creating an email newsletter that works perfectly on all email clients except Outlook 2013, I realized that the image I included is not adhering to the table width specified. Instead, it is defaulting to its own width of 658px. View image here Below ...

Function being called from TypeScript in HTML is not functioning as expected

Hello, I am currently using Django and looking to implement TypeScript for a specific function within my application. Below is the content of my TypeScript file: testselector.ts: getSelectionText() { var text = ""; if (window.getSelection) { ...

Identify modifications in the content within an iframe, where the content is constantly changing due to the use of

Alright, so I have a jQuery mobile enabled page that is being loaded inside an iFrame. Typically, if I want to detect changes in the content of an iFrame, I would use: $('iframe').load(function(){ //content changed! }); However, in this par ...

Problem: Toggle functionality not working properly in JavaScript

As a beginner, I am facing an issue with multiple toggle buttons. They work fine individually, but when nested within each other, only one toggle button works. After some research, I realized that I need to make adjustments to my JavaScript code. However, ...

Tips for positioning and resizing an HTML slide

Once again I am faced with my favorite HTML/CSS dilemma and am feeling frustrated. Seeking advice from the experts on SO this time around to solve my problem. Here it is... Imagine you want to create a slideshow in a browser. The requirements are simple: ...

What could be causing this strange striping effect in the radial gradient?

What causes the striped effect in the radial gradient code provided on this website: click here to view body { background: rgba(216,215,221,1); background: -moz-radial-gradient(center, ellipse cover, rgba(enter code here216,215,221,1) 0%, rgba(0,9 ...

What is the solution for incorporating multiple elements in knockout's applyBindingsToNode function?

I am currently using knockout applyBindingsToNode to dynamically add and remove elements in order to update my html. I need to cut the binding, which is why I am utilizing applyBindingsToNode. In an example I have provided, if you click on the button "Reb ...

Using force-directed layout to access and retrieve specific data from external or internal data sources

Just starting out with d3js and currently working on modifying the Force directed layout found at http://bl.ocks.org/mbostock/1153292 I have managed to make it so that when I hover over the node circles, the corresponding source value filenames should app ...

Are there any methods to adjust the spacing of bootstrap card grids and optimize the maximum limit?

Having a bit of an issue with my bootstrap cards in a Flask for loop. It's working fine, but every time I pass 3 cards, a new column starts and messes up the layout. Check out this screenshot for an example: https://ibb.co/jTvtSbq Also, the vertical ...