There is a way to override this mobile rendering behavior - viewport, which is inserted into our HTML pages in the form of a tag. But this doesn't help us responsible web developers, who have written small screen layouts into our CSS using media queries and want mobile devices to display those! This is a sensible defensive mechanism - most old school sites that don't have media queries would look terrible when rendered at say, 320px or 480px wide. Instead, they render pages at a higher assumed viewport width (something approaching a laptop screen), and then shrink the result down to fit inside the mobile screen. They don't render web pages at their true viewport width. I'm sure you'll agree that this really isn't what we wanted - why is this happening? In short, mobile browsers lie. If we viewed my example in a mobile browser in its current state, we wouldn't see our nice mobile layout.
![fit image to width of screen blocs app fit image to width of screen blocs app](https://image.slidesharecdn.com/20190121-reactiveprogramming-flutterlondon-190123152754/85/bloc-pattern-practical-use-cases-flutter-london-21jan2019-22-320.jpg)
One last problem to mention for our example app is concerned with mobile browsers and media queries. To achieve this, we applied the Brick CSS to the page using a separate element with a media attribute: What's more relevant to this article is that we didn't want the Brick CSS and JavaScript files being applied to the markup unless we were looking at the mobile app view. For more on using Brick, read Mozilla Brick: ready made UI components. In particular, we used the deck component for the nice transition effect between cards when the buttons are pressed. Let's have a look at the mobile layout, in the below image.īut there are more tricks up our sleeves for this mobile app layout! As mentioned above, we used Mozilla Brick, a collection of ready-rolled mobile UI components, in the making of the mobile app layout. Last, we have used flex: 1 to make the buttons always take up the same proportion of space on the line. All buttons in the app have been set to have a line-height of 2.5, in the default CSS at the top of the stylesheet (check if you don't believe me.) And 6.8 x 2.5 = 17.
![fit image to width of screen blocs app fit image to width of screen blocs app](https://images.viblo.asia/52241cb6-b8dc-43af-bfcf-ec68f46b4b6a.png)
Why? Because the top-margin of the x-cards was set to 17vw earlier on. Next up, the font-size of the buttons is set to 6.8vw. In this last set of rules, we change the display value of the to flex to make it show (it was set to none in the default CSS at the top of the stylesheet, as it wasn't needed for the other views.) We then use absolute positioning and z-index to make it take up no space in the document flow, and sit on top of the x-cards (this is why we gave the x-cards that top-margin earlier). X-card:nth-child(1) video, x-card:nth-child(2) img, x-card:nth-child(3) Read more about responsive design advantages and disadvantages. Also, taking an existing site and adding responsiveness to it, to make it mobile/tablet friendly, can be a lot more effort than just creating a separate mobile site or app, especially if it is a sprawling enterprise site. If the content, layout, and functionality need to change greatly for different devices, it may not be such a good approach. There are disadvantages to this approach as well.
FIT IMAGE TO WIDTH OF SCREEN BLOCS APP CODE
You don't get caught in the situation of having to bring out more new site versions as more new browsers and platforms come out, and adjust code as feature support in existing browsers changes. This is much more reliable, more maintainable, and more future proof. For a discussion on the differences between the two, read Responsive design versus adaptive design. This tends to be termed responsive design or adaptive design, two related but different approaches. It is usually much better to create a single version of your code which doesn't care about what browser or platform is accessing the site, but instead uses feature tests to find out what code features the browser supports or what the values of certain browser features are, and then adjusts the code appropriately. But this is increasingly inefficient: browser sniffing is inherently error prone, and maintaining multiple copies of your code can turn out to be a nightmare.
![fit image to width of screen blocs app fit image to width of screen blocs app](https://m.media-amazon.com/images/I/71SxGysgJWL._AC_SL1500_.jpg)
![fit image to width of screen blocs app fit image to width of screen blocs app](https://forum.blocsapp.com/uploads/db8018/original/2X/9/92ee9cb2f313c37f3de662461fc6413fe134a16c.jpeg)
One approach to this is to create different versions of your site/app for different platforms or browsers and serve them appropriately after detecting which browser or platform is looking at your site. In this article we will discuss the main essential components of responsive design, with some links to further information where necessary.įor Web developers, it is now fairly common to be called upon to create a Web site or app that changes its user interface depending on the browser or device accessing the site to provide an optimized experience.