会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132428个问题
Python 全系列/第七阶段:网页编程基础/浮动与定位 32612楼
Python 全系列/第一阶段:Python入门/控制语句 32615楼

老师,我在做分辨率和缩放率的测试时,发现在div设置了背景图后,div内的文字本来是居中的,一般的分辨率也正常,但是在电脑的缩放率300%和分辨率变得很大,到达4000左右的时候,就会出现文字不居中了的情况了?这是为什么呢?背景图在设置为宽100%,高为auto,不就是自适应页面大小的,文字设置了center,我觉得就不会出现这种情况的。实在不明白了,麻烦老师了,正常图和问题图如下:


<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0,
 maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <title>flex</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询(media queries)功能 -->
    <!-- 警告:通过 file:// 协议(就是直接将 html 页面拖拽到浏览器中)访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script
    <![endif]-->
    <script src="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css"></script>
    <script src="https: //cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    <style>
        *{
            margin: 0px;
            padding: 0px;
        }
        html,body{
            width: 100%;
            height: 100%;
            background: #0d3349;
        }
        body{
            min-width: 768px;
        }
        #div{
            width: 100%;
            height: 100%;
            background: #00c2de;
        }
        #div1{
            background: #bd362f;
            background-image:url(static/images/shouye-biaoti.png);
            background-size: 100% auto;
            background-repeat: no-repeat;
            width: 100%;
            height: 15%;
            margin-top: 1%;

        }

        h1{
            text-align: center;
            font-size: 0.7rem;
            font-weight: 700;

        }

    </style>
</head>
<script>
    function setRem() {
        var whdef = 100 / 1920
        var bodyWidth = document.body.clientWidth
        console.log(bodyWidth)
        console.log(window.screen.width)
        var rem = bodyWidth * whdef
        document.getElementsByTagName('html')[0].style.fontSize = rem + 'px'
    }
    window.addEventListener('load', setRem)
    window.addEventListener('resize', setRem)
</script>
<body  style="font-size: 60px">
<div id="div">
        <div id="div1" >
            <h1 >标题</h1>
        </div>
</div>
</body>
</html>


WEB前端全系列/第二阶段:JavaScript编程模块/正则对象 32617楼

老师,我想求出二叉树中两个节点的距离,我的代码如下,函数已经写出来了,但是不知道如何返回level值,麻烦您帮我改一下,谢谢您了

class BiTNode:
    def __init__(self):
        self.data = None
        self.lchild = None
        self.rchild = None

def arraytotree(arr,start,end):
    #中序遍历生成二叉树
    root = None
    if end >= start:
        root = BiTNode()
        mid = (start+end+1)//2
        root.data = arr[mid]
        root.lchild = arraytotree(arr,start,mid-1)
        root.rchild = arraytotree(arr,mid+1,end)
    else:
        root = None
    return root

def FindParentNode(root,node1,node2):
    #找到公共父节点
    if root == None or root == node1 or root == node2:
        return root
    lchild = FindParentNode(root.lchild,node1,node2)
    rchild = FindParentNode(root.rchild,node1,node2)
    if lchild == None:
        return rchild
    elif rchild == None:
        return lchild
    else: return root

def printTree(root,node,level=1):
    #输出节点与根节点的距离level

    if root == node:
        return 0
    if root.lchild != None:
        if root.lchild == node:
            print(level)
        printTree(root.lchild,node,level=level+1)
    # print(root.data,end=" ")
    if root.rchild != None:
        if root.rchild == node:
            print(level)
        printTree(root.rchild,node,level=level+1)

if __name__=="__main__":
    arr = [1,2,3,4,5,6,7,8,9,10]
    root = arraytotree(arr,0,len(arr)-1)
    node1 = root.rchild.lchild.lchild
    node2 = root.lchild.rchild.lchild
    L = printTree(root,node1)
    M = printTree(root,node2)
    res = FindParentNode(root,node1,node2)
    N = printTree(root,res)
    print(L,M,N)
    distance = printTree(root,node1)+printTree(root,node2)-2*printTree(root,res)
    # if res != None:
    #     print(str(node1.data))
    #     print(str(node2.data))
    #     print(str(res.data))
    # print(distance)


Python 全系列/第十六阶段:数据结构与算法/算法与数据结构(旧) 32618楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 32619楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 32622楼
Python 全系列/第一阶段:Python入门/面向对象 32624楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/反射技术 32625楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637