concept browser in category css

appears as: The browser, browser, browsers, browser, A browser
CSS in Depth

This is an excerpt from Manning's book CSS in Depth.

Fundamentally, CSS is about declaring rules: Under various conditions, we want certain things to happen. If this class is added to that element, apply these styles. If element X is a child of element Y, apply those styles. The browser then takes these rules, figures out which ones apply where, and uses them to render the page.

Figure 6.19. Fallback layout for browsers that don’t support grid

With the page loaded, open the browser’s DevTools (Cmd+Option+I on Mac; Ctrl+Shift+I on Windows). In the Elements panel, click the <html> tag to select it. Its associated styles are shown in the Styles panel, including your custom properties (figure 12.9).

Listing 16.7. Applying a grid layout for browsers that support it
@media (min-width: 30em) { .flyin-grid { display: flex; 1 flex-wrap: wrap; margin: 0 5rem; } .flyin-grid__item { flex: 1 1 300px; margin-left: 0.5em; margin-right: 0.5em; max-width: 600px; } @supports (display: grid) { 2 .flyin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); 3 grid-gap: 2em; } .flyin-grid__item { max-width: initial; margin: 0; 4 } } }
Sass and Compass in Action

This is an excerpt from Manning's book Sass and Compass in Action.

Outside of basic brochure sites, who really writes much static HTML anymore? You take your HTML and carve it up for your blog engine, CMS, or application framework to preprocess, mixing markup and dynamic content. These tools give life to your HTML and it’s crazy to imagine the web without them. So why do you still write static stylesheets? You’ll see how the concepts you use in creating static markup, dynamically, can be applied to creating static stylesheets, dynamically. What does it mean to write dynamic stylesheets? It means that when you author Sass stylesheets, you’re no longer limited by how the browser thinks about CSS. With conditional logic, reusable snippets, variables, and various other tools, you can bring your stylesheets to life. Changing a website’s layout and color scheme can be as simple as tweaking a few variables. Of course, though Sass lets you write stylesheets in a dynamic fashion, the output is still 100% pure static CSS. Once you’re working with dynamic stylesheets, you can now listen to that inner voice that keeps shouting Don’t Repeat Yourself.

Another common problem during development and across production deployments is that browsers are lazy; they don’t like to download things. Perhaps it’s tedious for them. So they cache your images and other assets in case they need them later, and they often do. This is great for users; it makes their browsing experience much nicer. But it’s a pain for web developers. If you change an image, those users who have recently downloaded it won’t notice. And it’s a shame, because the new image is clearly much better. To work around this, Compass adds a query parameter to the end of each asset based on its modification time. Your web server will still serve it just fine, but when the query parameter changes, it’ll force the browser to ask for the image again.

This efficiency gain isn’t only the result of doing it just once. When you design directly in the browser, it’s more likely that you’ll express the relationships between design elements clearly and explicitly. During the act of creation, you don’t think, Boy, what this design needs is some #4F9942. You think, I need to de-emphasize this header color. At that instant it’s easier to write adjust-color ($header-color, $saturation: -15%, $lightness: -25%) and then tweak the values a couple times until it looks right to you. But when you’re authoring CSS from a mockup, the easiest thing to do is take out your color picker and copy the end-result value to your stylesheet, thereby losing all the information that was in your head during the design step and making it much harder to change the header color than it should be.

Browsers are full of limitations. From time to time it’s great to push the limits of what’s possible in the browser, but most of the time, you just need to get the job done. Designing in the browser allows you to work within those limitations and embrace them as part of the design process. The way floats work, it’s hard to imagine and emulate how floated elements will respond to browser window resizing. But when you’re designing in the browser, it’s easy to test and see how it’ll work out.

Sure, you might find that it takes a little longer to build your initial design with this approach, but unless you have to throw the whole thing out, it’s likely that designing and prototyping in the browser will yield a higher-quality product, in less time, that is easier to change in the future.