I have a semantic ui site that I need to scale down, it all seems too zoomed in. I would like everything to be proportionally smaller, from fonts to containers and segments.
I have tried some css approaches such as zoom: 80%; but this does not work on firefox, even though it is exactly what I was looking for when testing it in google chrome.
I then tried using transform scale:
html {
-webkit-transform: scale(0.8);
-ms-transform: scale(0.8);
transform: scale(0.8);
}
The problem with this approach is that the header and footer that were supposed to have 100% width no longer do.
Is there a semantic ui way of doing this? I have used site.variables to change the color of some predefined color variables, but I don't know if I can do it to change default size for things, decreasing px or em for every element proportionally.
Is there a CSS or Semantic UI way of doing this?
UPDATE:
As an example, when opening the site with my resolution, segments get a width of 1135px, applied by a media css when resolution is above 1200px. I would like this width either to be applied only for resolutions above 1300 or 1400px, or instead have the width of the segments to be 1000px with 1200px resolution. I would however prefer this to be set for all components in a standard way, instead of needing to write custom css for all elements to override default behaviour.
This is the current style that is being applied to each container:
#media only screen and (min-width: 1200px)
.ui.container {
width: 1135px;
margin-left: auto !important;
margin-right: auto !important;
}
Is there a better way of doing this, instead of overruling every size related style, for all width specifications? I find the site too big when I open it in a screen with a width near but above 1200.
Semantic UI uses Gulp to compile the CSS and Javascript for use in your project. You need the change the base font-size to make your components smaller. The thing is, you need to override this value before compiling. I'm afraid that that's why the solution of Barry127 won't work as expected, since the sizes for several components have already been calculated at this point.
Change the base size in {theme}/globals/site.variables:
/*-------------------
Base Sizes
--------------------*/
/* This is the single variable that controls them all */
#emSize : 14px;
/* The size of page text */
#fontSize : 14px;
Now compile everything by running gulp build. If you don't want to use the build tools shipped with Semantic UI, use your own (custom) gulp functions. Read more about theming here.
Never up- or downscale the whole document, this is not a good practice. There are still browsers out there that don't support the transform property. Also, this may cause text and borders to appear blurry.
I found a solution for this, so I am sharing it with the audience, in case someone else stumbles upon this issue.
I didn't want to simply override CSS rules as that seems a lot hard to maintain, so I wanted to have it done in a standard semantic ui way.
I ended up changing src/site/elements/container.variables, and changing the default width of the large monitor, which defaulted to 1200px:
#largeMonitorBreakpoint:1000px;
This way I guarantee that the breakpoint for large monitors is 1000px instead of 1200px, and so the width of the containers is based on this value, so every container will take up to 935px.
I think Semantic UI uses relative sizes for all elements so setting the font-size like this should do the trick:
html, body {
font-size: 14px;
}
The default value is mostly 16px
Related
I am building my project. I just noticed that I made a big mistake with using just pixel values in tables, sidebars etc. So it makes a problem, like if other person has different resolution in computer my website looks shapeless and bad.
Which codes I should use to apply responsive design?
As I know to use width, height values with % is useful. Also I don't know exactly how to use % values. What else I should do?
I use "rem" units to avoid problems (including the "media" max/min widths).
Consider 1rem = 16px for your desktop desing and 99.99% times everything goes well even in almost unknown devices.
https://www.w3.org/TR/css-values-3/#font-relative-lengths
EDIT: (cause the comment)
There are different things.
1.- Use "rem" to size things (like font-size: 0.875rem in spite of font-size:14px) to keep thing with adecuate proportions to the size of the pixels, 2.- Use #media queries to change layout when the screen is to wide/to narrow, that sizing can be done in rems to, so min-width 20rem means (more or less) the width of 20 "M" letters (not really true, but close).
Let say you have a 24 inchs screen with 1480px, and your friend have also 1480px, but in just 6 inchs. If you make font size 12 px you will see pretty nice, but probably your friend will find it small. The device/browser developers can define a different rem size, acording to the physical size of the device (24px, for example) and your 0.875 rem will be 21 pixels in his screen (not so small, more comfortable to see)
The change in layout to adapt to a narrow screen can be done using those rems also, so for the same 1480px he can have a more comfortable layout. You have a screen 1480/16=92,5 rems width, but he have 1480/20=74 rems width.
You can use percentage values just like you would use pixel values. If you want 1/4th of your website to be a sidebar, it can be as easy as:
.container {
width: 75%
}
.sidebar {
width: 25%
}
This wil make the container take up 75% of the browsers window. Since there is 25% space left, you could neatly fit a sidebar next to it by making that 25% width (you might need to add float:left to both elements).
However, I can image that on mobile view you would like your container and sidebar to be 100% width. You can do this by using media queries:
//medium phone size
#media screen (max-width: 425px) {
.container {
width: 100%
}
.sidebar {
width: 100%
}
}
There are several solutions:
Use media queries to your pages.
Use a CSS grid (and media queries)
Use Flexbox (and media queries)
Use an other css framework including a grid system
You can start with Bootstrap. That will not only make your site responsive but also there are many predefined designs for the HTML elements like buttons, fonts, tables etc. You will only have to use the classes.
If you are not well accustomed to Bootstrap the do as #Damian Makkink and #Marc_DNL have posted.
IMO a self-built CSS for a responsive site and design is better. Initially, in my hobby project, I started with Bootstrap but I have completely phased that out.
I am studying the Introduction to Linux as edX. The study page has a menu with 14px font size, and the actual content has 12px font size. I would like to reduce the font size of menu so that it takes less space. Simply making the div thinner is not a solution , it needs a smaller font size.
What CSS rule could I add to the menu's top-most div to affect all child divs' font sizes? I tried style="font-size:0.5em", style="font-size:50%", and style="font-size:8px" however none of these were able to overcome the CSS defined for the inner divs.
I stress that this question pertains to a website that I do not control, rather, I am trying to add a rule using the Firefox Inspect Element feature.
Not very pretty, but
.menu * { font-size: 11px !important; }
could be what you are looking for. Or,
.menu { transform: scale(0.8); }
although that could affect other things in undesirable ways.
You could also try using the non-standard:
.menu { zoom: 80%; }
Setting a font size of 0.5em on the parent element only works if the children also use em units. On the page in question, it seems that other units are used (px, probably). In this case, you can use the font-size-adjust property on the parent element to reduce the font size of all children. font-size-adjust is normally used to define the font size in terms of "x-height", so you should try values around 0.5.
Edit: As #Jackson pointed out, font-size-adjust only works on Firefox, but maybe that's good enough for you.
Ok. Here is the thing. Like we can use width:100% of an element and it'll take the full width of its container. How can we do that in case of fonts?
I have tried using 100% or em etc but that's not working.
Let me explain the actual problem. Here are three versions of a div. Please see the images.
1- Desktop
2- Android
3- iPhone
You can see that the text "Quote and Buy Online" is in the same line for Desktop and Android (which is the requirement) while it is in two lines in iPhone. Whereas the font-size is the same for all three. Now, that's the problem.
One way is that I reduce the size of the font until the problem gets solved for iPhone but it would then be much smaller for Desktop and Android.
If somehow, I tell the font to adjust its size according to its containing div then the problem will be solved.
Please note that I have checked the solution here but It says it won't be dynamic. So looking for a better alternative.
Here is the link where you can find the form.
This is not possible with pure CSS. You have 4 options:
1) Define the font size for certain breakpoints, to fill up as much as the container as possible, cross browser/platform.
2) Use Viewport Percentage Units: vw as described in this SO answer
3) Use a JS library to fill the text of the parent container, eg:
BigText
FitText
4) Apply a font size that fits the container well, maybe tweak it after 600px +; and live with the fact the font won't fit exactly 100% of the container.
I recommend no.4 for your specific requirment - there will be no JS dependancy, it's simplest to apply and it won't make that much of a difference for your requirement. Maybe the form would look better if you align the text to the left as well. I think no1 and 2 are a bit of an overkill.
You may want to look at using media queries to hit this across the device spectrum. One for iPhone portrait is below, but you will likely have a few to align for all devices.
#media screen and (max-width: 320px) {
.selector { font-size: 10px; }
}
.selector = your class or id of the button or any other html selector or tag.
I personally would go with a screen based fixed figure as you know it is going to render exactly over a scaling method. my 2c worth.
Further Reading: http://css-tricks.com/css-media-queries/
The last days I dealt with units in responsive webdesign and webdesign in general. My question is about units for sizes in CSS at all, meaning not only related to font-size, but also padding, width, media queries, ...
It seems as px is considered pretty for most use cases bad by most professional web designers.
Everyone against px
Some articles that let me come to this assumption
http://css-tricks.com/why-ems/
http://webdesign.about.com/cs/typemeasurements/a/aa042803a.htm
http://blog.cloudfour.com/the-ems-have-it-proportional-media-queries-ftw/
Here an article that has also an opinion pro px:
Should I use px or rem value units in my CSS?
Reasons against px / for (r)em?
media queries
The big advantage of em media queries is, following many articles, that these media queries are even applied when using the browser's text-only zoom.
However I think all modern browsers support full-page zoom, which also applies media queries defined in pixels (tested in up-to-date Firefox and IE).
accessibility
em (or rem) seems to be recommended for font-size (accessibility) but what is about the other sizes?
Increased accessibility is IMHO no important reason anymore, because modern browsers support full-page zoom. I have no idea about screenreaders, but I can't imagine, that they haven't been improved in the last years.
maintainability
It is easy to change the size of the complete site by changing the base size.
If it is a persistent change for every device it should be very easy when using a CSS preprocessor.
The only reason I could find was in the css-tricks.com article, because you may want to have all sizes changed on mobile devices. Do you really want this for all / most elements?
For some cases like really big headings it seems to be useful, but why should a mobile user be able to read smaller text better than a desktop user? Additionally the measuring in reference pixels compensates the different DPIs.
Real life examples
I have roughly analyzed their source code, probably I have overlooked some things.
Bootstrap 3
In most places px is used: font-size, media queries, padding, margin ...
The grid system uses percents at least for widths.
However you can find many issues regarding this topic at Github. Many people demand em / rem.
ZURB Foundation 5
It is based on rem and em and in little cases it uses px, but just for borders etc.
cloudfour.com
Media queries and font-size in em and a mix of different units for everything else: px, %, em.
css-tricks.com
font-size, padding, margin mostly in px, but media queries in em and some widths in %.
So far I have read everywhere, that you should use relative sizes and have done so. If there are sensible reasons for (and I thinks so, because many professionals do so) I will continue / improve doing so, but it was more complicated than using px.
If you assume most people are using full-page zoom, where is the problem with px for everything, having one consistent unit seems to be nice?
(Supporting people, who haven't upgraded their browser / device for almost 10 years (IE <= 7), is not my aim.)
Which is the way to go? (Please consider the different properties font-size, width, media queries, ...)
TL;DR:
Use % for horizontal page layout
em works great for vertical spacing
Use anything you prefer for font-size (I like em)
Use em for media queries
CSS Measurement Units
I find that my usage of different CSS measurement units varies with the area of measurement I'm dealing with: horizontal, vertical, typography, or media query.
Horizontal measurements
The horizontal space gives structure to the page. Thus, horizontal measurements work well with units relative to the page width (%). For example, it's great for giving some basic breathing room to the main content:
#main {
width: 90%;
margin: 0 auto;
}
More complex layouts (columns, for example) also work well when one or all of the horizontal measurements are proportional to the page or to their container.
.column-main {
width: 61.8%; /* The golden ratio is pretty awesome. */
}
.column-secondary {
width: 38.2%;
}
There's a corollary to this idea, which is that if you set up your container structure well, you won't have to do much horizontal sizing on the contents. You basically let the block-level elements fill the width of their container, as they like to do, and you're all set.
Vertical measurements
Vertical space is more about the structure of the content (i.e. how close elements in the document flow are to one another), and I think these measurements work fine with both fixed and relative units (px or em).
However, using relative units here helps give you a vertical rhythm, which can be very pleasing. It also allows you to make changes to your content (read: font-size) and keep your vertical spacing proportional.
p, ul, ol, dl {
margin: 0 1em; /* gives you proportional spacing above and below,
no matter the font size */
}
Typographic measurements
Font measurements fall into their own category, maybe because font-size acts as the base for all other measurements in em. I've seen advocates for different strategies, but from what I've seen any measurement will work fine, as long as you know what you're doing.
px
Setting font-size in px is extremely reliable and easy to calculate. In the post-IE6 age, it also scales nicely, so there's really no reason not to use px if that's what you prefer.
The only problem I see in using px is that it doesn't take advantage of the CSS cascade. In other words, once I've specified sizes in px, I have to go back and change each one of them individually if I want to make any large-scale changes.
em
Despite any drawbacks, I think em can be a really good way to specify font-size. What I like is that it lets me quickly see the relationship between my font sizes. A lot of times I don't care what the exact size of the font is because the most important thing for me is the relationship of that size to all of the other sizes on the page.
The important thing about using em is to set the sizes as close to the end tag as possible. That means I avoid setting font units on containers:
aside { font-size: 0.8em; } /* This can mess me up */
...
aside p { font-size: 0.8em; } /* Way too small! */
And mostly set sizes on headings and text items:
h1 { font-size: 2.5em; }
h2 { font-size: 2.1em; }
h3 { font-size: 1.7em; }
...
Anyway, I like that I can see clearly and easily the relationship between the sizes there.
rem
Sizing things based on the browser's base font size seems like the web-standards thing to do, because then you allow for browsers whose optimal base font size might not be 16px. In practice, though, it kind of works the other way. From what I've seen, browsers use 16px as the base font size because that's what everyone expects, and set the actual size of that CSS measurement to look decent in the browser.
The biggest drawback here I see is browser support. If you code for browsers that don't support rem, you'll be adding your rules twice:
p {
font-size: 16px;
font-size: 1rem; /* I kind of hate repeating myself here,
but a good CSS preprocessor might ease that pain. */
}
Font Spacing
Other font measurements are a lot easier to figure out once you've got your font-size since most other font measurements fall into the category of either vertical or horizontal measure. For example:
h1 {
font-size: 2.5em; /* Change this, and everything below stays proportional.
(Use whatever measurement unit you prefer.) */
margin-top: 0.618em;
margin-bottom: 0.3em;
line-height: 1.2; /* The only unit-less measure in CSS */
}
Media queries
In most cases, there is little difference between the way browsers handle em and px in media queries. This holds true even when a user uses text zoom to resize the page.
HOWEVER, if someone has changed the default text size in their browser settings, things behave very differently. See my answer to a related question and my codepen demo for a longer explanation.
In short, while px works well for media queries in most cases, it's definitely safer to go with em.
Other cases
There are certainly cases where the above general comments don't apply. For example, you may find that ems come in handy any time you want things proportional to the font size, like the following:
h1.title {
font-size: 2em;
width: 20em; /* Resizing the font also resizes its container properly. */
background-color: #d00d1e;
}
#media (min-width: 400px) {
h1 {
font-size: 2.5em; /* Woot! Didn't have to touch the width! */
}
}
Or maybe you want to constrain line lengths for readability:
p {
max-width: 42em;
}
Also, as mentioned in other comments, px still works well for borders and things like that. It can also be good for padding, especially when you pair it with box-sizing:
.example {
width: 80%;
box-sizing: border-box; /* Padding is NOT added to total width. Huzzah! */
padding: 10px;
}
There is already a great answer for this question: Should I use PX or REM?
But to add to that, the articles you link to for "All against px" are generally based on misunderstandings or mis-assumptions.
For example, PX are relative (see the other answer). From an accessibility point of view (my area of exertise), zoom is now the default method of making things bigger/smaller, so PX vs EM is irrelevant. (The browser renders to CSS pixels in both cases.)
Also (for the Cloudfour article) Webkit used to have a bug, but it fixed that a while ago (pre split with blink) so that PX now trigger media queries on zoom.
Basically, whatever you use is translated to (CSS) pixels anyway, so it is up to you.
Personally, I set a based size in PX (generally 16px) and then size in REM. That means it is easy to set the sizes relative to the base, including padding/margin etc. Then you can easily change the base pixels within different media queries. You can also provide PX fallbacks for older browsers if needed.
I have personally made the switch EMs and haven't had any issues with it. It works great for anything you'd normally put pixels in. There are only a few scenarios where I use px still and that is for borders and shadows and other things I don't want growing/shrinking with the font size.
Since EMs are somewhat of a dynamically calculated PX size they work well in the situations where you "know" your size. A great tool for converting PX to EM (or vice versa)
http://pxtoem.com/
I do use % for fluid elements rather than define a specific grid system which has worked well for my own needs. But I haven't tried that approach while also using third-party grid/responsive frameworks. So mileage may vary there.
I recall it was long ago best practice to hardcode width and height for any image (generally so it allocated appropriate amount of space while loading), but now with most people on high speed and things generally more dynamic, what is the best practice for this? Is it still preferred that any content image have inline size set with html?
It doesn't matter if you set the size using HTML attributes or in a stylesheet, but you should still specify the size for images.
Eventhough images are loaded a lot faster nowadays, there is still a noticable delay between the page being displayed and the images pop up. It's still irritating when the layout of a page changes while the images are loading.
Yes, it is still preferred.
Plenty of people are not on high speed connections, and mobile is becoming more common.
It doesn't have to be inline - you can do it in external CSS. Some older browsers, if you don't specify the size, will just treat it as 0px;
Its always best to use CSS
You could hardcode the image height and width like this
.myimg img {
width: 10px;
height: 10px;
}
your image file itself should be the size you want it to display as, for the most part, if your concerned about slow loading especially! if you've got a 500X800 px image, that you only want to show as 100X200, scale it down! the file size will be much smaller so it will load faster :)
I would say yes if you want to make sure the white space is included in case of the image does not load or during document load. But no if you're scaling/resizing the image with those attributes, as its unnecessary load on the browser and causes image distortion.
If you are designing for cross browser compatibility, then you should at the very least specify the height and width in your CSS for the image itself. I have found inconsistency between FireFox, IE, Opera, etc if sizes are not specified specifically for the image. Due to the fact that each browser, not to mention different versions, handle adherence to HTML Standards differently. I have found that some browsers will do its best to extrapolate the HTML designers intent, while others just croak on the first error. I would also recommend em sizes, rather than pixel or %'s if you intend for the website to be viewed from a mobile device such as a tablet. I will say, however I have just started playing with HTML5 so I don't of the difference in HTML5 with respect to images.
I just answered a similar question on Wordpress Stack Exchange and also on Webmaster Stack. I am posting it here intending to clarify and help more people. (admins/moderators: if this isn't allowed, let me know the proper way to help).
doesn't really means you need to specify width and height in the html. What it means is that is you gotta reserve te proper space and when the image is loaded, the browser doens't have to reflow and repaint the page.
Besides, if you hardcode the dimensions, it kinds of defeats responsive behaviour. If your layout is not responsive, it's ok, but if you want to keep some responsiveness, you could use only CSS to achieve the results.
Most of time, using both width and max-width:100 will do the work, but this post from Smashing Magazine has an interesting technique: instead of using max-width:100%, you can use The Padding-Bottom Hack :
"With the technique, we define the height as a measure relative to the width. Padding and margin have such intrinsic properties, and we can use them to create aspect ratios for elements that do not have any content in them.
Because padding has this capability, we can set padding-bottom to be relative to the width of an element. If we also set height to be 0, we’ll get what we want. [...]
The next step is to place an image inside the container and make sure it fills up the container. To do this, we need to position the image absolutely inside the container, like so:"
.img-container {
padding-bottom: 56.25%; /* 16:9 ratio */
height: 0;
background-color: black;
}
.img-container img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}