![]() ![]() |
| sameer shaik |
Sep 5 2012, 03:04 AM
Post
#1
|
|
Group: Members Posts: 6 Joined: 16-August 12 Member No.: 17,617 |
we add negative margin values for top and left but why should we add values for bottom and left also.
why this? margin: -5px 5px 5px -5px why it cant be this? margin: -5px 0px 0px -5px because we want our image to move top and left in negative direction but why should we also add values for right and bottom sides? pls clarify thanks... |
| pandy |
Sep 5 2012, 06:37 AM
Post
#2
|
|
Don't like donuts. Don't do MySpace. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: WDG Moderators Posts: 13,731 Joined: 9-August 06 Member No.: 6 |
You can use just "margin-top: -5px, margin-left: -5px", that is leave the other values out altogether.
Theoretically what you suggest would stretch the image. You move the top-left margins but say the bottom-right ones should stay where they were. I don't know if any browser does this now, I can't find one. Maybe the rules have changed. I'm sure that at one point it was possible to stretch a box with margins in the most CSS aware browsers but I don't manage to do it now. -------------------- |
| Christian J |
Sep 5 2012, 11:50 AM
Post
#3
|
|
. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: WDG Moderators Posts: 4,776 Joined: 10-August 06 Member No.: 7 |
we want our image to move top and left in negative direction but why should we also add values for right and bottom sides? In the first example a block element like a DIV should be moved. In the second it should become stretched, assuming that the width is "auto" (otherwise it will move there, too). Can't remember exactly why all this happens, the W3C spec can be very vague about things like this. Images (like in your example) have intrinsic width, so maybe they can't be stretched this way. |
| Christian J |
Sep 5 2012, 11:50 AM
Post
#4
|
|
. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: WDG Moderators Posts: 4,776 Joined: 10-August 06 Member No.: 7 |
I'm sure that at one point it was possible to stretch a box with margins in the most CSS aware browsers but I don't manage to do it now. It still works: CODE <style type="text/css"> body { border: solid blue; margin: 3em; width: 20em; } p { border: 1px solid red; margin: 0; } p#t {margin-top: -5px;} p#r {margin-right: -5px; width: auto;} p#rw {margin-right: -5px; width: 20em;} p#b {margin-bottom: -5px;} p#l {margin-left: -5px; width: auto;} p#lw {margin-left: -5px; width: 20em;} p#lr {margin-left: -5px; margin-right: 5px; width: auto;} p#lrw {margin-left: -5px; margin-right: 5px; width: 20em;} </style> <p id="t">top</p> <p id="r">right, auto width</p> <p id="rw">right, explicit width</p> <p id="b">bottom</p> <p id="l">left, auto width</p> <p id="lw">left, explicit width</p> <p id="lr">left+right, auto width</p> <p id="lrw">left+right, explicit width</p> |
| pandy |
Sep 5 2012, 01:22 PM
Post
#5
|
|
Don't like donuts. Don't do MySpace. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: WDG Moderators Posts: 13,731 Joined: 9-August 06 Member No.: 6 |
Yeah. My test DIVs had a width.
I just want to point a thing out. QUOTE but why should we add values for bottom and left also. That is the springing point. You CAN leave them out. But you don't do that in you example. Setting them to zero isn't leaving them out. It's specifying exactly how wide they should be, even if that width is 0. -------------------- |
| Jaycbrf4 |
Sep 5 2012, 02:17 PM
Post
#6
|
|
Member ![]() ![]() ![]() Group: Members Posts: 33 Joined: 9-August 12 Member No.: 17,587 |
If you leave them out, they will default to browser defaults
http://www.w3.org/TR/CSS21/sample.html |
| pandy |
Sep 5 2012, 02:27 PM
Post
#7
|
|
Don't like donuts. Don't do MySpace. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: WDG Moderators Posts: 13,731 Joined: 9-August 06 Member No.: 6 |
It isn't likely there will ever be a browser that adds margins to IMG.
-------------------- |
![]() ![]() |
|
Lo-Fi Version | Time is now: 25th May 2013 - 12:44 AM |