使用HTML5 / CSS向Image添加文本

时间:2013-11-13 22:36:37

标签: css html5 banner

我试图为我正在创建的网站制作一个横幅,但是当我将它添加到我的网站时,结果却很糟糕。我想知道我是否可以使用HTML5和/或CSS为我的横幅添加文字。

HTML:

<!doctype html>
<html lang="en">

    <head>
        <meta charset="utf-8" />
        <title>Play - Learn - Grow</title>
        <link rel="stylesheet" href="main.css">
    </head>

    <body class="body">

        <span class="banner_h">
            <img src="Images\Top_Banner_4.png" alt="Banner" height="150" width ="1240"/>
        </span>

        <nav>
            <ul class="nav">
                <li><a href="index.html">Home</a></li>
                <li><a href="about.html">About Us</a></li>
                <li><a href="contact.html">Contact Us</a></li>
                <li><a href="membership.html">Become a Member</a></li>
                <li><a href="borrow.html">Borrow Toys</a></li>
                <li><a href="policies.html">Our Policies</a></li>
                <li><a href="sitemap.html">Site Map</a></li>
            </ul>
        </nav>

        <span class="banner_l">
            <img src="Images\Side_Banner.jpg" alt="Banner" />
        </span>

        <span class="banner_r">
            <img src="Images\Side_Banner.jpg" alt="Banner" />
        </span>

        <h2 class="headers">Welcome to the Home Page!</h2>

        <div class="container">

            Our aim is to provide the children of the community with an ever-changing variety of educational and fun toys to enhance
            their cognitive, social, emotional and physical development in the important first six years of their lives.

            <br><br><span class="Links">Be sure to check out our Wikispace site with more information <a href="http://mysocialmediatools-pn.wikispaces.com/">here</a>!</span>

        </div>

        <div id="content"></div>

        <div id="footer">
            Copyright &copy 2013
        </div>


      </body>

</html>

CSS:

/* Entire Document CSS */
html{
    height: 100%;
}
/* Header CSS */
.headers{
    color: #FFD89A;
    text-align: center;
    padding: 10px;
}
/* Body CSS */
.body{
    background-color: #61B329;
    height: 50%;
    color: #FFFFFF;
}
.container{
    margin: 0 auto 0 auto;
    width: 50em;
    text-align: center;
    padding-bottom: 500px;
    height: 50%;
}
/* Navigation CSS */
.nav {
    display: inline-block;
    background-color: #00B2EE;
    border: 1px solid #000000;
    border-width: 1px 0px;
    margin: 0;
    padding: 0;
    min-width: 1000px;
    width: 100%;
}
.nav li {
    list-style-type: none;
    width: 14.28%;
    float: left;
}
.nav a {
    display: inline-block;
    padding: 10px 0;
    width: 100%;
    text-align: center;
}
/* Banner / Picture CSS / Text in Images */
.banner_l{
    float: left;
}
.banner_r{
    float: right;
}
.banner_h{
    display: block;
    width: 100%;
}
.banner_h img{
    width: 100%;
}
/* Footer CSS */
#footer {
 clear: both;
 position: relative;
 z-index: 10;
 height: 3em;
 margin-top: -3em;
}
#content {
    padding-bottom: 3em;
}
/* Link CSS */
a:link{
    color: #FFFFFF;
    text-decoration: none;
}
a:visited{
    color: #FFFFFF;
    text-decoration: none;
}
a:hover{
    background-color: #028482;
    color: #FFFFFF;
    text-decoration: underline;
}
a:active{
    background-color: #FCDC3B;
    color: #AA00FF;
    text-decoration: overline;
}
.Links A:hover{
    color: #028482;
    background-color: transparent;
    text-decoration: underline overline;
}

我正试图将我的文字居中/居中在横幅上,用白色字体(字体可以变化)。我该怎么做才能实现这一目标?谢谢!

1 个答案:

答案 0 :(得分:0)

这取决于您要添加到横幅的文字类型。如果你想添加静态文本(例如,它永远不会或很少改变)并想要添加自定义字体,你应该在Photoshop中编辑图像。

另一方面,如果横幅中的内容会不断变化,那么我建议将图像添加为背景。你的横幅h类看起来像这样:

.banner_h{
    display: block;
    width: *actual pixel size of the banner*;
    height: *actual pixel size of the banner*;
    background: url('*location of file*') no-repeat;
}

如果你将宽度保留为百分比,那么div将不会有任何内部因此不会显示横幅,所以你需要弄清楚横幅的实际宽度和高度是多少把它放在这个CSS声明中,以便它显示横幅。

完成此操作后,从标记中删除图像并将其替换为您要添加的内容。