How to control the size of a font using @media

Asked

Viewed 109 times

2

I’m trying to change the size of a font when decreasing or increasing my screen size using @media

I know this is how it works:

#Fonte{font-size:10vw;}

@media (max-height:880px){
  #Fonte{
     font-size: 10vh !important;
  }
}

But that command only deals with height.

How can I treat the height and width ?

Can be done in the same @media ?

I was thinking of something like if the screen height is changed or the screen width is changed:

@media (max-height:880px, max-width:1279px){
      #Fonte{
         font-size: 10vh !important;
      }
    }

1 answer

2


It was on the lock spoke a and at your watering

@media (max-height:880px) and (max-width:1279px){
  #Fonte{
     font-size: 10vh !important;
  }
}

Just reinforcing that for this rule to be valid the two things has to be true, so to apply this CSS in the source the screen has to be at most 880px high and at the same time has to be at most 1279px wide

EDIT

Lists separated by commas behave like the operator or when used in media queries. When we use media queries with a comma-separated list, if any media wants to return true, styles or style sheets will be applied. Each media query in a comma-separated list is treated as an individual query, and any operator applies in a media query does not affect others. This means media queries separated by commas can have different media goals.

Just one example:

@media screen and (max-width: 900px) and (min-width: 600px), (min-width: 1100px) { }

Source: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/CSS_Media_queries#Listas_separadas_por_v%C3%ADrgula

  • Understood, but I was looking for something as if I increase the height of the screen would be applied a vh in the source and if I increase the width of the screen be applied a vw in the source. So I understood a little vw changes the font relative to width and vh relative to height. , in this reply, would work if I traded the condition and for an or ?

  • 2

    @Gabrielsilva yes VH is height, and VW width of the screen, the viewport, not the container. Your rule has great chances of going wrong qq way pq is complicated to use source measures based on viewport. However I left an edition that can help you. And in the last case you can create how many rules @ media want for each height, width, orientation etc....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.