Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a linebreak after IMG

Tags:

html

css

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>
like image 563
Matthew Cox Avatar asked Oct 01 '10 23:10

Matthew Cox


People also ask

How do I stop a line break in HTML?

There are several ways to prevent line breaks in content. Using &nbsp; 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.

How do you remove a line break in CSS?

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.

How do you start a new line after an image in HTML?

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.

How do you prevent a line break with an H1 H2 h3 tag?

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.


1 Answers

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)

like image 172
Retired_User Avatar answered Oct 20 '22 17:10

Retired_User