Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the diference between Margin and Padding and contribution of the bounding box?

Tags:

wpf

xaml

Here is image to explain my question better

enter image description here

Every control has bounding box and every control has margins and padding. In the image The Gap between button border and the border of the bounding box is labeled as GAP-B, is this the padding or Margin?

Also there is gap between the two buttons GAP-A, is this the padding or margin?

like image 673
Phill Greggan Avatar asked Aug 12 '14 12:08

Phill Greggan


People also ask

What is the difference between margin and padding?

What is the Difference Between Margin and Padding. The main difference between margin and padding is that margin helps to create space around the element outside the border, while padding helps to create space around the element inside the border.

What is the difference between a border and a margin?

Padding is the space inside the border of a block that separates the border from the content. The margin is the spacing outside the border that separates a block from the adjacent blocks.

Is it possible to assign negative values for margin and padding?

It is not possible to assign negative values for those properties. The main difference between margin and padding is that margin helps to create space around the element outside the border, while padding helps to create space around the element inside the border.

What is padding in CSS box model?

Another part of the CSS box model, padding is the space between a border and the element within it. Padding surrounds the text or image within a certain boundary to prevent that content from touching the border, or box, around it. Like margins, you can create and change the amount of padding when designing a webpage.


1 Answers

Gap A is Margin and Gap B is Padding.

Padding on second Border

 <StackPanel>
    <Border  Height="100" Width="400" >
        <Button  Content="StackOverFlow" Background="Yellow"/>
    </Border>
    <Border Padding="20" Background="Lime"  Height="100" Width="400">
        <Button  Content="StackOverFlow" Background="Yellow"/>
    </Border>
</StackPanel>

Padding

Margin on second border

    <StackPanel>
    <Border  Height="100" Width="400" >
        <Button  Content="StackOverFlow" Background="Yellow"/>
    </Border>
    <Border Margin="20" Background="Lime"  Height="100" Width="400">
        <Button  Content="StackOverFlow" Background="Yellow"/>
    </Border>
</StackPanel>

Margin

like image 50
yo chauhan Avatar answered Nov 09 '22 15:11

yo chauhan