Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unwanted line of text in div

Tags:

html

css

So, I got a problem I've been trying to figure out for a while. I'm getting an extra row of text (or so it seems) in my DOM-structure that as far as I can tell is added by the browser. This happens in all browsers I've run the code in (IE8, IE9, Chrome 20, Firefox 11) and I want to remove it.

This is my HTML:

<div id="wrapper">
    <div id="inner">
        <div class="item">
            content
        </div>
    </div>
</div>​

And this is my CSS:

#wrapper {
    bottom: 0;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
}
.item {
    float: left;
    width: 171px;
    position: relative;
    background: #fc0;
}

And here is a jsfiddle showing my problem: http://jsfiddle.net/henrikandersson/wMg2m/

As you can see, there is a gap between the top and the yellow item, which as far as I can tell is caused by a line of text above the #inner-div that should not be there.

like image 575
Henrik Janbell Avatar asked Jul 09 '12 10:07

Henrik Janbell


People also ask

How do I stop div text wrapping?

If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).

How do I break a line inside a div?

You can insert line breaks in HTML with the <br> tag, which is equivalent to a carriage return on a keyboard.

How do I stop text from going to a new line in CSS?

To prevent the text from wrapping, you can use the CSS white-space property with the “nowrap” or “pre” value. In this snippet, you can see examples with both of them.


2 Answers

You have an invisible control-command &65279; following the closing > of your wrapper div. Its actually the HTML-encoded byte order mark.

Just delete that one and you'll be fine.

See this updated fiddle.

like image 54
Sirko Avatar answered Oct 30 '22 16:10

Sirko


You have got a special character just after <div id="wrapper"> that is invisible.

So this works:

<div id="wrapper">
    <div id="inner">
        <div class="item">
            s
        </div>
    </div>
</div>

I retyped the code that you had, this fixed the problem.

The problem could be copy and pasted code, or your text editor.

Notepad++ is the best free Windows text editor.

I found the problem by pasting your code in an ANSI-encoded text file in Notepad++. ANSI cannot display that character, so it changes to a ?.

like image 34
uınbɐɥs Avatar answered Oct 30 '22 15:10

uınbɐɥs