2016-01-24 80 views
0

我对这个响应式网页设计感到沮丧。我正在尝试为我正在尝试构建的单页网站创建横幅(用于练习目的)。html和css中的标题横幅

而不是将图像作为标题的背景,我把它写在html标题标签内,使它看起来像一条横幅对我来说不难,但我想在图像上放一些文字并且它与hgroup的绝对定位完美地结合在一起。

header#main img{ 
 
    max-width: 100%; 
 
    max-height: auto; 
 
    opacity: 2; 
 
    margin: 0 auto; 
 
} 
 

 
header#main hgroup h1{ 
 
    position: absolute; 
 
    top: 50%; 
 
    left: 20%; 
 
    opacity: .5; 
 
    margin-top: 0; 
 
    color: #E7E7E7; 
 
    font-size: 3.5em; 
 
    font-family: 'Open Sans'; 
 
    font-weight: lighter; 
 
    max-width: 100%; 
 
    margin: auto; 
 
} 
 

 
header#main hgroup h2{ 
 
    font-family: 'Open Sans'; 
 
    opacity: .9; 
 
    font-style: italic; 
 
    color: #E7E7E7; 
 
    font-size: 1em; 
 
    font-family: 'Open Sans'; 
 
    font-weight: lighter; 
 
    text-align: justify; 
 
    position: absolute; 
 
    top: 60%; 
 
    left: 42%; 
 
    max-width: 100%; 
 
    margin: auto; 
 
}
<header id="main"> 
 
    <img src="imgs/mountain.jpg"/> 
 
    <hgroup> 
 
     <h1>Title</h1> 
 
     <h2> subtitle </h2> 
 
    </hgroup> 
 
</header>

当我尝试调整他们失踪的浏览器。 任何制作标题横幅的技巧?

+1

据我所知,'hgroup'标记已从W3C规范中删除,并且至少被MDN视为实验性的。 – Utkanos

回答

0

看看当你放置一个位置会发生什么:绝对的 元素在一个位置:相对一个。这应该给你你需要的东西。

您的位置目前相对于整个屏幕而不是外部横幅区域 - 这意味着当屏幕更改大小时,无论图像高度如何,整个屏幕都会跳转。

如果您制作横幅位置的外部元素:relative,那么它们将与该横幅区域的尺寸相关,而不是屏幕。

0

我认为这应该工作。 https://jsfiddle.net/1c8qy7bo/

HTML:

<header> 
    <div class="container"> 
    <img align="center" src="http://www.improntaunika.it/wp-content/uploads/2014/09/moutain.jpg"/> 
    <h1> AAAAAAAAA </h1> 
    <h2>BBBBBBBBBBBBB</h2> 
    </div> 
</header> 

CSS:如果你有一个问题

header{ 
    width:100%; 
    position: absolute; 
    background: #f5f5f5; 
    height: 14%; 
    background-position: 100%; 
    min-height: 80px; 
    min-width: 300px; 
} 

    img{ 
    width: 100px; 
    height: 100px; 
    position: absolute; 
    right: 50%; 
    margin-right: -50px; 
    } 

h1{ 
    position: absolute; 
    font-size: 10px; 
    right: 50%; 
    margin-right: -50px; 

} 
h2{ 
    position: absolute; 
    font-size: 10px; 
    right: 50%; 
    margin-right: -50px; 
    top:50%; 
} 

评论。 我希望这将是有用的。