I have an img element set next to a div. I have tried a couple of different approaches to remove the linebreak that is occurring between the two but have not had any success. Any input would be greatly appreciated!
CSS
#newsMainBody
{
margin-right: auto;
margin-left: auto;
background:#61bc49;
width: 750px;
height: 900px;
font-family:"sans-serif";
text-align:left;
-moz-border-radius: 10px;/*mozilla*/
z-index: 1;
white-space: nowrap;
}
#starOfMonth
{
background: #ffff99;
width: 275px;
height: 300px;
text-align: center;
font-family:"sans-serif";
white-space: normal;
}
HTML
<div id="newsMainBody">
<img src="img/farm.jpg" alt="Farm photo" />
<div id="starOfMonth">
<br />
<font style="font-weight:bold;font-size:medium; color:Purple;">DooLittle Farms Childcare</font><br />
<font style="font-size:small;">"We're Growing Great Kids"</font><br />
<img id="starImg" src="img/gold-star.jpg" alt="Star of the Week" width="200" height="200"/><br />
Our Star Of The Week!
</div>
</div>
There are several ways to prevent line breaks in content. Using is one way, and works fine between words, but using it between an empty element and some text does not have a well-defined effect. The same would apply to the more logical and more accessible approach where you use an image for an icon.
The white-space property has numerous options, all of which define how to treat white space inside a given element. Here, you have set white-space to nowrap , which will prevent all line breaks.
The BR tag is used to force line breaks within text. Normally, linebreaks are treated as a space by browsers (except inside the PRE tag). The optional CLEAR attribute is used when you have an IMG image in your text. If that image uses ALIGN=LEFT or ALIGN=RIGHT, the text will flow around it.
You may want to format header tags like H1 and H2 as inline and prevent a break straight after them. Removing padding and margin does not remove the new line. By default, header tags take up all the horizontal space where they appear.
Add:
#newsMainBody img {
float: left;
}
#startOfMonth {
float: right;
}
and remove the first <br />
after <div id="starOfMonth">
, it's useless (use padding-top in css instead if you need some space)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With