DIV神秘地向下移动

时间:2015-08-17 10:09:45

标签: html css

我正在设计一个标题,我的文字div正在向下移动。

HTML:

<!doctype HTML>
<html lang = "en-AU">
    <head>
        <title>Simon Teacher Search</title>
        <meta charset = "UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <base href="../">
        <link rel="stylesheet" type="text/css" href="CSS/desktop.css">
    </head>
    <body>
        <div id = "body-container">
            <header id = "header">
                <div id = "header-content">
                    <div id = "logo-container">
                        <img src = "Images/SHCK Logo.png" alt = "SHC Logo">
                    </div>
                    <div id = "header-text-container">
                        <div id = "header-text-top-container">
                            <span id = "SACRED-HEART-COLLEGE">SACRED HEART COLLEGE</span>
                            <span id =""></span>
                        </div>
                        <div id = "header-text-bottom-container">
                            <span id = "Kyneton">Kyneton</span>
                        </div>

                    </div>
                </div>
            </header>
        </div>
    </body>
</html>

CSS:

    /*Code written by Oliver Murfett and Caelan Grgurovic 2015
Start Code*/

/*The following are classes that can be added to tags to give them certain features*/

.italics, i, em {
    font-style: italic;
}

.bold, b, strong {
    font-weight: bold;
}

.underline, u {
    text-decoration: underline;
}

.hidden {
    display: none;
}

/*Fonts*/
@font-face {
    font-family: "Open Sans-Regular";
    src: url(Fonts/OpenSans-Regular.ttf);
}

@font-face {
    font-family: "Trajan Pro Regular";
    src: url(Fonts\Trajan Pro Regular.ttf);
}
/*The following styles are to the maximize page space*/
html, body {
    width: 100%;
    margin: 0px;
    padding: 0px;
    background-color: white;
    top: 0px;
    height: 100%;
    min-height: 100%;
}

#body-container {
    width: 100%;
    margin: 0px;
    padding: 0px;
    top: 0px;
    height: 100%;
    min-height: 100%;
}

header {
    width: 100%;
    margin: 0px;
    padding: 0px;
    top: 0px;
    height: 100px;

}

/*The following styles are to style the header*/

#header-content {
    width: 100%;
    margin: 0px;
    padding: 10px;
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box;   
    box-sizing: border-box;    
    height: 100%;
    min-height: 100%;
}

#logo-container {
    height: 100%;
    min-height: 100%;
    display: inline-block;
    margin-right: 20px;
}

#logo-container img {
    height: 100%;
    min-height: 100%;
}

#header-text-container {
    height: 100%;
    min-height: 100%;
    top: 0;
    display: inline-block;
    margin-top: 0px;

}

#header-text-top-container {
    height: 50%;
    min-height: 50;
}

#header-text-bottom-container {
    height: 50%;
    min-height: 50;
}

#SACRED-HEART-COLLEGE {
    font-family: "Trajan Pro Regular";
    font-size: 34px;
    color: rgb(30,30,117);
}

此处的所有代码:http://jsfiddle.net/j5kcfwLa/

现在我的问题是:#header-text-container div正在向下移动而不是停留在顶部。我尝试了top: 0;,它什么也没做,position: absolute,这使得不必要的机会。如何将此容器强制到其父容器的顶部?

2 个答案:

答案 0 :(得分:1)

改变这个:

    <Style x:Key="ScrollBarPageButtonStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border BorderBrush="Transparent"></Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ScrollBarThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Margin" Value="1,0,1,0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border  CornerRadius="4" Width="10">
                        <Border.Background>
                            <RadialGradientBrush>
                                <GradientStop Color="#FF322E2E"/>
                                <GradientStop Color="#FF363232" Offset="0.385"/>
                                <GradientStop Color="#FF2B2626" Offset="1"/>
                            </RadialGradientBrush>
                        </Border.Background>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
        <Border CornerRadius="5" Width="14" >
            <Border.Background>
                <RadialGradientBrush>
                    <GradientStop Color="#FF645B5B" Offset="0.923"/>
                    <GradientStop Color="#FF685F5F" Offset="0"/>
                </RadialGradientBrush>
            </Border.Background>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Track Name="PART_Track" Grid.Row="1" 
               IsDirectionReversed="True" ViewportSize="28" >
                    <Track.DecreaseRepeatButton>
                        <RepeatButton Command="ScrollBar.PageUpCommand" Style="{StaticResource ScrollBarPageButtonStyle}">
                        </RepeatButton>
                    </Track.DecreaseRepeatButton>
                    <Track.Thumb>
                        <Thumb Style="{StaticResource ScrollBarThumbStyle}">
                        </Thumb>
                    </Track.Thumb>
                    <Track.IncreaseRepeatButton>
                        <RepeatButton Command="ScrollBar.PageDownCommand" Style="{StaticResource ScrollBarPageButtonStyle}">
                        </RepeatButton>
                    </Track.IncreaseRepeatButton>
                </Track>
            </Grid>
        </Border>
    </ControlTemplate>

    <Style TargetType="{x:Type ScrollBar}">
        <Setter Property="Template" Value="{StaticResource VerticalScrollBar}"/>
    </Style>

到此:

#SACRED-HEART-COLLEGE {
    font-family:"Trajan Pro Regular";
    font-size: 24px;
    color: rgb(30, 30, 117);
}

JSFiddle demo

答案 1 :(得分:0)

如果你想达到像用户所说的那么你可以尝试只添加

#SACRED-HEART-COLLEGE {
    font-family: "Trajan Pro Regular";
    font-size: 24px;
    color: rgb(30,30,117);
    line-height: 0;
    display: block;
}

嘿,你想要实现这个目标吗?

Demo Fiddle

/*Code written by Oliver Murfett and Caelan Grgurovic 2015
Start Code*/

/*The following are classes that can be added to tags to give them certain features*/

.italics, i, em {
	font-style: italic;
}

.bold, b, strong {
	font-weight: bold;
}

.underline, u {
	text-decoration: underline;
}

.hidden {
	display: none;
}

/*Fonts*/
@font-face {
    font-family: "Open Sans-Regular";
    src: url(Fonts/OpenSans-Regular.ttf);
}

@font-face {
    font-family: "Trajan Pro Regular";
    src: url(Fonts\Trajan Pro Regular.ttf);
}
/*The following styles are to the maximize page space*/
html, body {
	width: 100%;
	margin: 0px;
	padding: 0px;
	background-color: white;
	top: 0px;
	height: 100%;
	min-height: 100%;
}

#body-container {
	width: 100%;
	margin: 0px;
	padding: 0px;
	top: 0px;
	height: 100%;
	min-height: 100%;
}

header {
	width: 100%;
	margin: 0px;
	padding: 0px;
	top: 0px;
	height: 100px;
	
}

/*The following styles are to style the header*/

#header-content {
	width: 100%;
	margin: 0px;
	padding: 10px;
	-webkit-box-sizing: border-box; 
	-moz-box-sizing: border-box;   
	box-sizing: border-box;    
	height: 100%;
	min-height: 100%;
}

#logo-container {
	height: 100%;
	min-height: 100%;
	float:left;
	margin-right: 20px;
}

#logo-container img {
	height: 100%;
	min-height: 100%;
}

#header-text-container {
	height: 100%;
	min-height: 100%;
}

#header-text-top-container {
	height: 50%;
	min-height: 50;
}

#header-text-bottom-container {
	height: 50%;
	min-height: 50px;
}

#SACRED-HEART-COLLEGE {
	font-family: "Trajan Pro Regular";
	font-size: 24px;
	color: rgb(30,30,117);
}
	<body>
		<div id = "body-container">
			<header id = "header">
				<div id = "header-content">
					<div id = "logo-container">
						<img src = "Images/SHCK Logo.png" alt = "SHC Logo">
					</div>
					<div id = "header-text-container">
						<div id = "header-text-top-container">
							<span id = "SACRED-HEART-COLLEGE">SACRED HEART COLLEGE</span>
							<span id =""></span>
						</div>
						<div id = "header-text-bottom-container">
							<span id = "Kyneton">Kyneton</span>
						</div>
						
					</div>
				</div>
			</header>
		</div>
	</body>