HTML文本图像

时间:2016-10-06 12:39:56

标签: html css

我试图将4个标题放在图像上,但是使用代码我会给出一些奇怪的事情:左边的2个标题会被抛出div。

图片参考:

正如您所看到的那样,div有一个红色边框,但由于某种原因,文本会跳出来。

代码:



error like videokit.so load fail:/data/user/0/packagename/lib/libvideokit.so.

@font-face {
    font-family: Head;
    src: url('HeadFont.ttf');
}
@font-face {
    font-family: SpecifyLight;
    src: url('SpecifyLight.ttf');
}
@font-face {
    font-family: SpecifyMedium;
    src: url('SpecifyMedium.ttf');
}

@font-face {
    font-family: Android;
    src: url('Android.ttf');
}

BODY {
    background-image: url("bg.jpg");
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: center;
    width: 75%;
    margin:auto;
}

/*Navigatie bar styling*/
ul {
    list-style-type: none;
    margin: auto;
    margin-top: 0;
    padding: 0;
    overflow: hidden;
    background-color: black;
}

.ulMain {
    background-image: url("menu.png");
    background-position: center;
    background-position: top;
    background-size: 100% auto;
    border-radius: 0px 0px 20px 20px;
}

li {
    float: left;
    border-right: 1px solid #bbb;
}

    li a {
        display: block;
        color: white;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
    }

        li a:hover:not(.active) {
            color: #B8371A;
            background-color: white;
        }

    li:last-child {
        border-right: none;
    }

.active {
    background-color: darkred;
}

h1 {
    width: 100%;
    font-family: Head;
    font-size: 80px;
    margin-top: 0;
    text-align: center;
    color: black;
    padding: 0;
}

h2 {
    width:100%;
    font-family: Head;
    font-size: 50px;
    text-align: center;
    padding: 0;
}

h3 {
    width:100%;
    font-family: Head;
    font-size: 30px;
    text-align: left;
    padding: 0;
}

h4 {
    width:100%;
    font-family: Head;
    font-size: 40px;
    margin: 10px;
    text-align: left;
    color: red;
}

h5 {
    width:100%;
    font-family: Head;
    font-size: 40px;
    text-align: right;
    color: red;
}

header {
    width: 100%;
    margin: auto;
    height: auto;

}

.menu {
    width: 100%;
    margin: auto;
    height: auto;
}

footer {
    width: 100%;
    margin: auto;
    height: 200px;
    background-color: #B8371A;
    border-radius: 0px 0px 20px 20px;
}

.content {
    font-family:SpecifyLight;
    font-size: 20px;
    width: 100%;
    margin: auto;
}

.bioFoto {
    float: right;
    width: 20%;
    height: auto;
    margin-right: 100px;
    border: solid;
    border-color: black;
    border-radius: 20px;
}

.website {
    width: 100%;
    margin:auto;
    background-color: lightgray;
}

.headerFoto {
    display:block;
    width: 100%;
    margin: auto;
    height: auto;
}

.mainFoto {
    width: 100%;
    margin: auto;
    height: auto;
}

.homePage {
    width:inherit;
    margin:auto;
    border:solid;
    border-color:red;
}




3 个答案:

答案 0 :(得分:1)

简短回答

position: relative设为homePage

简短回答

来自MDN

  

绝对定位的元素相对于最近定位的祖先(非静态)定位。如果定位的祖先不存在,则使用初始容器。

在您的情况下,由于所有元素都是position: static(这是默认行为),这意味着您的4个绝对元素相对于<html>标记(例如您的初始容器)。
在其父级上设置position: relative(或任何不是static的值)会通过设置相对于它的任何top|right|bottom|left来修复其定位。

答案 1 :(得分:0)

@font-face {
    font-family: Head;
    src: url('HeadFont.ttf');
}
@font-face {
    font-family: SpecifyLight;
    src: url('SpecifyLight.ttf');
}
@font-face {
    font-family: SpecifyMedium;
    src: url('SpecifyMedium.ttf');
}

@font-face {
    font-family: Android;
    src: url('Android.ttf');
}

BODY {
    background-image: url("bg.jpg");
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: center;
    width: 75%;
    margin:auto;
}

/*Navigatie bar styling*/
ul {
    list-style-type: none;
    margin: auto;
    margin-top: 0;
    padding: 0;
    overflow: hidden;
    background-color: black;
}

.ulMain {
    background-image: url("menu.png");
    background-position: center;
    background-position: top;
    background-size: 100% auto;
    border-radius: 0px 0px 20px 20px;
}

li {
    float: left;
    border-right: 1px solid #bbb;
}

    li a {
        display: block;
        color: white;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
    }

        li a:hover:not(.active) {
            color: #B8371A;
            background-color: white;
        }

    li:last-child {
        border-right: none;
    }

.active {
    background-color: darkred;
}

h1 {
    width: 100%;
    font-family: Head;
    font-size: 80px;
    margin-top: 0;
    text-align: center;
    color: black;
    padding: 0;
}

h2 {
    width:100%;
    font-family: Head;
    font-size: 50px;
    text-align: center;
    padding: 0;
}

h3 {
    width:100%;
    font-family: Head;
    font-size: 30px;
    text-align: left;
    padding: 0;
}

h4 {
    width:100%;
    font-family: Head;
    font-size: 40px;
    margin: 10px;
    text-align: left;
    color: red;
}

h5 {
    width:100%;
    font-family: Head;
    font-size: 40px;
    text-align: right;
    color: red;
}

header {
    width: 100%;
    margin: auto;
    height: auto;

}

.menu {
    width: 100%;
    margin: auto;
    height: auto;
}

footer {
    width: 100%;
    margin: auto;
    height: 200px;
    background-color: #B8371A;
    border-radius: 0px 0px 20px 20px;
}

.content {
    font-family:SpecifyLight;
    font-size: 20px;
    width: 100%;
    margin: auto;
}

.bioFoto {
    float: right;
    width: 20%;
    height: auto;
    margin-right: 100px;
    border: solid;
    border-color: black;
    border-radius: 20px;
}

.website {
    width: 100%;
    margin:auto;
    background-color: lightgray;
}

.headerFoto {
    display:block;
    width: 100%;
    margin: auto;
    height: auto;
}

.mainFoto {
    width: 100%;
    margin: auto;
    height: auto;
}

.homePage {
  position:relative;
    width:inherit;
    margin:auto;
    border:solid;
    border-color:red;
}
<!DOCTYPE html>

<html>
<head>
    <title>Atlas</title>
    <link rel="stylesheet" type="text/css" href="siteStyle.css">
    <link rel="shortcut icon" type="image/png" href="Logo.png" />
</head>
<body>
    <div class="website" style="background-color:black">
        <div class="menu">
            <ul>
                <li class="active"><a href="index.html">Home</a></li>
                <li><a href="bio.html">Biografie</a></li>
                <li><a href="projecten.html">Projecten</a></li>
                <li><a href="galerij.html">Galerij</a></li>
                <li><a href="contact.html">Contact</a></li>
            </ul>
        </div>
        <h2 style="color:white">Klik op de opties hier beneden</h2>
            <div class="homePage">
                <img src="grootLogo.png" class="mainFoto">
                <h4 style="position: absolute; top:50%;">Biografie</h4>
                <h5 style="position: absolute; top:50%;">Projecten</h5>
                <h4 style="position: absolute; top:75%;">Galerij</h4>
                <h5 style="position: absolute; top:75%;">Contact</h5>
                <br />
            </div>
    </div>
    <footer></footer>
</body>
</html>

答案 2 :(得分:0)

&#13;
&#13;
@font-face {
    font-family: Head;
    src: url('HeadFont.ttf');
}
@font-face {
    font-family: SpecifyLight;
    src: url('SpecifyLight.ttf');
}
@font-face {
    font-family: SpecifyMedium;
    src: url('SpecifyMedium.ttf');
}

@font-face {
    font-family: Android;
    src: url('Android.ttf');
}

BODY {
    background-image: url("bg.jpg");
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: center;
    width: 75%;
    margin:auto;
}

/*Navigatie bar styling*/
ul {
    list-style-type: none;
    margin: auto;
    margin-top: 0;
    padding: 0;
    overflow: hidden;
    background-color: black;
}

.ulMain {
    background-image: url("menu.png");
    background-position: center;
    background-position: top;
    background-size: 100% auto;
    border-radius: 0px 0px 20px 20px;
}

li {
    float: left;
    border-right: 1px solid #bbb;
}

    li a {
        display: block;
        color: white;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
    }

        li a:hover:not(.active) {
            color: #B8371A;
            background-color: white;
        }

    li:last-child {
        border-right: none;
    }

.active {
    background-color: darkred;
}

h1 {
    width: 100%;
    font-family: Head;
    font-size: 80px;
    margin-top: 0;
    text-align: center;
    color: black;
    padding: 0;
}

h2 {
    width:100%;
    font-family: Head;
    font-size: 50px;
    text-align: center;
    padding: 0;
}

h3 {
    width:100%;
    font-family: Head;
    font-size: 30px;
    text-align: left;
    padding: 0;
}

h4 {
    width:100%;
    font-family: Head;
    font-size: 40px;
	margin: 10px;
    text-align: left;
    color: red;
}

h5 {
    width:100%;
    font-family: Head;
    font-size: 40px;
    text-align: center; 
	
    color: red;
}

header {
    width: 100%;
    margin: auto;
    height: auto;

}

.menu {
    width: 100%;
    margin: auto;
    height: auto;
}

footer {
    width: 100%;
    margin: auto;
    height: 200px;
    background-color: #B8371A;
    border-radius: 0px 0px 20px 20px;
}

.content {
    font-family:SpecifyLight;
    font-size: 20px;
    width: 100%;
    margin: auto;
}

.bioFoto {
    float: right;
    width: 20%;
    height: auto;
    margin-right: 100px;
    border: solid;
    border-color: black;
    border-radius: 20px;
}

.website {
    width: 100%;
    margin:auto;
    background-color: lightgray;
}

.headerFoto {
    display:block;
    width: 100%;
    margin: auto;
    height: auto;
}

.mainFoto {
    width: 100%;
    margin: auto;
    height: auto;
}

.homePage {
    width:inherit;
    margin:auto;
    border:solid;
    border-color:red;
}
&#13;
<body>
    <div class="website" style="background-color:black">
        <div class="menu">
            <ul>
                <li class="active"><a href="index.html">Home</a></li>
                <li><a href="bio.html">Biografie</a></li>
                <li><a href="projecten.html">Projecten</a></li>
                <li><a href="galerij.html">Galerij</a></li>
                <li><a href="contact.html">Contact</a></li>
            </ul>
        </div>
        <h2 style="color:white">Klik op de opties hier beneden</h2>
            <div class="homePage">
                <img src="grootLogo.png" class="mainFoto">
                <h4 style="position: absolute; top:33%;">Biografie</h4>
                <h5 style="position: absolute; top:24%;">Projecten</h5>
                <h4 style="position: absolute; top:55%;">Galerij</h4>
                <h5 style="position: absolute; top:46%;">Contact</h5>
                <br />
            </div>
    </div>
    <footer></footer>
</body>
&#13;
&#13;
&#13;