如何使用CSS删除图像下方的额外空白区域

时间:2015-09-15 17:47:34

标签: html css

/* Typography */

.header {font-family: "futura-pt", Arial, Helvetica, sans-serif; font-weight: 700; font-size: 1.0em; margin: 0; padding: 0; text-transform: uppercase; letter-spacing: 0.1em;}
p {font-family: "futura-pt", Arial, Helvetica, sans-serif; font-weight: 400; font-size: 1.0em; margin: 0; padding: 0; text-transform: uppercase; letter-spacing: 0.1em;}
/* Sizes */

.large-5 {font-size: 5.0em;}
.large-4 {font-size: 4.0em;}
.large-3 {font-size: 3.0em;}
.large-25 {font-size: 2.5em;}
.large-2 {font-size: 1.5em;}
.large-15 {font-size: 1.3em;}

@media screen and (min-width: 768px) {
.large-5 {font-size: 5.0em;}
.large-4 {font-size: 4.0em;}
.large-3 {font-size: 3.0em;}
.large-25 {font-size: 2.5em;}
.large-2 {font-size: 2.0em;}
.large-15 {font-size: 1.5em;}
}

/* Colours */

.white {color: #fff;}
.black {color: #000;}

/* Spacing */

.padding-top {padding-top: 2em;}
.padding-top-double {padding-top: 2em;}
.padding-top-triple {padding-top: 1em;}
.padding-bottom {padding-bottom: 1em;}

/* Links */

a:link, a:visited, a:active {color: #fff; text-decoration: none;}
a:hover {color: #fff; text-decoration: underline;}

/* General */

body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    text-align: center;
    background: #fff;
}

*, *:before, *:after {
  -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
 }

/* Structure */

.container {
    background-image: url("img/hd-sunset-river-HD-1200x1920.jpg");
    background-size: cover;
    width: 100%;
    height: 100%;
    border: 5px solid #fff;

}


.content {
    width: 100%;
    max-width: 500px;
    position: relative;
    top: 50%;
    height: 1200px;
    -webkit-transform: translateY(-50%);
    -ms-transform: translateY(-50%);
    transform: translateY(-50%);
    margin: 0 auto;

}

.content img {
    max-width: 100%;

}

my-email::after {
content: attr(data-domain);
}

my-email::before {
content: attr(data-user) "\0040";
}

这是我的CSS代码。在尝试Stack Overflow上的人之前,我曾尝试研究过这个问题,我尝试了{display: block;}和其他人,但我没有运气。我希望我在代码中犯了错误,因为我还在学习CSS和HTML,这引起了一些麻烦。

<!doctype html>

<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>Coming Soon</title>
   <link href="css/Main.css" rel="stylesheet"> 

</head>

<body>


   <div class="container">
        <img src="img/hd-sunset-river-HD-1200x1920.jpg" width="1900" height="900">
    </div>
    <section class="content">
        <img src="img/logo.png">
        <img src="img/line.png">
        <p class="header large-2 white padding-top-triple">Coming This Fall 2015</p>
        <p class="white padding-top"><span class="header">Email: </span><a href="mailto:Jethwa96@hotmail.co.uk"><my-email data-user="Jethwa" data-domain="jedesigns.uk"></my-email></a></p> 
    </section> 





    </body>
</html>

1 个答案:

答案 0 :(得分:0)

问题是,您要将背景放在单独的div作为图像块,然后尝试将divsection对齐。这有点向后和从里到外。

我建议设置section的背景,然后将内容包装在div中,以便轻松定位section

带有背景,内部div包装内容的部分:

<section class="content">

    <div style="width:500px;
                margin:0 auto;
                top:25%;
                position:relative">

       <img src="http://jedesigns.uk/img/logo.png">
       <img src="http://jedesigns.uk/img/line.png">
       <p class="header large-2 white padding-top-triple">Coming This Fall 2015</p>
       <p class="white padding-top"><span class="header">Email: </span><a href="mailto:Jethwa96@hotmail.co.uk"><my-email data-user="Jethwa" data-domain="jedesigns.uk"></my-email></a></p> 

     </div>

</section> 

然后,对于您的section.content CSS,请更改为:

.content{
    width: 100%;
    position: relative;
    height: 1200px;
    margin: 0 auto;
    background:url(http://jedesigns.uk/img/hd-sunset-river-HD-1200x1920.jpg) no-repeat;
}

这里的jsFiddle:http://jsfiddle.net/z22hrvk9/