Remove a linebreak after IMG
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>
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)
Try making the image and the div float:left; You WILL need to provide a width for each to make this work.
#starOfMonth
{
background: #ffff99;
float: left;
width: 275px;
height: 300px;
text-align: center;
font-family:"sans-serif";
white-space: normal;
}
#starOfMonthImage {
height:275px; /*Optional, but it's a good idea to supply height for images so that the browser doesn't shift things around during the loading process*/
width:475px; /*OR SOMETHING! Make it narrower if it isn't working, I haven't been super careful about reading your padding in depth so this may be wrong.*/
float:left;
}
Then you can write:
<div id="newsMainBody">
<img src="img/farm.jpg" alt="Farm photo" id="starOfMonthImage" />
<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>
On the assumption you're referring to the one with the alt-text of Farm photo
:
div#newsMainBody > img {
/* display: block; commented out as per @M2tM's comment, below */
float: left;
width: 200px;
}
#starOfMonth {
margin-left: 200px; /* or 'width of floated image' + 'a margin of 10px'
} /* or whatever, just so they're not physically touching */
Should achieve this, but I'm unsure why you've got a floating <br />
inside the #starOfMonth
div. That might be a problem.
Live demo, over at jsbin (obviously the image
s don't load (given the src
isn't pointing at anything, but it should give you a feel for what my approach does.)
精彩评论