0

I have a little problem with margin top for children element.

CSS:

body {
    height: 960px;
}
.breadcrumbs {
    position: relative;
    background-color: #eee;
    height: 10%;
}
.name {
    color: #000;
    margin-top: 50px;
}

http://jsfiddle.net/GRQNh/

Why it doesn't work? Class .name sticky on top.

Thanks in advance.

owl
  • 4,201
  • 3
  • 22
  • 28

4 Answers4

8

In your example you are using <span> and <span> is not block element, so you need either display: block or display: inline-block on it for margin to work.

If you add display: block to <span> then you can use <div> instead because the effect is the same.

dkasipovic
  • 5,930
  • 1
  • 19
  • 25
  • 1
    **for margin to work** -> in fact not all the margins, just **margin-top** and **margin-bottom**, `margin-left` and `margin-right` still work. – King King Apr 08 '14 at 12:20
  • Yeah, but in my answer **margin** refers to his problematic margin which in this case is margin-top. – dkasipovic Apr 08 '14 at 12:23
  • @D. Kasipovic, http://jsfiddle.net/GRQNh/11/. Or I need to specify position: absolute? – owl Apr 08 '14 at 12:26
  • @owl it has a margin top now, doesn't it? – dkasipovic Apr 08 '14 at 12:27
  • @D. Kasipovic, I need to move the text relative to the class .breadcrumbs. – owl Apr 08 '14 at 12:28
  • Your question was for margin-top not working. We got that sorted out. If you need more help, regarding different topic, you should open new question. That said, text **IS** relative to .breadcrumbs. If you add `top: 100px` to `.breadcrumbs` you will see that margin top starts at 100px and your text starts at 150px (100px top offset of breadcrumbs + 50px of top margin). – dkasipovic Apr 08 '14 at 12:31
  • @D. Kasipovic, I'm sorry for my bad English. I need it: http://i.imgur.com/A8t3sYr.png – owl Apr 08 '14 at 12:36
  • I really do not understand you. You want margin or you do not want it? On the other hand, this is not chat room, if you need help with some other issue, please open new question and ask it along with good explanation of what you need. – dkasipovic Apr 08 '14 at 12:38
  • @D. Kasipovic, sorry, it's new question: http://stackoverflow.com/questions/22937483/top-margin-of-an-element-css – owl Apr 08 '14 at 12:46
2

Demo update CSS as

.name {
    color: #000000;
    display: inline-block;
    margin-top: 50px;
}
Pravin W
  • 2,451
  • 1
  • 20
  • 26
1

This is how it works:

.name{
display:block;
padding-top: 50px;
color: #000;
}
gco
  • 1,670
  • 7
  • 24
  • 46
1

Try to add in class .name attribute display:inline-block; that should help

Gntvls
  • 230
  • 4
  • 16