remove parent padding for child div

ignore parent padding android
child div width exceeding parent div
css div full width of screen
css margin
css full width image
css remove padding from child
css get parent width
css child wider than parent

I have a div#B in the div#A in HTML. div#A has padding in the CSS file and I want to doesn't affect on the div#B; I tried this ↓ but because of percent format they have, it doesn't work (doesn't fit completely to parent div because of the percent)!

div#wrapper {
  width: 80%;
  margin: 5px auto;
  background: blue;
}
#sidebar {
  float: left;
  width: 19%;
  margin-right: 1%;
  background: green;
  border-radius: 5px;
}
#A {
  padding: 0.5% 2%;
  width: 76%;
  background: red;
  float: right;
  margin-bottom: 5px;
}
#B {
  border-radius: 5px 5px 0 0;
  height: 116px;
  background: green;
}
<body style="background: aqua;">
<div id="wrapper">
  <div id="sidebar">this is sidebar and there is something here i dont know for now :))</div>
  <div id="A">
    <div id="B">
    </div>
  </div>
</div>
</body>

it works fine, made few minor updates to your css, have a look at the below-working snippet :)

#A {
  padding: 1%;
  background: red;
}
#B {
  margin: -1%;
  background: green;
}
<div id="A">
  <div id="B">&nbsp;</div>
</div>

Ignore parent padding, How do you make a child div bigger than a parent? However the key elements above are offset any parent padding with matching negative margins on the child. Then most critical if you want to run the child full-width then set width to auto. (as mentioned in a comment above by schlingel ).

If you add padding on your B, it will be solve your problem.

#B{
padding: 20%;}

Like that example.

Can you make a child div larger than parent without position , How do I reduce the size of a container in CSS? There are times where I set the padding of a DIV to be 1em on all sides, then I nest a second DIV inside the first and set it's width to 100%. In Firefox, the width of this nested div appears as the width of the parent, minus padding. In internet explorer, the div ignores the padding of the parent. Is this considered a bug in IE?

#B {
    width: 100vw;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
}

The idea here is to push the container to the exact middle of the browser window with left: 50%;, then pull it back to the left edge with a negative margin margin-left: -50vw;.

CSS Layout - width and max-width, How do you make a full width page in HTML? Margin on child element moves parent element. I have a div (parent) that contains another div (child). Parent is the first element in body with no particular CSS style. The end result is that top of my child is still aligned with parent. Instead of child being shifted for 10px downwards, my parent moves 10px down.

Full screen width div area, Just use top:0; and left: 0; and you can also eliminate padding: 0 . Don't use top: 0; for other div except top, use left: 0; for other div for eliminate the left space. 2. Child div positioned top right of parent and parent bottom left. Let’s add another child box in this example. We’ll call these elements grandparent (large box), parent and child (small box). As the parent is positioned relative to the grandparent with bottom:0px; then it is given a position:absolute.

Full Width Containers in Limited Width Parents, But margin is calculated based on the parent element, so to pull it to the left 20% of the browser window, you'd need 1/3 of the width of the  I have a parent Div and an Empty Child Div within it. So the Height of the parent Div is ‘0’. Can i in some way use a css selector to select the parent Div. I need to clear out certain css properties like padding, margin on the parent Div if it’s height is ‘0’. I can’t use Javascript or Jquery for some reason. Is this possible.

The "Inside" Problem, Centered, max-width/padding containers inside full-width color bands. The parent element is naturally as wide as it's own parent, and let's #If you can definitely hide the overflow-x on the parent, then extreme negative-margin and Normally, I achieve this with a <section> element that has a child  CSS Padding. The CSS padding properties are used to generate space around an element's content, inside of any defined borders. With CSS, you have full control over the padding. There are properties for setting the padding for each side of an element (top, right, bottom, and left).

Comments
  • Please update your question with a minimal reproducible example
  • Plaes add also your HTML markup
  • actually the div#A is in the div#wrapper and div#A's width is 76% with 2% padding.
  • @Mehdi, please have a look at the second working snippet
  • i am glad it helped you, please upvote and accept the answer