【CSS】css插入背景图,底线留有白边,怎么才能去掉?

试了网上的方法,都不好使

#body, body {

/*background: #f0f0f0;*/

}

html, body{

height:100%;

width:100%;

/*padding:0px;*/

/*border:0px;*/

/*margin:0px;*/

/*box-sizing: border-box;*/

}

img{

border:0px

}

.bg42beff {

background: #42beff;

}

.index-root {

height: 100%;

box-sizing: border-box;

margin: 0;

border: 0;

padding: 0;

background: url("../images/bg.jpeg") repeat-y center;

vertical-align: middle;

/*background-size: auto 100%;*/

font-size: 0;

}

.index-title {

width: 100%;

height: 44px;

overflow: hidden;

background-color: #51a1ff;

line-height: 44px;

font-size: 18px;

color: #fff;

text-align: center;

}

.flex-center {

display: flex;

justify-content: center;

align-items: center;

}

.title-return {

width: 50px;

height: 44px;

background: url(../images/arrow_left.png) 50% no-repeat;

background-size: 18px auto;

left: 0;

top: 0;

position: absolute;

}

.logo-container {

width: 100%;

box-sizing: border-box;

padding-left: 10px;

padding-right: 10px;

margin-top: 10px;

display: flex;

justify-content: center;

align-items: center;

}

.logo-image {

width: 230px;

display: block;

height: 230px;

}

.button-create {

width: 100px;

height: 50px;

background: #51a1ff;

color: #ffffff;

}

.mode-select-container {

width: 100%;

/*background: #99FF00;*/

box-sizing: border-box;

margin-top: 10px;

overflow: hidden;

}

.mode-select-container::after {

clear: both;

content: '';

display: block;

}

.buttons-room-container {

width: 84.8%;

height: 44px;

border-radius: 4px;

font-size: 18px;

margin: 19px auto;

line-height: 44px;

/*border-radius: 20px;*/

box-sizing: border-box;

/*background: #99FF00;*/

display: flex;

justify-content: space-between;

padding-left: 10px;

padding-right: 10px;

color: #ffffff;

}

.button-create-room, .button-join-room {

width: 150px;

background-color: #42beff;

}

.buttons-mode-container {

width: 84.8%;

height: 44px;

border-radius: 4px;

font-size: 18px;

margin: 19px auto;

line-height: 44px;

/*border-radius: 20px;*/

box-sizing: border-box;

background: #99FF00;

display: flex;

justify-content: space-between;

padding-left: 10px;

padding-right: 10px;

color: #ffffff;

}

.button-tourist-mode, .button-match-mode, .button-qualifying-mode {

width: 100px;

background-color: #42beff;

}

.buttons-videos-container {

width: 84.8%;

height: 44px;

border-radius: 4px;

font-size: 18px;

margin: 19px auto;

line-height: 44px;

/*border-radius: 20px;*/

box-sizing: border-box;

background: #99FF00;

display: flex;

justify-content: space-between;

padding-left: 10px;

padding-right: 10px;

color: #ffffff;

}

.button-tutorial-videos {

}

<div class='index-root'>

<div class='index-title'>

<div class='title-return left' data-v-2609e579=""></div>

全球首款吐槽类历史游戏 - 战斗棋

</div>

<div>

<div class='logo-container'>

<img class='logo-image' src="assets/images/logo_temporary.png" />

</div>

<div class='game-introduce-container'>

<div>无论你的过去、现在或者未来多么辉煌</div>

<div>终不过是我手中的一枚棋子</div>

</div>

<div class='mode-select-container'>

<div class='buttons-room-container'>

<div class='button-create-room flex-center'>创建房间</div>

<div class="button-join-room flex-center">加入房间</div>

</div>

<div class='buttons-mode-container'>

<div class="button-tourist-mode flex-center">排位模式</div>

<div class="button-match-mode flex-center">匹配模式</div>

<div class="button-qualifying-mode flex-center">游客模式</div>

</div>

<div class='buttons-videos-container flex-center'>

<div class='button-tutorial-videos bg42beff'>新手教程</div>

</div>

</div>

</div>

</div>

bg的副本.jpeg

501.png

我把代码抽出来了

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

<meta name="description" content="刘小尖">

<meta name="keywords" content="战斗棋, 吐槽, 明星, 交友, 游戏王, 炉石传说, 棋牌, 游戏,国产,五子棋, 九宫格, 刘小尖, 历史, 独创, 简单">

<meta name="author" content="Abbott">

<meta name="fragment" content="!">

<title>战斗棋 - 首页</title>

<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">

<link rel='stylesheet' href="assets/styles/base.css" />

<link rel='stylesheet' href="assets/styles/index.css" />

<style>

#body, body {

/*background: #f0f0f0;*/

}

html, body{

height:100%;

width:100%;

/*padding:0px;*/

/*border:0px;*/

/*margin:0px;*/

/*box-sizing: border-box;*/

}

img{

border:0px

}

.bg42beff {

background: #42beff;

}

.index-root {

height: 100%;

box-sizing: border-box;

margin: 0;

border: 0;

padding: 0;

background: url(./assets/images/bg.jpeg) 50% no-repeat;

vertical-align: middle;

/*background-size: auto 100%;*/

font-size: 0;

background-size: cover;

}

</style>

</head>

<body>

<div class='index-root'>

</div>

</body>

回答:

1.先看看你的index-root的高度(加个border看看是不是包着那个白边)
2.加上这个试试:background-size: 100% 100%
3.检查背景图片是不是本来就有一个白边

回答:

用你的代码,加了body{margin: 0}以后就没有问题了

回答:

建议你抽取出有关代码放进一个单独的html里。检验效果。

回答:

background-size: cover

以上是 【CSS】css插入背景图,底线留有白边,怎么才能去掉? 的全部内容, 来源链接: utcz.com/a/154367.html

回到顶部