1

I have the following HTML and CSS codes :

HTML :

<div>
    <a href="#">ITALIANO</a>
    <a href="#">ENGLISH</a>
    <a href="#">FRANÇAIS</a>
    <a href="#">DEUTSCH</a>
</div>

CSS :

div>a{
   margin-left: 30px;
}

div{
   font-size: 28px;
   width: 70%;
   margin: 2% auto;
}

There is no problem at normal zoom. The problem appears when I zoom in and out, as the text gets too big which makes it use two lines, or gets too small. Is there any way to adjust the font size dymamically without JavaScript?

Thanks

user1319182
  • 481
  • 12
  • 26
  • 1
    you might want to fix up the title of this question as it has nothing to do with what youre asking. also, see this: http://stackoverflow.com/questions/14431411/pure-css-to-make-font-size-responsive-based-on-dynamic-amount-of-characters – Jacob Raccuia Mar 12 '15 at 16:07
  • @JacobRaccuia I hope the new one is better. – user1319182 Mar 12 '15 at 16:09

2 Answers2

2

as taken from this SO answer, you can set font size to respond to the viewport width.

p {
    font-size: 30px;
    font-size: 3.5vw;
}

More information can be found at CSS Tricks.

Community
  • 1
  • 1
Jacob Raccuia
  • 1,666
  • 1
  • 16
  • 25
-1

I was going to suggest (until I saw @Jacob answer on viewport-sized Typography, wouldn't know of any Bugs though). The idea is assign a universal font-size in your html code inside your css code. Base font-size is set to 16px=1em. Then rest of your CSS code font sizes can be in percentage, which will make them responsive according to screen width. For example:

html {
font-size: 1em;
}

div>a{
margin-left: 30px;  <-- I would use left margin as percentage here, which will adjust according to screen width.
    }

div{
font-size: 175%;  <-- this is for 28px
width: 70%;
margin: 2% auto;
}
Mugé
  • 452
  • 3
  • 15