[英]Adapting text size to image & screen size in Bootstrap
Here is a the jsFiddle link to my SSCCE, but the gist of my code is below. 这是到我的SSCCE的jsFiddle链接 ,但是下面是我的代码的要点。 I'm using Twitter Bootstrap 4.0 to make a simple page: 我正在使用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"> </div>
</div>
</body>
</html>
As you can see in the jsFiddle, there are several glaring issues: 正如您在jsFiddle中看到的那样,存在几个明显的问题:
h1
title under the image is way too small; 该h1
的图像下标题来说太小了; and 和 I'm trying to tune either the bootstrap classes or the CSS stylings directly so that: 我试图直接调整bootstrap类或CSS样式,以便:
h1
title does its best to resize the text so that its width is more or less the same width of the image 在所有情况下, h1
标题都会尽力调整文本的大小,以使其宽度大致等于图像的宽度 Can anyone see where I'm going awry? 有人可以看到我要去哪里吗?
Here is an example of what you might do. 这是您可能会做的一个例子。 Obviously the details of the styles are up to you to match your exact preference. 显然,样式的详细信息取决于您的确切偏好。
.well-lg img{ width:20%; } body{ display:flex; justify-content:center; } @media screen and (max-width:468px){ .well-lg img{ width:80%; } .well-lg h1{ font-size:4em !important; } }
<!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"> </div> </div> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.