繁体   English   中英

DIV神秘地向下移动

[英]DIV mysteriously moving down

我正在设计标题,而我的文本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 ,这会带来不必要的机会。 如何强制将此容器置于其父容器的顶部?

更改此:

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

对此:

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

    position: absolute;
    top: 0;
}

JSFiddle演示

如果您想实现像用户所说的那样,则可以尝试通过添加

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

嘿,您正在尝试实现这一目标吗?

演示小提琴

 /*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> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM