The CSS margin properties define the space around elements.
Questions tagged [margin]
3723 questions
143
votes
8 answers
How do negative margins in CSS work and why is (margin-top:-5 != margin-bottom:5)?
A common trick for vertical positioning elements is to use the following CSS:
.item {
position:absolute;
top:50%;
margin-top:-8px; /* half of height */
height: 16px;
}
When seen in the metric view as in Chrome this is what you…

PhD
- 11,202
- 14
- 64
- 112
140
votes
6 answers
Why can't I center with margin: 0 auto?
I have a #header div that is 100% width and within that div I have an unordered list. I have applied margin: 0 auto to the unordered list but it won't center it within the header div.
Can anybody please tell me why? I thought that if I define the…

zeckdude
- 15,877
- 43
- 139
- 187
140
votes
2 answers
margin-top only when the flex item is wrapped
I have a flex container with two flex items. I want to set a margin-top on the second one, but only when it's wrapped and not at the first flex line.
If possible, I want to avoid using media queries.
I thought margin-bottom on the first element…

Manuel Di Iorio
- 3,631
- 5
- 29
- 31
122
votes
16 answers
CSS Cell Margin
In my HTML document, I have a table with two columns and multiple rows. How can I increase the space in between the first and second column with css? I've tried applying "margin-right: 10px;" to each of the cells on the left hand side, but to no…

Tom
- 4,341
- 9
- 27
- 21
121
votes
8 answers
jQuery How to Get Element's Margin and Padding?
Just wondering - how using jQuery - I can get an elements formatted total padding and margin etc ? i.e. 30px 30px 30px 30px or 30px 5px 15px 30px etc
I tried
var margT = jQuery('img').css('margin');
var bordT = jQuery('img').css('border');
var…

Tom
- 1,229
- 2
- 8
- 5
118
votes
8 answers
How to align two elements on the same line without changing HTML
I have two elements on the same line floated left and floated right.
element 1 markup
element 2…

user1074378
- 1,405
- 3
- 15
- 14
111
votes
10 answers
Auto margins don't center image in page
In this example the image is not centered. Why? My browser is Google Chrome v10 on windows 7, not IE.


Web_Designer
- 72,308
- 93
- 206
- 262
94
votes
9 answers
Remove all padding and margin table HTML and CSS
I have this table :
and…
je suis | |
1 | 2 |

begiPass
- 2,124
- 6
- 36
- 57
89
votes
9 answers
Setting Margin Properties in code
MyControl.Margin.Left = 10;
Error:
Cannot modify the return value of 'System.Windows.FrameworkElement.Margin' because it is not a variable

Giffyguy
- 20,378
- 34
- 97
- 168
86
votes
11 answers
Does bootstrap have builtin padding and margin classes?
Does Bootstrap have built-in padding and margin classes like pad-10, mar-left-10 or I have to add my own custom classes? For example, similar to the ones here at padding and margin tabs.

Ozgur Erdogan
- 1,133
- 1
- 8
- 13
86
votes
7 answers
How to remove padding around Android CheckBox
I need to put check to the right hand top corner of my imageview. But when I do this I noticed a default margin around my checkbox. Is there a way to remove this??

Lincy
- 1,033
- 1
- 8
- 14
86
votes
4 answers
How to get margin value of a div in plain JavaScript?
I can get height in jQuery with
$(item).outerHeight(true);
but how do I with JS?
I can get the height of the li with
document.getElementById(item).offsetHeight
but i will always get "" when I try…

YuC
- 1,787
- 3
- 19
- 22
84
votes
2 answers
How do I force a vertical scrollbar to appear?
My site has both very short and longer pages. Since I center it in the viewport with margin: 0 auto, it jumps around a few pixels when switching from a page that has a scrollbar to one that hasn't and the other way around.
Is there a way to force…

Bakabaka
- 1,505
- 1
- 13
- 21
76
votes
5 answers
Flutter Layout Container Margin
I have a problem with my Flutter Layout.
I have a simple container with a Margin right and left of 20.0
Inside this container i have another container.
But this container does not fit to the parent container only on the left side.
I dont know why…

M. Berg
- 921
- 2
- 8
- 11
74
votes
10 answers
UIButton Text Margin / Padding
I have the following layout, and I'm trying to add a padding to the left and right..
The controls are a disabled UIButton.
My code for creating a button is this:
UIButton *buttonTime = [[UIButton alloc] initWithFrame:CGRectMake(90, 10, 50, 20)];…

PartySoft
- 2,749
- 7
- 39
- 55