1

I'm trying to add a margin-top to a child div in a parent div, but when I add the margin, the parent container moves, leaving a white space between the header and the parent div on the page. Any idea how to fix this issue?

#container .con {
  width: 20%;
  height: auto;
  margin-top: 15px;
}
<div id="container">
  <div class="con">
    <p>Daily Tasks.</p>
    <p>Organized</p>
    <p>Free. Easy To Use. Reliable</p>
  </div>
  <button type="download">Download</button>
  <img src="../Images/interface.PNG">
</div>
Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57

2 Answers2

0

Theres no need to define your height in this case.

Also make sure you are using a css reset.

this is the one i use.

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

img{
    display: block;
}
Mr Kushy
  • 43
  • 7
-2

hello you must add display: flex on parent element


after you can add margin top on child element you can see code below for parent element

display:flex;
tskhvedadze
  • 49
  • 1
  • 3