html - Responsive text size using ems -
i trying learn responsive webdesign techniques , trying code website in responsive way. don't want use frameworks yet. problem div width in ems different on mobile on desktops. when viewing on desktop, h1
fits div , on mobile not. shouldn't same in both case? sizes in em.
here html code:
<!doctype html> <!--[if ie 8]> <html class="no-js lt-ie9" lang="en" > <![endif]--> <!--[if gt ie 8]><!--> <html class="no-js" lang="en" > <!--<![endif]--> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>sieć z pasją</title> <link rel="stylesheet" href="css/style.css"> <!-- google webfonts --> <!-- font-family: 'expletus sans', cursive; --> <link href='http://fonts.googleapis.com/css?family=expletus+sans' rel='stylesheet' type='text/css'> </head> <body> <div class="transparent-bg"> <h1><span class="hello">hello</span> </br><span class="is">my name is</span> </br><span class="adam">adam</span></h1> </div> </body> </html>
css:
body { background:url('../img/background.jpg') no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; filter: progid:dximagetransform.microsoft.alphaimageloader(src='.mybackground.jpg', sizingmethod='scale'); -ms-filter: "progid:dximagetransform.microsoft.alphaimageloader(src='mybackground.jpg', sizingmethod='scale')"; } .transparent-bg { background-color:rgba(185,178,160,0.6); padding:2em; padding-top:5em; max-width:30em; position:relative; left:4em; top:5em; } h1 { font-family: 'expletus sans', cursive; color:black; line-height:1em; } span.hello { font-size:4em; } span.is { letter-spacing:0.4em; position:relative; left:0.3em; } span.adam { font-size:3em; letter-spacing:0.15em; position:relative; top:0.3em; }
here live version: adamlakomy.pl. appreciate help.
the problem text sizes not re-sizing based on window. here great article understand responsive re-sizing.
to fix have few options.
the first use @media
queries - can still use em
s! note: when using em
s should have base em
others (including width, height, , other font sizes) based off of. can affect changing 1 font size. example
media , (max-width: 25em) { html { font-size:50%; } }
this make text have half it's original size when screen smaller 25em
width
a second option use javascript (this uses jquery well) it. pulled example this post, can find or come more eloquent solution if want use method. here example
$(function() { $(window).bind('resize', function() { resizeme(); }).trigger('resize'); }); function resizeme() { //standard height, body font size correct var preferredheight = 768; var displayheight = $(window).height(); var percentage = displayheight / preferredheight; var newfontsize = math.floor(/*default font size*/ * percentage) - 1; $("body").css("font-size", newfontsize); }
or use plugin don't recommend paragraphs of text, small amount work fine. 2 of common ones fittext , bigtext
Comments
Post a Comment