Padding Left weird behavior on vertical position











up vote
2
down vote

favorite












I'm having a hard time figuring it out a weird behavior. So, I have this div with a couple paragraphs, and when I set the padding left within the div so I have all paragraphs left aligned, instead of just the paragraphs being left-aligned, they also get pushed up to the top as if I'm positioning them vertically up as well. I tried testing to see what's going on, it seems like the more padding left I apply to the parent div, the more the paragraphs within the div get pushed up to the top. I tried looking at W3C standards about padding-left to see if there is any relationship with margin top and/or bottom or if it affects the top and bottom position of elements, and I found nothing about. Also, tried see if there is anything here on stackoverflow that can help me figure out what's going on and couldn't find it either.



I'm sure I can fix the problem by applying more margin top to the paragraphs within the div to get the paragraphs where I want, but that's not the solution I'm looking for. I want to know why does applying padding-left to the parent div, not just pushes it's paragraph children to the right, but also position them up to the top the more padding-left I apply to the div?
Has anybody even come across something like that?



UPDATE: Here is the code for better explanation of the problem:



Html:



<div id="home-page">
<div id="intro-page" class="animated FadeInLeft">
<canvas class="animated fadeInUp" id="canvas"></canvas>

<p class="animated fadeInUp" id="p1">Lorem ipsum dolor sit amet, <br> consectetuer adipiscing elit!</p>
<p class="animated fadeInUp" id="quote">“consectetuer adipiscing elit, <br>no, and WOW! consectetuer adipiscing elit.” <br> consectetuer adipiscing elit</p>
<hr class="animated fadeInUpBig">
</div>
</div>


Css: The div in question in "intro-page". There is the comment in its css padding-left rule. Change it to see what I mean



* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
}



body {
background-color: #000;
}

#home-page {
height: 100vh;
width: 100%;

}

#intro-page {
width: calc(100% - 120px);
height: 100vh;
background: url(images/light-bulb.jpeg);
background-size: cover;
display: inline-block;
vertical-align: top;
overflow-y: hidden;
padding-left: 5%; /* Change this padding to 50% and see what I
mean*/
}

#intro-page:before {
content: "Hello!";
color: #ffffff;
position: absolute;
left: 6%;
top: 20%;
font-size: 700%;
animation: upAndDown 6s linear infinite;
font-family: 'PT Serif', serif;
}

@keyframes upAndDown {
0% {
transform: translateY(-20%);
}

50% {
transform: translateY(0%);
}


100% {
transform: translateY(-20%);
}
}

#intro-page p {
color: #bababa;
font-family: 'Roboto Condensed', sans-serif;
}

#intro-page #p1 {
font-size: 240%;
margin-top: 26%;
line-height: 50px;
}

#intro-page #quote {
margin-top: 5%;
font-size: 110%;
font-weight: 300;
letter-spacing: 1px;
}

#intro-page hr {
width: 32%;
margin-top: 2%;
}









share|improve this question




















  • 2




    How about you post a demonstration of the problem here, so we can reproduce it, and then give you an answer that would fit your current question? As far as your question goes, I don't see any correlation between padding-left and unexplained top alignment of it's children, so a Minimal, Complete, and Verifiable example would be a lifesavior
    – Icepickle
    Nov 11 at 0:37












  • Just updated it with the code
    – einacio
    Nov 11 at 0:57















up vote
2
down vote

favorite












I'm having a hard time figuring it out a weird behavior. So, I have this div with a couple paragraphs, and when I set the padding left within the div so I have all paragraphs left aligned, instead of just the paragraphs being left-aligned, they also get pushed up to the top as if I'm positioning them vertically up as well. I tried testing to see what's going on, it seems like the more padding left I apply to the parent div, the more the paragraphs within the div get pushed up to the top. I tried looking at W3C standards about padding-left to see if there is any relationship with margin top and/or bottom or if it affects the top and bottom position of elements, and I found nothing about. Also, tried see if there is anything here on stackoverflow that can help me figure out what's going on and couldn't find it either.



I'm sure I can fix the problem by applying more margin top to the paragraphs within the div to get the paragraphs where I want, but that's not the solution I'm looking for. I want to know why does applying padding-left to the parent div, not just pushes it's paragraph children to the right, but also position them up to the top the more padding-left I apply to the div?
Has anybody even come across something like that?



UPDATE: Here is the code for better explanation of the problem:



Html:



<div id="home-page">
<div id="intro-page" class="animated FadeInLeft">
<canvas class="animated fadeInUp" id="canvas"></canvas>

<p class="animated fadeInUp" id="p1">Lorem ipsum dolor sit amet, <br> consectetuer adipiscing elit!</p>
<p class="animated fadeInUp" id="quote">“consectetuer adipiscing elit, <br>no, and WOW! consectetuer adipiscing elit.” <br> consectetuer adipiscing elit</p>
<hr class="animated fadeInUpBig">
</div>
</div>


Css: The div in question in "intro-page". There is the comment in its css padding-left rule. Change it to see what I mean



* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
}



body {
background-color: #000;
}

#home-page {
height: 100vh;
width: 100%;

}

#intro-page {
width: calc(100% - 120px);
height: 100vh;
background: url(images/light-bulb.jpeg);
background-size: cover;
display: inline-block;
vertical-align: top;
overflow-y: hidden;
padding-left: 5%; /* Change this padding to 50% and see what I
mean*/
}

#intro-page:before {
content: "Hello!";
color: #ffffff;
position: absolute;
left: 6%;
top: 20%;
font-size: 700%;
animation: upAndDown 6s linear infinite;
font-family: 'PT Serif', serif;
}

@keyframes upAndDown {
0% {
transform: translateY(-20%);
}

50% {
transform: translateY(0%);
}


100% {
transform: translateY(-20%);
}
}

#intro-page p {
color: #bababa;
font-family: 'Roboto Condensed', sans-serif;
}

#intro-page #p1 {
font-size: 240%;
margin-top: 26%;
line-height: 50px;
}

#intro-page #quote {
margin-top: 5%;
font-size: 110%;
font-weight: 300;
letter-spacing: 1px;
}

#intro-page hr {
width: 32%;
margin-top: 2%;
}









share|improve this question




















  • 2




    How about you post a demonstration of the problem here, so we can reproduce it, and then give you an answer that would fit your current question? As far as your question goes, I don't see any correlation between padding-left and unexplained top alignment of it's children, so a Minimal, Complete, and Verifiable example would be a lifesavior
    – Icepickle
    Nov 11 at 0:37












  • Just updated it with the code
    – einacio
    Nov 11 at 0:57













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm having a hard time figuring it out a weird behavior. So, I have this div with a couple paragraphs, and when I set the padding left within the div so I have all paragraphs left aligned, instead of just the paragraphs being left-aligned, they also get pushed up to the top as if I'm positioning them vertically up as well. I tried testing to see what's going on, it seems like the more padding left I apply to the parent div, the more the paragraphs within the div get pushed up to the top. I tried looking at W3C standards about padding-left to see if there is any relationship with margin top and/or bottom or if it affects the top and bottom position of elements, and I found nothing about. Also, tried see if there is anything here on stackoverflow that can help me figure out what's going on and couldn't find it either.



I'm sure I can fix the problem by applying more margin top to the paragraphs within the div to get the paragraphs where I want, but that's not the solution I'm looking for. I want to know why does applying padding-left to the parent div, not just pushes it's paragraph children to the right, but also position them up to the top the more padding-left I apply to the div?
Has anybody even come across something like that?



UPDATE: Here is the code for better explanation of the problem:



Html:



<div id="home-page">
<div id="intro-page" class="animated FadeInLeft">
<canvas class="animated fadeInUp" id="canvas"></canvas>

<p class="animated fadeInUp" id="p1">Lorem ipsum dolor sit amet, <br> consectetuer adipiscing elit!</p>
<p class="animated fadeInUp" id="quote">“consectetuer adipiscing elit, <br>no, and WOW! consectetuer adipiscing elit.” <br> consectetuer adipiscing elit</p>
<hr class="animated fadeInUpBig">
</div>
</div>


Css: The div in question in "intro-page". There is the comment in its css padding-left rule. Change it to see what I mean



* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
}



body {
background-color: #000;
}

#home-page {
height: 100vh;
width: 100%;

}

#intro-page {
width: calc(100% - 120px);
height: 100vh;
background: url(images/light-bulb.jpeg);
background-size: cover;
display: inline-block;
vertical-align: top;
overflow-y: hidden;
padding-left: 5%; /* Change this padding to 50% and see what I
mean*/
}

#intro-page:before {
content: "Hello!";
color: #ffffff;
position: absolute;
left: 6%;
top: 20%;
font-size: 700%;
animation: upAndDown 6s linear infinite;
font-family: 'PT Serif', serif;
}

@keyframes upAndDown {
0% {
transform: translateY(-20%);
}

50% {
transform: translateY(0%);
}


100% {
transform: translateY(-20%);
}
}

#intro-page p {
color: #bababa;
font-family: 'Roboto Condensed', sans-serif;
}

#intro-page #p1 {
font-size: 240%;
margin-top: 26%;
line-height: 50px;
}

#intro-page #quote {
margin-top: 5%;
font-size: 110%;
font-weight: 300;
letter-spacing: 1px;
}

#intro-page hr {
width: 32%;
margin-top: 2%;
}









share|improve this question















I'm having a hard time figuring it out a weird behavior. So, I have this div with a couple paragraphs, and when I set the padding left within the div so I have all paragraphs left aligned, instead of just the paragraphs being left-aligned, they also get pushed up to the top as if I'm positioning them vertically up as well. I tried testing to see what's going on, it seems like the more padding left I apply to the parent div, the more the paragraphs within the div get pushed up to the top. I tried looking at W3C standards about padding-left to see if there is any relationship with margin top and/or bottom or if it affects the top and bottom position of elements, and I found nothing about. Also, tried see if there is anything here on stackoverflow that can help me figure out what's going on and couldn't find it either.



I'm sure I can fix the problem by applying more margin top to the paragraphs within the div to get the paragraphs where I want, but that's not the solution I'm looking for. I want to know why does applying padding-left to the parent div, not just pushes it's paragraph children to the right, but also position them up to the top the more padding-left I apply to the div?
Has anybody even come across something like that?



UPDATE: Here is the code for better explanation of the problem:



Html:



<div id="home-page">
<div id="intro-page" class="animated FadeInLeft">
<canvas class="animated fadeInUp" id="canvas"></canvas>

<p class="animated fadeInUp" id="p1">Lorem ipsum dolor sit amet, <br> consectetuer adipiscing elit!</p>
<p class="animated fadeInUp" id="quote">“consectetuer adipiscing elit, <br>no, and WOW! consectetuer adipiscing elit.” <br> consectetuer adipiscing elit</p>
<hr class="animated fadeInUpBig">
</div>
</div>


Css: The div in question in "intro-page". There is the comment in its css padding-left rule. Change it to see what I mean



* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
}



body {
background-color: #000;
}

#home-page {
height: 100vh;
width: 100%;

}

#intro-page {
width: calc(100% - 120px);
height: 100vh;
background: url(images/light-bulb.jpeg);
background-size: cover;
display: inline-block;
vertical-align: top;
overflow-y: hidden;
padding-left: 5%; /* Change this padding to 50% and see what I
mean*/
}

#intro-page:before {
content: "Hello!";
color: #ffffff;
position: absolute;
left: 6%;
top: 20%;
font-size: 700%;
animation: upAndDown 6s linear infinite;
font-family: 'PT Serif', serif;
}

@keyframes upAndDown {
0% {
transform: translateY(-20%);
}

50% {
transform: translateY(0%);
}


100% {
transform: translateY(-20%);
}
}

#intro-page p {
color: #bababa;
font-family: 'Roboto Condensed', sans-serif;
}

#intro-page #p1 {
font-size: 240%;
margin-top: 26%;
line-height: 50px;
}

#intro-page #quote {
margin-top: 5%;
font-size: 110%;
font-weight: 300;
letter-spacing: 1px;
}

#intro-page hr {
width: 32%;
margin-top: 2%;
}






javascript html5 css3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 1:02

























asked Nov 11 at 0:31









einacio

427




427








  • 2




    How about you post a demonstration of the problem here, so we can reproduce it, and then give you an answer that would fit your current question? As far as your question goes, I don't see any correlation between padding-left and unexplained top alignment of it's children, so a Minimal, Complete, and Verifiable example would be a lifesavior
    – Icepickle
    Nov 11 at 0:37












  • Just updated it with the code
    – einacio
    Nov 11 at 0:57














  • 2




    How about you post a demonstration of the problem here, so we can reproduce it, and then give you an answer that would fit your current question? As far as your question goes, I don't see any correlation between padding-left and unexplained top alignment of it's children, so a Minimal, Complete, and Verifiable example would be a lifesavior
    – Icepickle
    Nov 11 at 0:37












  • Just updated it with the code
    – einacio
    Nov 11 at 0:57








2




2




How about you post a demonstration of the problem here, so we can reproduce it, and then give you an answer that would fit your current question? As far as your question goes, I don't see any correlation between padding-left and unexplained top alignment of it's children, so a Minimal, Complete, and Verifiable example would be a lifesavior
– Icepickle
Nov 11 at 0:37






How about you post a demonstration of the problem here, so we can reproduce it, and then give you an answer that would fit your current question? As far as your question goes, I don't see any correlation between padding-left and unexplained top alignment of it's children, so a Minimal, Complete, and Verifiable example would be a lifesavior
– Icepickle
Nov 11 at 0:37














Just updated it with the code
– einacio
Nov 11 at 0:57




Just updated it with the code
– einacio
Nov 11 at 0:57












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










From W3C Spec about margin properties:




The percentage is calculated with respect to the width of the
generated box's containing block. Note that this is true for
'margin-top' and 'margin-bottom' as well. If the containing block's
width depends on this element, then the resulting layout is undefined
in CSS 2.1.




This part of your css is implied :



#intro-page #p1 {
font-size: 240%;
margin-top: 26%;
line-height: 50px;
}


When augmenting the padding of #intro-page, you are reducing the width of the paragraph, therefore reducing the top margin.






share|improve this answer





















  • Thanks, your answer makes sense. I did read about how the percentage padding/margin is calculated. I just didn't think enough to realize that the more padding I apply to the div, the smaller the paragraph's width gets. Well done explanation.
    – einacio
    Nov 11 at 1:12











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244769%2fpadding-left-weird-behavior-on-vertical-position%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










From W3C Spec about margin properties:




The percentage is calculated with respect to the width of the
generated box's containing block. Note that this is true for
'margin-top' and 'margin-bottom' as well. If the containing block's
width depends on this element, then the resulting layout is undefined
in CSS 2.1.




This part of your css is implied :



#intro-page #p1 {
font-size: 240%;
margin-top: 26%;
line-height: 50px;
}


When augmenting the padding of #intro-page, you are reducing the width of the paragraph, therefore reducing the top margin.






share|improve this answer





















  • Thanks, your answer makes sense. I did read about how the percentage padding/margin is calculated. I just didn't think enough to realize that the more padding I apply to the div, the smaller the paragraph's width gets. Well done explanation.
    – einacio
    Nov 11 at 1:12















up vote
2
down vote



accepted










From W3C Spec about margin properties:




The percentage is calculated with respect to the width of the
generated box's containing block. Note that this is true for
'margin-top' and 'margin-bottom' as well. If the containing block's
width depends on this element, then the resulting layout is undefined
in CSS 2.1.




This part of your css is implied :



#intro-page #p1 {
font-size: 240%;
margin-top: 26%;
line-height: 50px;
}


When augmenting the padding of #intro-page, you are reducing the width of the paragraph, therefore reducing the top margin.






share|improve this answer





















  • Thanks, your answer makes sense. I did read about how the percentage padding/margin is calculated. I just didn't think enough to realize that the more padding I apply to the div, the smaller the paragraph's width gets. Well done explanation.
    – einacio
    Nov 11 at 1:12













up vote
2
down vote



accepted







up vote
2
down vote



accepted






From W3C Spec about margin properties:




The percentage is calculated with respect to the width of the
generated box's containing block. Note that this is true for
'margin-top' and 'margin-bottom' as well. If the containing block's
width depends on this element, then the resulting layout is undefined
in CSS 2.1.




This part of your css is implied :



#intro-page #p1 {
font-size: 240%;
margin-top: 26%;
line-height: 50px;
}


When augmenting the padding of #intro-page, you are reducing the width of the paragraph, therefore reducing the top margin.






share|improve this answer












From W3C Spec about margin properties:




The percentage is calculated with respect to the width of the
generated box's containing block. Note that this is true for
'margin-top' and 'margin-bottom' as well. If the containing block's
width depends on this element, then the resulting layout is undefined
in CSS 2.1.




This part of your css is implied :



#intro-page #p1 {
font-size: 240%;
margin-top: 26%;
line-height: 50px;
}


When augmenting the padding of #intro-page, you are reducing the width of the paragraph, therefore reducing the top margin.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 1:05









AllirionX

1765




1765












  • Thanks, your answer makes sense. I did read about how the percentage padding/margin is calculated. I just didn't think enough to realize that the more padding I apply to the div, the smaller the paragraph's width gets. Well done explanation.
    – einacio
    Nov 11 at 1:12


















  • Thanks, your answer makes sense. I did read about how the percentage padding/margin is calculated. I just didn't think enough to realize that the more padding I apply to the div, the smaller the paragraph's width gets. Well done explanation.
    – einacio
    Nov 11 at 1:12
















Thanks, your answer makes sense. I did read about how the percentage padding/margin is calculated. I just didn't think enough to realize that the more padding I apply to the div, the smaller the paragraph's width gets. Well done explanation.
– einacio
Nov 11 at 1:12




Thanks, your answer makes sense. I did read about how the percentage padding/margin is calculated. I just didn't think enough to realize that the more padding I apply to the div, the smaller the paragraph's width gets. Well done explanation.
– einacio
Nov 11 at 1:12


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244769%2fpadding-left-weird-behavior-on-vertical-position%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python