reduce font size but only when height decreases - html

I have a menu that comes out on click, and the design of the font is very large, so when the screen height is reduced some of the text gets hidden. Is there a way to decrease font size for only when the height is reduced? not the width? Using a media query for height kind of messes with the mobile font size.
Is there another method that I'm not thinking of the fix this issue?
First screenshot is of the nav when the height reduced, you can see the text becomes squashed.
This second image is how the nav looks at full height. I want it to keep this spacing

You can use media query like this:
#media (max-height: 600px) and (min-width: 1024px) {
/* Styles */
}
You can play with max and min properties, according to the sizes you are looking for.

You can achieve that by using vh value for font size.
h1{
fontsize: 10vh;
}

Related

Scale font size based on screen height with only CSS

Is it possible to scale font size based on screen height with only CSS?
For example, I have a sentence like this:
HELLO
WORLD
YOU ROCKS
Using this as my home page title and it is sitting inside a div that with 100vh.
What's is the calculation to make sure this text will scale and fit inside the div height? And if this is viewing in portrait mode, the font size will also keep to the max-width.
You can use
<p>HELLO
WORLD
YOU ROCKS</p>
<style>
p{
font-size:20vh;
line-height: 18vh;
}
</style>
limiting it to CSS using #media would likely be the easiest solution, create a rule for the popular screen-heights and change the font-size to a size you prefer:
#media only screen and (max-height: 600px) {
#div {
font-size: 80%;
}
}
Responsive Text
Resize the browser window to see how the text size scales.
Use the "vw" unit when sizing the text. 10vw will set the size to 10% of the viewport width.

Why some full screen website width do not match my screen width?

I use a 1920px wide screen. But when I inspect the html tag with chrome devtools on websites such as firebase or facebook messenger, this is what I see :
But these websites appear fullscreen, so I expected them to match my screen width.
Why is there a difference between my screen width (1920px) and the html tag width (1440px) and how to achieve this ?
If you set the width of the body of your HTML to a fixed width of 1440px, it will be 1440px even if the user screen is bigger or smaller than this. What you can do is set width to width: 100%; and a max-width: 1440px. That would make the size of the body to be the size of the screen if the screen is smaller than 1440px and 1440px if the screen is larger or equals to 1440px.
If I understood correctly what you are asking, you have a sidebar menu and a dashboard that needs to fullfill the screen. In that case, you could do:
.side-menu {
width: 20%;
}
.dashboard {
width: 80%;
max-width: 1440px;
}
#media (min-width: 1500px) {
.side-menu {
width: 100%
}
}
Using media-query makes you set different CSS properties for the elements in your HTML, depending, in this example, of the screen size. What I did: if the screen size is smaller than 1440px, the sidebar fills 20% of it and the dashboard fills 80%. If the screen size is bigger or equals to 1500px (a little big bigger than the max-width of the dashboard, to fit the sidebar also), the dashboard stays at 1440px and the sidebar fills the rest of the screen width (width: 100% makes the sidebar takes all the width that is left of the body).
Obviously in bigger websites such as Facebook etc it's a much more complex thinking than just CSS, because they have to consider the data flow, the device the person is using and many other things.
Either you have setup a DPI scaling on your PC or have the zoom level in your browser to something higher than 100%

Change layout based on screen size

I would like the content of my website header to occupy 100% of the screen width on regular-sized desktops/laptops, but to be centered on larger displays. By "larger displays", I'm referring to the actual size of the display too, not just the resolution. On my 15" laptop and my 23" desktop (both having the same resolution of 1920x1080), I would like the displays to be different. Having such a wide menu on a 23" display doesn't look good as there are wide empty parts.
I'm currently using a .container BootStrap class for the contents of the header, and I overrided a media query so that the container has a width of 100% when the screen width exceeds 1200px. Again, this isn't really what I want :
If the screen width exceeds 1200px, the header width should be 100%
If the screen width exceeds 1920px, the header width should be the default one, and the header should be centered
If the screen width exceeds 1200px, and the screen itself is large (anything above 19"), the header width should be the default one, and the header should be centered.
I'm not sure if that's the best approach, but I'm open to all suggestions.
Thanks
My solution was to use media queries based on pixel density
This allowed to write something like
#media screen and (max-resolution: 116dpi){
116dpi is the DPI of a 19" screen with a resolution of 1920x1080. If the screen gets larger, say 23" with the same resolution, pixel density gets lower, then we have something below 116dpi.
Try out setting media screen and limitation through min-width.
http://www.w3schools.com/cssref/css3_pr_mediaquery.asp
#media screen and (min-width: 1200px) {
.container {
width: 100%;
}
}
#media screen and (min-width: 1920px) {
.container {
width: 500px;
}
}

Make a responsive navigation bar with a search box

I have a navigation bar, an example of which is available here: http://fiddle.jshell.net/4uq6y5fa.
This displays as expected when all the elements fit on the screen, but if I resize the window, bits of the menu start disappearing. How do I fix this?
Use CSS media queries:
#media only screen (//defined for particular width)
{
//code of nav bar and search box
}
e.g.
#media screen and (max-width: 300px) {
body {
background-color: lightblue;
}
}
Alternatively, you can define widths and heights in percentages(relatively), using em instead of pixels.
I don't really get what your point is, do you want to make the menu responsive or do you want to know what the problem is?
As for making it responsive, use media queries.
W3schools, The #media rule is used to define different style rules for different media types/devices.
So for example you make your width 100% for the screen size of 1920x1080 and 50% for the size of 1024x720. So your nav will "jump" to the 50% when someone resizes the website.

Is it possible to both catch browsers width and still adjust the content when browser is made smaller

Here is an example. If I, for example, set body to 70em and then adjust the browser width this rule
#media only screen and (min-width: 481px) and (max-width: 1024px)
{
body
{
background : #B0E0E6 url(img/bg.jpg) no-repeat;
}
}
is true when the width is between 481px and 1024px.
But when I have the width:70em given in body the content is not being adjusted when I make the width for the browser smaller.
If I now change a little and set the width in the body to be 80% now the content is automatically being smaller when the width of the browser is smaller.
It seems to me that it's not possible to both being able to catch when the browser is for example between 481px and 1024px and at the same time shall the content being able to be smaller when the browser width is made smaller.
So my question is if it's possible to both being able to catch when the width of the browser is between 481px and 1024px and at the same adjust the content automatically being adjusted when the width of the browser
You set the width to 70em. That's a fixed width (more or less considering it's based on font size). Within the media query you do not set the width anywhere. You just set the background. You would need to adjust the width of the object you want to resize within the media query. So if you have
body{
width:70em;
}
#media only screen and (min-width: 481px) and (max-width: 1024px)
{
body
{
background : #B0E0E6 url(img/bg.jpg) no-repeat;
width: 50em;
}
}
That would resize the body based on the media query that you specify. Also, you may wish to look up CSS units to make sure you want to use em (because by your description, % may work for your needs): http://www.w3schools.com/cssref/css_units.asp