2015-10-23 4 views
0

В этой скрипке: http://jsfiddle.net/thbuf/110/div появляется перед | элемент

Разница «тест» появляется перед | элемент. Это происходит, несмотря на то, что «тест» добавляется после | , Есть ли проблема с css?

html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, code, del, dfn, img, q, dl, dt, dd, ol, ul, li, fieldset, form, label, legend { 
 
    /*table, tbody, tfoot, thead, tr, th, td*/ 
 
    margin: 0; 
 
    padding: 0; 
 
    border: 0; 
 
    outline: 0; 
 
    font-weight: inherit; 
 
    font-style: inherit; 
 
    font-size: 100%; 
 
    font-family: inherit; 
 
} 
 

 
html, body { 
 
    height: 100%; 
 
    background-color:#333; 
 
    color:#CCC; 
 
    font-family:Myriad Pro, Verdana; 
 
} 
 

 
#container { 
 
    position: relative; 
 
    min-height: 100%; 
 
    height: 100%; 
 
    height: auto;  
 
} 
 
html>body #container { 
 
    height: auto; 
 
} 
 

 
#page{ 
 
    padding:0 0 100px 0; 
 
} 
 

 
#content{ 
 
    padding:15px; 
 
} 
 
#content h1{ 
 
    font-size:3em; 
 
} 
 

 
#footer { 
 
    position: relative; 
 
    bottom:0; 
 
    width: 100%; 
 
    background-color:#CCC; 
 
    color:#333; 
 
    padding:20px; 
 
}
<div id='container'> 
 

 
    <div id='page'> 
 
    <div id='content'> 
 
     <h1>title</h1> 
 
     <p>some content would go here</p> 
 
     <p>Loet consectetur elementum, faucibus in nulla.</p> 
 
     <p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;.</p> 
 
    </div> 
 
    </div> 
 

 
    <div id='footer'> 
 
    <div style="display: inline">here is your footer</div> 
 
    <div style="display: inline; float:right;">|</div> 
 
    <div style="display: inline; float:right">test</div> 
 
    </div> 
 

 
</div>

+3

'поплавок: right' заставит элементы идти прямо, начиная с первого. Поменяйте порядок ваших 'div' в HTML. - http://jsfiddle.net/abhitalks/thbuf/113/ – Abhitalks

+0

@Abhitalks: Извините за отправку ответа. Страница не обновилась, и у меня не было возможности увидеть ваш комментарий. Если вы хотите опубликовать свой комментарий в качестве ответа, я удалю свой (или) добавит ссылку на ваш комментарий. – Harry

+1

@ Харри: Ничего. Хорошо, что вы ответили :) – Abhitalks

ответ

1

Это происходит из-за float: right на обоих элементы. Это заставляет их действовать так, как будто они сложены с правой стороны экрана, поэтому первый элемент в заказе документа становится первым справа, а затем вторым элементом.

Чтобы отменить их, вам просто нужно изменить порядок.

html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, code, del, dfn, img, q, dl, dt, dd, ol, ul, li, fieldset, form, label, legend { 
 
    /*table, tbody, tfoot, thead, tr, th, td*/ 
 
    margin: 0; 
 
    padding: 0; 
 
    border: 0; 
 
    outline: 0; 
 
    font-weight: inherit; 
 
    font-style: inherit; 
 
    font-size: 100%; 
 
    font-family: inherit; 
 
} 
 

 
html, body { 
 
    height: 100%; 
 
    background-color:#333; 
 
    color:#CCC; 
 
    font-family:Myriad Pro, Verdana; 
 
} 
 

 
#container { 
 
    position: relative; 
 
    min-height: 100%; 
 
    height: 100%; 
 
    height: auto;  
 
} 
 
html>body #container { 
 
    height: auto; 
 
} 
 

 
#page{ 
 
    padding:0 0 100px 0; 
 
} 
 

 
#content{ 
 
    padding:15px; 
 
} 
 
#content h1{ 
 
    font-size:3em; 
 
} 
 

 
#footer { 
 
    position: relative; 
 
    bottom:0; 
 
    width: 100%; 
 
    background-color:#CCC; 
 
    color:#333; 
 
    padding:20px; 
 
}
<div id='page'> 
 
    <div id='content'> 
 
    <h1>title</h1> 
 
    <p>some content would go here</p> 
 
    <p>Loet consectetur elementum, faucibus in nulla.</p> 
 
    <p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;.</p> 
 
    </div> 
 
</div> 
 

 
<div id='footer'> 
 
    <div style="display: inline">here is your footer</div> 
 
    <div style="display: inline; float:right">test</div> 
 
    <div style="display: inline; float:right">test</div> 
 

 
</div>

+1

Я действительно пытался найти ссылку в спецификациях для этого. Из (http://www.w3.org/TR/CSS21/visuren.html#float-position) Я думаю, что здесь применяется правило №7. Что сказать? – Abhitalks

+0

@Abhitalks: Да, 7 и 9 применяются. Первый элемент в порядке doc помещен как можно дальше, что означает, что следующий может быть помещен только его левым краем (потому что он не может двигаться дальше справа). – Harry

0

Просто добавьте новый DIV, чтобы содержать вложенные дивы так:

<div style="float:right"> 

Hind рабочий скрипку: here

Смежные вопросы