0
我正在为网站创建横幅。我固执地试图用HTML5/CSS3来做,而不是制作图像。该横幅有一个不透明的背景图像,跨越页面包装的整个宽度(设置为80%的屏幕宽度)。除此之外,我有三个元素:一个徽标和两行文字。我已经把三个我想要的东西放在我想要的地方,让它们成为绝对的,并且使用顶部,左边等等。我还将这三个元素放在他们自己的div中。我想将它们置于背景图片上。我试着在两边设置自动边距(css3中的首选方式,但它不起作用)如何在div中集中元素组
实际上,如果能够不仅能将三个中心组(标识,第1行, 2号线),但要能够身边一起移动作为一个绝对的因素。这可能吗?
http://jsfiddle.net/abalter/965Mj/1/
* HTML *
<div id="wrapper">
<header>
<div id="background-image"></div>
<div id="header-group">
<img id="house-logo" src="http://arielbalter.com/cio/img/CheckItOutHouseNoBackground.png " />
<h1 id="line1">check it out!</h1>
<h1 id="line2">Home Inspection</h1>
</div>
</header>
</div>
* CSS *
#wrapper {
background-color: Wheat;
width: 1280px;
/* doing that because jsfiddle viewport is not the entire page width.*/
/* in real life, the wrapper extends below the banner -- that is where the main part of the website is */
}
header {
position: relative;
width: 100%;
height: 180px;
background-color: White;
}
header #background-image {
background-image: url("http://arielbalter.com/cio/img/3tab_slanted.jpg");
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 100%;
background-repeat: no-repeat;
background-size: 100% 100%;
opacity: 0.3;
}
#header-group {
margin: 0 auto 0 auto;
}
#house-logo {
position: absolute;
float: left;
height: 160px;
top:10px;
left: 10px;
}
#line1 {
display: block;
position: absolute;
left: 220px;
top: -15px;
padding: 0;
margin: 0;
font-family:"KGLoveSomebody", "Comic Sans MS", sans-serif;
font-size: 7em;
color: FireBrick;
}
#line2 {
display: block;
position: absolute;
left: 185px;
bottom: 1px;
margin: 0;
padding: 0;
font-family:"Trebuchet", sans-serif;
font-size: 4em;
}
我拿出了你不需要的所有职位。我用填充修复它和显示表我看不到你的代码的其余部分,所以我不知道这是否适合。 –
它确实有效,但不是我想要的。我真的想把这个团队作为一个单位集中在一起,并将标题组集中在一起。似乎应该是可能的。 – abalter
我让它成为另一种方式,也许这对你会更好。请注意,我不得不延长标题和背景图像的高度以适应背景中的line2,因为line2不会向上移动。这就是你要弄清楚,如果你不喜欢这个 –