背景图片和html中的图片之间的差距

时间:2018-12-26 18:46:09

标签: html css

我的背景图片之间存在空白,我希望弥补这一空白。我该怎么做呢?

我尝试过删除文本,将页边距设置为0,删除空白,将div彼此内联,将背景图像设置为HTML中的独立图像,更改图像的高度。我很沮丧!

HTML:

<div class="main">
        <h1 id="mainTitle">Sample Text</h1>
        <hr>
        <i class="fa fa-id-card" aria-hidden="true"></i><h3 id="underTitle">Sample Text</h3>
    </div>
    <input type="submit" class="btn" value="Sample Text">
    <div class="projects">
        <h1 id="proTitle">Sample Text</h1>
        <img src="images/codebg.jpg" alt="Sample Text" id="codeimg">
    </div>

CSS:

html, body{
    font-family: 'Thasadith', sans-serif;
    background-image: url(images/bg.png);
    background-repeat: no-repeat;
}

.main{
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    top: 350px;
    font-size: 0;
    margin: 0 auto;
}
#mainTitle{ font-size: 100px;}
#underTitle{ font-size: 50px; margin-top: 10px;}

#mainTitle, #underTitle{
    transition: font-size 1s;
}
#mainTitle:hover{
    font-size: 110px;
}
#underTitle:hover{
    font-size: 60px
}
.fa-id-card{
    position: absolute;
    transform: translateX(-125px);
    top: 77%;
    font-size: 20px;
}
hr{
    margin: 0 auto;
    padding: 0;
    background-color: black;
}
.btn{
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    top: 560px;
    width: 100px;
    background-color: black;
    color: white;
    transition: width 1s ease;
}
.btn:hover{
    color: white;
    width: 110px;
}

.projects{
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    top: 1100px;
    /*background-image: url(images/codebg.jpg);*/
    width: 100%;
    height: 100%;
    margin: 0 auto;


}
#proTitle{
    color: black;
    margin: 0 auto;
}
#codeimg{
    opacity: 0.4;
}

理想情况下,图像之间应该没有间隙

感谢任何人都可以提供的帮助

3 个答案:

答案 0 :(得分:0)

您可以更改图像的位置类型。 将此代码添加到您的CSS文件中:

img 
{
   position: relative;
   bottom: -4px;
}

我重新创建了更改图像的代码。 您可以在此链接中看到: https://codepen.io/mvinnicius/pen/aPyObB

希望对您有帮助

答案 1 :(得分:0)

这里有一些小的改动可以使它起作用:

CSS:为您的标题ID添加break.beforebreak.after样式

#mainTitle{
    font-size: 100px;
    break.after: 0;  }

#underTitle{
    font-size: 50px;
    margin-top: 10px;
    break.before: 0; }

#mainTitle, #underTitle{
    transition: font-size 1s;   }

#mainTitle:hover{
    font-size: 110px;
    break.after: 0;  }

#underTitle:hover{
    font-size: 60px;
    break.before: 0; }

HTML:将<div class="main">换成语义正确的<main>,然后不要使用<h1><h3>(这会在它们周围加空格),而是将其包装在{{ 1}}标签。

<p>

答案 2 :(得分:-1)

玩.projects CSS 顶部和左侧