Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can CSS truly override the order of HTML elements on a page?

Tags:

If you have several divs on a page, you can use CSS to size, float them and move them round a little... but I can't see a way to get past the fact that the first div will show near the top of the page and the last div will be near the bottom! I cannot completely override the order of the elements as they come from the source HTML, can you?

I must be missing something because people say "we can change the look of the whole website by just editing one CSS file.", but that would depend on you still wanting the divs in the same order!

(P.S. I am sure no one uses position:absolute on every element on a page.)

like image 381
Magnus Smith Avatar asked Sep 18 '08 12:09

Magnus Smith


People also ask

Does overriding the normal styles of an HTML tag with CSS possible?

Adding the ! important keyword to any CSS rule lets the rule forcefully precede over all the other CSS rules for that element. It even overrides the inline styles from the markup. The only way to override is by using another !

Does the order of elements matter in HTML?

The Order of CSS Classes in HTML Doesn't Matter.

Which CSS property controls the order of stack of HTML elements?

The z-index property specifies the stack order of an element.


1 Answers

CSS can take elements out of the normal flow and position them anywhere, in any manner you want. But it cannot create a new flow.

By this I mean that you can position the last item from the html document at the beginning/top of the page/window, and you can position the first item from the html document at the end/bottom of the page/window. But when you do this you can't position these items relative to each other; you have to know for yourself how far down the end of the page will be for the first item from the html document to be positioned correctly. If that content is dynamic (ie: from a database or CMS), this can be far from trivial.

like image 72
Joel Coehoorn Avatar answered Oct 11 '22 12:10

Joel Coehoorn