当前位置:首页 » 高清图片 » div背景图片居中
扩展阅读
女生和渣男搞笑图片 2023-08-31 22:07:09
嘻嘻长什么样图片 2023-08-31 22:06:10

div背景图片居中

发布时间: 2022-01-31 22:27:16

① 在网页设计中怎么让背景图片水平居中

CSS使网页背景图片居中的三种方法。
1、第一种:用像素设定,很多都用这种,但是也是最麻烦的:
<div
style="width:800px;height:600px;background:url(图片地址)
no-repeat
250px
270px;border:1px
solid
#cccccc;"></div>
2、第二种:用50%设定,很方便。
<div
style="width:800px;height:600px;background:url(图片地址)
no-repeat
50%
50%;border:1px
solid
#cccccc;"></div>
3、第三种:用center设定(注:第2个center可以省略,因为默认就是center)。
<div
style="width:800px;height:600px;background:url(图片地址)
no-repeat
center
center;border:1px
solid
#cccccc;"></div>

② 怎么修改背景图片居中并自适应宽度的css

在CSS中加入
margin-right:
auto;
margin-left:
auto;
意思是header这个框架左右自动对齐,这样header这个框架中的背景图片也就跟着居中了

③ CSS中背景图怎么居中显示啊

css中有一个background-position 属性设置背景图像的起始位置。

他有以下可能的值:

1,top left 左上角

2,top center 正上方

3,top right 右上方

4,center left 正左方

5,center center 正中

6,center right 正右方

7,bottom left 左下方

8,bottom center 正下方

9,bottom right 右下方


所以要是背景图居中显示,css里边加上下边这条属性:

background-position:centercenter;

④ 在网页设计中怎么让背景图片水平居中

background:url(bg.jpg)
no-repeat
center
center;
:no-repeat为背景图不重复,最好是满足1280宽度的分辨率下位满屏,图片可以宽度为1280像素,第一个center为水平居中,第二个center为垂直居中,第二个center换成top也就是顶部显示背景图。

⑤ div背景图片无法居中

<body style="background:url(1.jpg); padding:0; margin:0;">
<div style="background:url(body-1.jpg) center center no-repeat; margin:0 auto; width:900px; height:538px;"></div>
</body>
这里已经是没问题了,如果还有问题的话,那就应该是其他地方的样式定义了左浮动了,仔细找找,或者把页面发出来看看

⑥ div+css 背景图垂直居中

div+css实现背景图片居中;


首先设置一个div区域,定义一个最外围的区域块,然后再次设置一个小的div区域在其css样式里设置一个背景图片,让小的div区域居中即可:属性:margi:0 auto;

<!DOCTYPEhtml>
<html>
<head>
<metacharset="gb2312"/>
<title>效果区</title>

</head>
<body>
<style>
.main{width:100%;height:500px;background-color:#06F;}
.bjimg{background:url(111111.png)no-repeat;width:525px;height:300px;margin:0auto;}
</style>
<divclass="main">
<divclass="bjimg">

</div>
</div>
</body>
</html>

实现效果网页区域:

标签以及属性详解:

外围div样式取名main:设置一个宽度为100%,高度height:500px的区域让其背景颜色background-color:#06F;蓝色,这样可以更好的浏览效果;

内部的一个小的区域div取名:bjimg,区域大小就是图片的大小;设置一张背景图片,background:url(111111.png) no-repeat;,

margin:0 auto; 让其在大区域块中左右居中,上下设置为0,当然如果感觉太靠上了可以将其值(0)修改一下,数值越大距离越远

⑦ css,如何使整个页面背景图片居中

css使整个页面背景图片居中,你是可以给一个总的div设置好一定的width和height,然后给它来设置背景图片,在通过margin让他们居中,同时,background的repeat来平铺实现,具体代码:

<html>
<head>
<style>
#div1{
width:960px;
height:1200px;
border:1pxsoild#f00;
background:url('图片地址')repeat0px0px;
margin:0auto;
}

</style>
</head>

<body>
<divid='div1'>

</div>
</body>
</html>

⑧ 在html代码中怎么让背景图片居中

用background-position属性来实现。

参考代码:

<html>
<head>
<styletype="text/css">
body
{
background-image:url(/i/eg_bg_desert.jpg);'背景图
background-position:centercenter;'居中
background-repeat:no-repeat;'图片不重复

}
</style>
</head>
<body>
</body>
</html>

⑨ CSS 如何 让背景图片居中

background-position:center;

<!doctypehtml>
<html>
<head>
<metacharset="utf-8">
<title>无标题文档</title>
<styletype="text/css">
#t{
margin:50pxauto;
border:1pxsolidred;
width:700px;
height:200px;
background-image:url(1.png);
background-repeat:no-repeat;
background-position:center;
}
</style>
</head>

<body>
<divid="t">
</div>
</body>
</html>

⑩ css背景图片放到最顶端居中 不重复

简写代码如下:

background:url(../images/abc.png)no-repeatcentertop;

说明:

  1. ../images/abc.png代表图片路径;

  2. no-repeat是不循环;

  3. center是水平方向居中;

  4. top是垂直方向居顶。