Javascript 使文本大小适应引导中的图像和屏幕大小

Javascript 使文本大小适应引导中的图像和屏幕大小,javascript,jquery,css,twitter-bootstrap,bootstrap-4,Javascript,Jquery,Css,Twitter Bootstrap,Bootstrap 4,下面是我的SSCCE的一个示例,但我的代码要点如下。我正在使用Twitter Bootstrap 4.0制作一个简单的页面: <!DOCTYPE HTML> <html> <head> <title>FooBar</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="vi

下面是我的SSCCE的一个示例,但我的代码要点如下。我正在使用Twitter Bootstrap 4.0制作一个简单的页面:

<!DOCTYPE HTML>
<html>
<head>
    <title>FooBar</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous" />
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<div class="container text-center mx-auto">
    <div class="col-lg-12 col-sm-12 well-lg">
        <img src="https://s3.amazonaws.com/smeeb-public-images/foobar.png" class="img-fluid mx-auto img-rounded" alt="FooBar logo" />
    </div>
    <div class="col-lg-12 col-sm-12 well-lg">
        <h1 style="color: rgb(0, 170, 236); font-size: 40px;">FOOBAR</h1>
    </div>
    <div class="col-lg-12 col-sm-12 well-lg alert alert-danger">
        <strong>Oops!</strong> Something went wrong!
    </div>
    <div class="col-lg-12 col-sm-12 well-lg">
        <button type="button" class="btn btn-primary btn-lg">Sign In</button>
    </div>
    <div class="col-lg-12 col-sm-12 well-lg">&nbsp;</div>
</div>
</body>
</html>
正如您在JSFIDLE中看到的,有几个突出的问题:

图像太大了;和 图片下方的h1标题太小;和 图像和标题并非在大屏幕/视口上水平居中 我试图直接调整引导类或CSS样式,以便:

图像和标题始终完全居中 在更大屏幕的台式机/笔记本电脑浏览器上,图像可能只占屏幕高度+宽度的20% 在较小屏幕的手机上,图像占据了屏幕的大部分宽度,可能两侧都有几%的填充 在所有情况下,h1标题都会尽最大努力调整文本大小,使其宽度与图像的宽度大致相同
有人知道我哪里出错了吗?

下面是一个你可能会做的例子。很明显,样式的细节取决于您的喜好

.嗯,lg img{ 宽度:20%; } 身体{ 显示器:flex; 证明内容:中心; } @媒体屏幕和最大宽度:468px{ .嗯,lg img{ 宽度:80%; } .嗯,lg h1{ 字体大小:4em!重要; } } 福巴 福巴 哎呀!出了点问题! 登录