Skip to content Skip to sidebar Skip to footer

Scaling Text And Image In Css

I'm trying to scale my background image to fit any screen and at the same time writing text over the image and having this scaling to fit the screen size as well. This is the site:

Solution 1:

If you want the div fill the whole viewport, you must first set

html, body {
    height: 100%;
}

Then you can give

#imagescale {    
    width: 100%;
    height: 100%;
}

To fill it with the image

#imagescale {
    background-image: url(http://lorempixel.com/1200/1000);
    background-repeat: no-repeat;
    background-position: center top;
}

Now, you can center the text. One solution is here at CSS tricks Centering in the Unknown

#imagescale {
    text-align: center;
}

#imagescale:before {
  content: '';
  display: inline-block;
  height: 100%;
  vertical-align: middle;
  margin-right: -0.25em; /* Adjusts for spacing */
}

See full JSFiddle

Solution 2:

Why not add the text as an svg image and have it scale?

Post a Comment for "Scaling Text And Image In Css"