1

If there is a specific name for the following thing, please tell me so I can make some proper research (so far what came up from my searches was things with the z index which is something totally different).

Alright, Consider the following situation. You have:

<div class="foo">Foo</div>
<div class="bar">bar</div>

Suppose the classes are defined in css sheets, so when you add another css sheet they change.

For the properties like font, color, bg it clear to me.

The question is how to modify their position. Consider that I want the following output: (you can only change the css) 'Foo' to be second, 'bar' to be first. 'foo' and 'bar' to be on one row.

PS: if there is a specific name for this (changing position with css styles) please tell me.

4 Answers 4

2

Changing index is not possible through css you can just style them:

http://jsfiddle.net/K9Pj8/

like

.foo{ position: relative; top: 20px;}
.bar{ position: relative; top: -20px;}

There is a further more you can do it with a wrapper like this example:

http://jsfiddle.net/K9Pj8/1/

Sign up to request clarification or add additional context in comments.

4 Comments

Interesting. That might as well be what I am looking for.
Probably be better to use em rather than px for the unit, more robust that way.
@steveax em are dependent on font-size in px too
Indeed, and the also scale more gracefully :-)
1

You have several options to position divs with css.

position is one of them.

For a more flexible solution you can also use float.

Whatever you need on the right assign float:right;

Whatever you need on the left assign float:left;

Demo

http://jsbin.com/oluyay/1/edit

Comments

0

Try manipulating position css attribute with top, left, bottom, right as required. If you want them to be one after another horizontally, you can try float:left

Comments

0

Yes, you have to use css floats to achieve it.

A float simply pushes elements to a specified direction and stacks up according to available space.

To get the result you need to apply this,

.foo, .bar { float: right; }

Make sure you have these tags wrapped in a parent element and make it as inline-block, or else they will float to end of full block

Check this fiddle http://jsfiddle.net/8hAmw/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.