0

I have created header in the top of page as give below. But why it keeps space from top page border even though I have kept margin 0?

FIDDLE LINK

<body><div class="page-header header" style="color:fff; font-size: large; font-family: Arial;
">
            <h1 class="page-header-text">Review Networks</h1>
        </div>
user2129623
  • 2,167
  • 3
  • 35
  • 64

3 Answers3

2

Add the property margin-top: 0; to your .page-header-text selector.

See this JSFiddle for a working code snippet of the vertical centering you want.

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • I want it to align in center vertically not the horizontal. This does not help – user2129623 Apr 02 '14 at 18:20
  • @Programming_crazy I will edit my answer once more, then. It's already center-aligned vertically. – TylerH Apr 02 '14 at 18:21
  • @Programming_crazy I've added a JSFiddle which should give you the result you want. – TylerH Apr 02 '14 at 18:39
  • can you please tell me how can I increase header height? without using pixel? I did `height:10%;` but did not help – user2129623 Apr 02 '14 at 18:49
  • @Programming_crazy `height:10%;` will specify a total element height of 10% of the parent element. What you can do is change `padding-top: 5px;` to `padding-top: 1%;` to achieve roughly the same result. – TylerH Apr 02 '14 at 18:55
2

Add this to your CSS:

h1 {
    margin: 0 auto;
    padding-top: 0;
    text-align: center;
}

Browsers add their own default styling, which was causing the margin issue with the h1. Setting margin: 0 auto; overrides that default styling. Auto tells the browser to split the remaining space between the left and the right of the element, thus centering it.

Hiram Hibbard
  • 537
  • 2
  • 10
2

I usually do that like this;

my first answer was : fiddle - http://jsfiddle.net/TPQnx/2/

As you don't want position:absolute;

new fiddle: http://jsfiddle.net/TPQnx/3/

Changes I've made:

added this to header class:

text-align:center;

and added;

h1 {
margin: 0 auto;
padding-top: 0;
}

Hope this helps.

Ekin
  • 1,957
  • 2
  • 31
  • 45