[英]Auto adjust font size when resizing
i just want to ask how am i able to make the font size change responsively (like a zoom effect no cuts) when resizing?我只是想问一下,在调整大小时,我如何能够响应式地更改字体大小(如缩放效果没有剪切)? I got bootstrap.css, jquery.js and bootstrap.js
我得到了 bootstrap.css、jquery.js 和 bootstrap.js
<div class="full-width1">
<div class="container">
<h1 class="firstinfo">About SWA{PRO}SE</h1>
<p class="desc">The Software and Web Application Professionals and System Engineers (SWAPROSE) is a team of IT experts with vast experience in intranet business software, web application and game development.</p>
</div>
</div>
<div class="full-width2">
<div class="arrow-white"></div>
<div class="container">
<h1 style="color:#1798AA; font-weight:bold">Project Development</h1>
<p class="desc">Swaprose provides a variety of project developments, from games to software. we create the applications need for our clients. We also create independent mobile games to be released on Android and iOS.</p>
</div>
</div>
</div>
Auto adjust font size when resizing
调整大小时自动调整字体大小
You can use vw
units to do that :您可以使用
vw
单位来做到这一点:
h2 {font-size: 8vw;}
Compatibility : http://caniuse.com/#search=vw兼容性: http : //caniuse.com/#search=vw
You can use css @media and apply to element, class or id In the sample is used an id您可以使用 css @media 并应用于元素、类或 id 示例中使用了一个 id
@media all and (max-width: 1200px) {
#your_id{font-size: 18px;}
}
@media all and (max-width: 700px) {
#your_id{font-size: 16px;}
}
You could use the JQuery event .resize()
and the css property transition-duration
您可以使用 JQuery 事件
.resize()
和 css 属性transition-duration
you need to add a re-size listener, would look something like: `你需要添加一个重新调整大小的监听器,看起来像:`
$(".container").resize( function(){
$(".container").css("font-size","24px");
//can be an algorithim like:
// var size $(".container").width() / 4;
//$(".container").css("font-size",size+"px");
});
CSS: CSS:
.container
{
font-size:16px
transition-duration: 0.4s;
-ms-transition-duration: 0.4s;
-moz-transition-duration: 0.4s;
-webkit-transition-duration: 0.4s;
}
If you don't want to use media queries and have that 'cutting' effect, you could always use jQuery.如果您不想使用媒体查询并具有“剪切”效果,则可以始终使用 jQuery。 I just quickly wrote this:
我只是很快写了这个:
// Resize text
function resize_text(){
// Var
f = $(window).width()/50;
min = 12;
if(f > min){
$('p').css('font-size',f + 'px');
} else {
$('p').css('font-size',min + 'px');
}
}
// Fire on resize
$(window).resize(function(){
resize_text();
})
// Init
resize_text();
Min being the smallest the text will go (otherwise it will be unreadable) Min 是最小的文本(否则它将不可读)
Working example here这里的工作示例
http://codepen.io/jcoulterdesign/pen/d54fc17bad1d651ab174b5708b16fb3c http://codepen.io/jcoulterdesign/pen/d54fc17bad1d651ab174b5708b16fb3c
A JS Project that will help you learn how the tweeks work.一个 JS 项目,将帮助您了解 tweeks 是如何工作的。 You can modify it very easily
你可以很容易地修改它
http://codepen.io/ShuvoHabib/pen/gPzdzO http://codepen.io/ShuvoHabib/pen/gPzdzO
From the code从代码
function doResize() {
resize(document.getElementById('text'), 5);
}
Change the value '5' as you wish to get the ratio of fontsize according to view/screen size.根据视图/屏幕大小更改值“5”,因为您希望获得字体大小的比率。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.