簡體   English   中英

如何使用CSS刪除圖像下方的多余空白

[英]How to remove the extra white space underneath an image using 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>

問題是您要將背景作為圖像塊放置在單獨的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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM