CSS:添加位置固定使标题向右移动?

时间:2014-03-27 18:24:00

标签: css

http://codepen.io/anon/pen/potcD

在标题css中,为什么当我添加位置时:固定研讨会文本会一直向左移动?

2 个答案:

答案 0 :(得分:1)

当你给定位置固定时,标题取内容的宽度,所以指定宽度。

试试这种风格

header{
  position:fixed;
  margin:0;
  padding:0;
  width:100%;
  left:0;
  text-align:center;
}

答案 1 :(得分:0)

我不确定你要做什么。

我已经玩了一下......请查看我的CodePen fork你的作品。

HTML

<header><div class="logo">symposiums</div></header>
<div class="content">
  <p>
1.a convivial meeting, usually following a dinner, for drinking and intellectual conversation.<br>
2.( initial capital letter, italics ) a philosophical dialogue (4th century b.c.) by Plato, dealing with ideal love and the vision of absolute beauty.</p>
<p>i realize that i have to live, to experience life and to do new things everyday. That is the antidote for boredom, procrastination and sulking. Don't let things be a routine, or else time will just fly by. Twas a good night.</p><br>
<p>And we gotta be a superhero, a renaissance man, against this all. everyones need an outlet for expression,  a skill in the arts, music, dance, writing, etc.</p>
and i need to put my feet on the ground, remember i am not special, pay my dues, and still put my mind in the skies.
<br><br><br><br><p><center>The mind is it's own place, and in itself can make a heaven of hell or a hell of heaven. John Milton.</p>

<h2>I WONDER</h2></center>

  <p>I'm too emasculated for this shit
  <br>jobs, aren't they buying part of your life? and i want family and freedom<br>
  <font color="red"> but of course you won't feel anything, not accomplishment nor desire, if you don't put seriousness and passion into</font></p>

  <p>Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines.  Sail away from the safe harbor.  Catch the trade winds in your sails.  Explore.  Dream.  Discover.</p>

  <p>the thing is it doesn't matter how much you read. there is a certain extent, you have to do, to experience, and nothing can replace that. what do i do?</p>

</div>

CSS

header
    {
      margin: 0;
  position:fixed;
  width: 100%;
  top: 0;

    background: #BDBDBD;
    font-size: 250%; 
    line-height: 200%; 
    opacity: 0.5;
height: 72px;
    }

header .logo {
  width: 35%;
  left: 22%;
  margin: 0 auto;
  position: absolute;
    font-family: georgia;
    font-variant: small-caps;
}

header .logo:first-letter
    {
    text-transform: uppercase;
    color: red;
    font-family: times;
    }

body 

    {
    cursor: crosshair; 
    font-family: helvetica; 
    font-size: 90%; 
    opacity: .7;
    }


h2 

    {
    font-family: arial, helvetica; 
    font-weight: bold; 
    font-size: 550%; 
    text-shadow: 0 1px 1px grey;
    }



.content

    {
margin: 80px auto;
    text-align: left;
    width: 35%;
    border: 2px dotted grey;
    padding: 0 4% 15% 4%;
    }