最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Implement a max-font-size style rule with CSSjavascriptjquery - Stack Overflow

programmeradmin1浏览0评论

I am using this code to dynamically resize text:

function fontResize(){
   $('.features').css('font-size', ($(window).width()/100) + 'px');
}

fontResize();
$(window).resize( function () {fontResize()});

This works great for pulling the browser inwards but when i'm stretching the screen out on my 21" iMac, the text is too big for a set size DIV i have. how can i implement a solution whereby i can cap the maximum font size on the text. Will i be able to override this function above and put a max-font-size of 13px?

Thanks

I am using this code to dynamically resize text:

function fontResize(){
   $('.features').css('font-size', ($(window).width()/100) + 'px');
}

fontResize();
$(window).resize( function () {fontResize()});

This works great for pulling the browser inwards but when i'm stretching the screen out on my 21" iMac, the text is too big for a set size DIV i have. how can i implement a solution whereby i can cap the maximum font size on the text. Will i be able to override this function above and put a max-font-size of 13px?

Thanks

Share Improve this question edited Jul 30, 2013 at 18:19 benhowdle89 asked Jul 14, 2011 at 22:14 benhowdle89benhowdle89 37.5k74 gold badges207 silver badges340 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4
function fontResize(){
   var size = $(window).width()/100;
   if ( size < 13 )
       $('.features').css('font-size', size + 'px');
}

You could implement a sizeRange to define maximum and minimum font sizes.

function fontResize(){
  var sizeRange = [6, 13];  
  var size = $(window).width()/100;

  if ( size <= sizeRange[1] && size >= sizeRange[0] ) {
    $('.features').css('font-size', size + 'px');
  } else {
    // font-size out of range
  }
}
发布评论

评论列表(0)

  1. 暂无评论