成都创新互联网站制作重庆分公司

CSS属性让整体布局的居中以及让网页的背景居中的方法

本篇内容主要讲解“CSS属性让整体布局的居中以及让网页的背景居中的方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“CSS属性让整体布局的居中以及让网页的背景居中的方法”吧!

创新互联公司是一家专业提供祁阳企业网站建设,专注与成都网站建设、成都网站设计HTML5、小程序制作等业务。10年已为祁阳众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。

DIV+CSS布局居中问题

在DIV+CSS布局的页面里,从布局内容到页面里文章文字居中都是非常重要的,而CSS来设置居中也是非常简单的。

1、首先介绍使用CSS属性让整体布局的居中:

设置页面父级居中,那整个页面的父级是什么呢?我们可以想象整个页面的内容是由和这两个包含,那根据较近父级我们就设置body的CSS来实现居中问题,可以向在内容里居中有text-aligh:center;而这个元素在IE下有用,经过试验在火狐等浏览器下只设置text-aligh:center;居中是无法让布局居中,那我们还需要设置个“margin:0auto;”这个是什么意思呢,意思是内容上下为0距离,而左右为“auto”自动,这样就可以设置实现网页布局居中具体CSS的居中代码为:

body{text-aligh:center;margin:0auto;}但是即使这样也会出现问题,因为你没有设置布局有多宽“width”,一旦你内容布局中在最外层CSS控制中,设置了float:属性,那布局将会向你设置的float:方向靠,解决方法,除了设置body的居中的CSS属性外,还需在布局设置最外层div也居中,而且定义宽度是多少,假如网页宽度为700px,最外层CSS样式为的class="weicheng",那设置应该这样“.weicheng{margin:0auto;width:700px;}”即可。完整实例为(可将代码拷贝新建html文件浏览观看效果):

以下为引用的内容:

    www.divCSS5.com的CSSdiv的布局居中实例title> <styletypestyletype="text/CSS"> <!--  body{text-align:center;margin:0auto;}   .waicheng{color:#0066CC;margin:5pxauto;width:700px;height:200px;  border:1pxsolid#000000;}  --> style> head> <body> <divclassdivclass="waicheng">我是CSS中的居中的实验;我的布局外层有一个边为1px黑色边,   我宽700px,高为200px,设置了与顶部内容距离为5PXdiv> body> html></pre><p><strong>DIV+CSS布局居中实例浏览</strong></p><p><strong>2、介绍使用CSS属性让网页的背景居中:</strong></p><p>这里居中就包括了左右居中与上下居中,居中代码如下:<br/>body{BACKGROUND:#FFFurl(http://www.divCSS5.com/img/CSS-logo.gif)no-repeatcenter;}//这段话意思就是让CSS-logo.gif这个图片设置背景不重复(no-repeat),并将居中(center)这个居中是左右居中,而垂直不需要设置,自动会居中。</p><p><strong>3、CSS让介绍文字、图片内容左右上下居中方法教程:</strong></p><p>我们知道左右就中好办,直接用text-align:center;即可让文字与图片内容居中,但是垂直呢,假如我们在高度为120px的高度下垂直居中,图片居中是vertical-align:middle;CSS属性,文字居中就要靠设置行高方法居中文字内容,这里我们设置为120px的高度这需要设置个line-height:120px;这样就通过CSS属性类样式来实现文字与图片的上下左右居中。</p><p>整个网站居中的代码如下:</p><p>以下为引用的内容:</p><pre><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <htmlxmlnshtmlxmlns="http://www.w3.org/1999/xhtml"> <head> <metahttp-equivmetahttp-equiv="Content-Type"content="text/html;charset=gb2312"/> <title>www.divCSS5.com的CSSdiv的完整居中实例title> <styletypestyletype="text/CSS"> <!--  body{text-align:center;margin:0auto;background:url(http://www.divCSS5.com/img/CSS-logo.gif)no-repeatcenter;}  .waicheng{color:#0066CC;margin:5pxauto;width:700px;height:120px;  line-height:120px;border:1pxsolid#000000;}  .waichengimg{vertical-align:middle;}  --> style> head> <body> <divclassdivclass="waicheng">我是CSS中的居中的完整居中实例;  我的布局外层有一个边为1px   <imgsrcimgsrc="/upload/otherpic60/486843.gif" alt="图片内容居中"/>div> body> html></pre><p>到此,相信大家对“CSS属性让整体布局的居中以及让网页的背景居中的方法”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!</p>            
            
                        <br>
            网站标题:CSS属性让整体布局的居中以及让网页的背景居中的方法            <br>
            网页URL:<a href="http://cxhlcq.com/article/jcsecc.html">http://cxhlcq.com/article/jcsecc.html</a>
        </div>
    </div>
</div>
<div class="other container">
    <h3>其他资讯</h3>
    <ul>
        <li>
                <a href="/article/dchhcsg.html">两个腾讯云服务器镜像 两个腾讯云服务器镜像怎么连接</a>
            </li><li>
                <a href="/article/dchhcsh.html">阿里云服务器费用可退吗 阿里云服务器可以续费一天吗</a>
            </li><li>
                <a href="/article/dchhcoj.html">php链接数据库出现错误 php数据连接失败的原因</a>
            </li><li>
                <a href="/article/dchhced.html">怎么找回自己之前的域名 如何找回域名管理权限</a>
            </li><li>
                <a href="/article/dchhcop.html">手机地域名怎么改 如何更改手机地域</a>
            </li>    </ul>
</div>
<div class="footer">
    <div class="foota container">
        <div class="foot_nav fl col-lg-8 col-md-8 col-sm-12 col-xs-12">
            <ul>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>网站制作</h3>
                    <a href="http://m.cdcxhl.cn/mobile/" target="_blank">手机网站制作</a><a href="http://www.cxjianzhan.com/" target="_blank">成都网站制作</a><a href="http://www.cxjianzhan.com/mobile/" target="_blank">手机网站制作</a><a href="http://www.cxhlcq.com/zhizuo/" target="_blank">重庆网站制作</a><a href="https://www.cdxwcx.com/" target="_blank">成都网站制作</a><a href="http://www.cdxwcx.cn/bj/" target="_blank">网站制作报价</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>企业服务</h3>
                    <a href="https://www.cdcxhl.com/shoulu/" target="_blank">网站收录</a><a href="https://www.cdcxhl.com/service/licence.html" target="_blank">药房许可证</a><a href="https://www.cdcxhl.com/shoulu/" target="_blank">分类目录</a><a href="https://www.cdcxhl.com/shoulu/" target="_blank">免费收录网站</a><a href="https://www.cdcxhl.com/ruanwen/yingxiao/" target="_blank">软文推广</a><a href="https://www.cdcxhl.com/mianfei/jianzhan/" target="_blank">免费建站模板</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>网站建设</h3>
                    <a href="https://www.cdxwcx.com/wangzhan/mobile.html" target="_blank">成都手机网站建设</a><a href="http://www.cdweb.net/solve/" target="_blank">网站建设方案</a><a href="http://www.kswcd.com/service/" target="_blank">上市集团网站建设</a><a href="http://m.cdcxhl.cn/dingzhi/" target="_blank">成都定制网站建设</a><a href="http://www.cddcz.com/" target="_blank">成都网站建设</a><a href="http://www.cdkjz.cn/fangan/education/" target="_blank">教育培训网站建设方案</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>服务器托管</h3>
                    <a href="http://www.cdfuwuqi.com/" target="_blank">服务器托管机房</a><a href="https://www.cdcxhl.com/idc/cqyd.html" target="_blank">重庆移动机房托管</a><a href="https://www.cdcxhl.com/tuoguan/" target="_blank">IDC机房托管</a><a href="https://www.cdcxhl.com/idc/mianyang.html" target="_blank">绵阳服务器托管</a><a href="http://www.cdxwcx.cn/tuoguan/mianyang.html" target="_blank">绵阳主机托管</a><a href="http://www.cdfuwuqi.com/jigui/" target="_blank">成都机柜租用</a>                </li>
            </ul>
        </div>
        <div class="footar fl col-lg-4 col-md-4 col-sm-12 col-xs-12">
            <p>全国免费咨询:</p>
            <b>400-028-6601</b>
            <p>业务咨询:028-86922220 / 13518219792</p>
            <p>节假值班:18980820575 / 13518219792</p>
            <p>联系地址:成都市太升南路288号锦天国际A幢1002号</p>
        </div>
    </div>
    <div class="footb">
        <div class="copy container">
            <div class="fl">Copyright © 成都创新互联科技有限公司重庆分公司  <a href="https://beian.miit.gov.cn/" target="_blank">渝ICP备2021005571号</a></div>
            <!--<div class="fr"><a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>:<a href="https://www.cdcxhl.com/" target="_blank">创新互联</a></div>-->
        </div>
    </div>
    <div class="link">
        <div class="container">
            友情链接::
            <a href="https://www.cdcxhl.com/" target="_blank">成都网站建设</a>
            <a href="https://www.cdcxhl.com/city/chongqing.html" target="_blank">重庆网站建设</a>
            <a href="">四川网站建设</a>
            <a href="">重庆建设网站</a>
            <a href="https://www.cdxwcx.com/jifang/xiyun.html" target="_blank">移动服务器托管</a>
            <a href="http://www.cdfuwuqi.com/" target="_blank">成都服务器托管</a>
            <a href="https://www.cdcxhl.cn/" target="_blank">云服务器</a>
            <a href="http://www.cdhuace.com/" target="_blank">广告设计制作</a>
            <a href="https://www.cdcxhl.com/sheji/chongqing.html" target="_blank">重庆网页设计</a>
            <a href="https://www.cdcxhl.com/zuo/chongqing.html" target="_blank">重庆做网站</a>
            <a href="https://www.cdcxhl.com/zhizuo/chongqing.html" target="_blank">重庆网站制作</a>
            <a href="">重庆网站建设</a>
            <a href="">重庆网站公司</a>
            <a href="">渝中网站制作</a>
            <a href="">重庆网站设计</a>
        </div>
    </div>
</div>
<div class="foot">
    <ul class="public-celan">
        <li>
            <a href="https://p.qiao.baidu.com/cps3/chatIndex?siteToken=6ce441ff9e2d6bedbdfc2a4138de449e&speedLogId=162260383240185e3_1622603832401_02407&eid=6256368&reqParam=%7B%22from%22%3A1%2C%22sessionid%22%3A%22-100%22%2C%22siteId%22%3A%2211284691%22%2C%22tid%22%3A%22-1%22%2C%22userId%22%3A%226256368%22%2C%22ttype%22%3A1%2C%22pageId%22%3A0%7D" target="_blank" class="a1 db tc">
                <img src="/Public/Home/img/icon-23.png" alt="" class="db auto">
                <span class="span-txt">在线咨询</span>
            </a>
        </li>
        <li>
            <a href="tel:18980820575" class="a1 db tc">
                <img src="/Public/Home/img/icon-24.png" alt="" class="db auto">
                <span class="span-txt">电话咨询</span>
            </a>
        </li>
        <li>
            <a target="_blank" href="tencent://message/?uin=1683211881&Site=&Menu=yes" class="a1 db tc">
                <img src="/Public/Home/img/icon-25.png" alt="" class="db auto">
                <span class="span-txt">QQ咨询</span>
            </a>
        </li>
        <li>
            <a target="_blank" href="tencent://message/?uin=532337155&Site=&Menu=yes" class="a1 db tc public-yuyue-up">
                <img src="/Public/Home/img/icon-26.png" alt="" class="db auto">
                <span class="span-txt">预约顾问</span>
            </a>
        </li>
    </ul>
</div>
<div class="customer">
    <dl class="icon1">
        <dt>
            <a href="tencent://message/?uin=1683211881&Site=&Menu=yes">
                <i class="iconT"><img src="/Public/Home/img/QQ.png" alt=""></i>
                <p>在线咨询</p>
            </a>
        </dt>
    </dl>
    <dl class="icon2">
        <dt><i><img src="/Public/Home/img/weixin.png" alt=""></i><p>微信咨询</p></dt>
        <dd><img src="/Public/Home/img/ewm.png"></dd>
    </dl>
    <dl class="icon3">
        <dt><i><img src="/Public/Home/img/dianhua.png" alt=""></i><p>电话咨询</p></dt>
        <dd>
            <p>028-86922220(工作日)</p>
            <p>18980820575(7×24)</p>
        </dd>
    </dl>
    <dl class="icon4">
        <dt class="sShow">
            <a href="tencent://message/?uin=244261566&Site=&Menu=yes">
                <i><img src="/Public/Home/img/dengji.png" alt=""></i><p>提交需求</p>
            </a>
        </dt>
    </dl>
    <dl class="icon5">
        <dt class="gotop">
            <a href="#top">
                <i><img src="/Public/Home/img/top.png" alt=""></i><p>返回顶部</p>
            </a>
        </dt>
    </dl>
</div>
</body>
</html>
<script>
    $(".con img").each(function(){
        var src = $(this).attr("src");    //获取图片地址
        var str=new RegExp("http");
        var result=str.test(src);
        if(result==false){
            var url = "https://www.cdcxhl.com"+src;    //绝对路径
            $(this).attr("src",url);
        }
    });
    window.onload=function(){
        document.oncontextmenu=function(){
            return false;
        }
    }
</script>