Front-end development isn’t my forte. I’ve re-created an issue in JSfiddle (https://jsfiddle.net/3uztg7ao/2/) as you see, for some strange reason, the text just randomly drops below the image.
I’ve noticed that it is when the text is in a long string without spaces. I’ve tried everything in my knowledge (not much) to fix it, but no avail.
I am wanting the text to remain on a singular line until the line break
I believe the issue is in the following css code block:
* {
padding: 0;
margin: 0;
box-sizing: border-box;
text-decoration: none;
}
body {
font-family: arial;
background: #FFFFFF;
}
.threadReply {
border: 1px solid #d9edff;
background-color: #dff0ff;
font-family: arial;
font-size: 14px;
max-width: 95%;
width: max-content;
color: #333333;
overflow: hidden;
padding: 5px 5px 5px 5px;
margin: 25px;
}
.threadReply:target {
border: 1px solid #ffe9d3;
background-color: #ffefdf;
}
.threadReply #replyInfo {
border: none;
font-family: arial;
font-size: 13px;
color: #333333;
padding: 5px 10px 0px 5px;
}
.threadReply #replyCount {
border: none;
font-family: arial;
font-size: 12px;
color: #333333;
padding: 5px 10px 5px 5px;
}
.threadReply #replyInfo a {
border: none;
color: #0000EE;
text-decoration: none;
}
.threadReply #replyInfo a:hover {
border: none;
color: #0000EE;
text-decoration: underline;
}
.threadReply #replyInfo .replyLink {
border: none;
color: #0000EE;
font-size: 12px;
text-decoration: none;
}
.threadReply #replyVote {
border: none;
font-family: arial;
font-size: 12px;
color: #333333;
padding: 0px 10px 10px 5px;
}
.threadReply #replyVote a {
border: none;
font-family: arial;
font-size: 12px;
color: #0000EE;
outline: none;
text-decoration: none;
}
.threadReply #replyVote a:hover {
border: none;
font-family: arial;
font-size: 12px;
color: #0000EE;
outline: none;
text-decoration: underline;
}
.threadReply .replyImage-resize {
border: 1px solid #DDDDDD;
float: left;
overflow: hidden;
max-width: 125px;
cursor: pointer;
margin: 0px 15px 10px 10px;
}
.threadReply #replyMessage {
border: none;
font-family: arial;
font-size: 14px;
color: #333333;
padding: 0px 10px 10px 20px;
}
.threadReply #replyMessage a {
border: none;
font-family: arial;
font-size: 14px;
color: #333333;
text-decoration: none;
}
.threadReply #replyMessage a:hover {
border: none;
font-family: arial;
font-size: 14px;
color: #333333;
text-decoration: underline;
}
<div class='threadReply'>
<div id='replyInfo'>
<p>Anonymous 06/08/2023 10:10:47 No.76 <a href='#nav' onclick='reply(this)'>[Reply]</a></p>
</div>
<div id='replyVote'>
<p>[thread creator][Authentic]</p>
</div>
<div id='replyContent'>
<img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQKByNgCmuW5bGdNNG0kCxIItgmAsPzu0w_vQ&usqp=CAU' class='replyImage-resize'>
<div id='replyMessage'>
<p>>be mod/janny/retard/whatever<br> >get challenged<br> >ban
<br> >still not providing proof<br>
<br> many such cases</p>
</div>
</div>
<div id='replyCount'>
<p><a href='javascript:void(0);' class='reportReply'>[Report]</a></p>
</div>
</div>
Thank you in advance.
4
Answers
The issue you’re seeing where the text is splitting between being beside the image to then being underneath is due to the use of
float: left
on the image andwidth: max-content
on the container. Please see the MDN on float for details about how float works.When that float is combined with
width: max-content
, it means your container will take the size of the largest content, which in this case is the text. Then, when the browser tries to wrap the text around the image because of the float, it does not have the space to handle a long string due to the constraint imposed bymax-content
.To fix this, there are a few options to consider:
word-break: break-all
orword-break: break-word
on the textOf course, each option has its own pros/cons, so it’s up to you to decide what will work best for your use case.
Cheers.
Different ways to go about this but one solution is to define row/column layout using grid or flexbox for your
img
and#replyMessage
content. Using flexbox below.Small tweak to your html by wrapping your image with a
<div>
and adding the below styles.Took a stab at this – removed a lot of CSS, some you may need for the
:target
but did not apply to the question.Put some borders on to show what was where – just remove those CSS lines.
You can decide how you want that image sized and if you want the
text-align:left
instead of center etc.Just add float:left to your #replyMessage and you should be right as rain