pe Wipro posts 7.2 per cent rise in Q2 net profit By www.thehindu.com Published On :: Wed, 21 Oct 2015 17:08:35 +0530 Consolidated net profit of India's 3rd largest software services firm is Rs 2,235.4 crore Full Article Business
pe IBM’s Supercomputer helps doctors to fight cancer By www.thehindu.com Published On :: Sun, 07 Aug 2016 23:44:13 +0530 Watson Supercomputer gets hidden insights from 15 million pages of medical content, including more than 200 medical textbooks. The computer combines Artificial Intelligence and analytical software to perform as a question answering machine. Full Article Business
pe Oil at six-month low | Petrol at breakeven, losses continue on diesel By www.thehindu.com Published On :: Thu, 18 Aug 2022 17:27:28 +0530 Brent crude oil was trading at ₹94.91 per barrel on August 18 Full Article Markets
pe Petronet to invest ₹40,000 crore in 5 years By www.thehindu.com Published On :: Sun, 04 Sep 2022 12:38:12 +0530 India's biggest gas importer, Petronet, looking to foray into petrochemicals business Full Article Industry
pe Boeing to open its second largest campus near Devanahalli By www.thehindu.com Published On :: Mon, 30 Jan 2023 21:41:02 +0530 The aeroplane manufacturer says it has invested $200 million to build the campus on 43 acres of land Full Article Bengaluru
pe Tata International appoints Rajeev Singhal as Chief Operating Officer By www.thehindu.com Published On :: Tue, 04 Apr 2023 13:20:45 +0530 He assumed office from April 1, 2023 and will report to Tata International Ltd Managing Director Anand Sen, the company said in a statement Full Article Companies
pe The Competition Commission’s proposed regulations on merger thresholds | Explained By www.thehindu.com Published On :: Sat, 09 Sep 2023 13:10:07 +0530 The Competition Commission of India has proposed certain definite thresholds for mergers as part of the larger regulatory ambit, in line with the amendments to the Competition Act earlier this year. Full Article Industry
pe A perspective on porn By www.thehindubusinessline.com Published On :: Mon, 06 May 2019 21:38:12 +0530 Knee-jerk reactions such as the ban on TikTok signal prejudiced attitudes towards social media and pornography Full Article India File
pe Is the e-way bill system another inspector raj? By www.thehindubusinessline.com Published On :: Mon, 03 Jun 2019 21:35:10 +0530 While there are glitches, the system has smoothened goods movement Full Article India File
pe Unsold inventory in ongoing projects spells a crisis:Gautam Chatterjee By www.thehindubusinessline.com Published On :: Tue, 13 Aug 2019 11:28:33 +0530 Full Article India File
pe A tale of three developers — will the law catch up? By www.thehindubusinessline.com Published On :: Tue, 13 Aug 2019 11:33:22 +0530 Full Article India File
pe ZBNF spells 'amogh' benefits for this farmer By www.thehindubusinessline.com Published On :: Thu, 17 Oct 2019 10:01:26 +0530 But Amog Gurave’s experience shows that wider adoption requires measured steps, not a rapid govt push Full Article India File
pe Advantage BJP in Maharashtra poll, as it usurps cooperative sector reins from Congress-NCP By www.thehindubusinessline.com Published On :: Mon, 21 Oct 2019 09:18:25 +0530 Cooperatives have played a key role in creating a set of socio-economic institutions in the State. Earlier controlled by NCP and Congress, the BJP has co-opted the cooperative sector leadership and given them tickets Full Article National
pe Cramped for justice By www.thehindubusinessline.com Published On :: Tue, 05 Nov 2019 10:06:40 +0530 Full Article India File
pe Fasal Bima, a story of dashed hopes By www.thehindubusinessline.com Published On :: Tue, 19 Nov 2019 08:39:34 +0530 Farmers, reeling under crop losses, feel the Centre’s crop insurance scheme is merely helping insurance firms make profits. Radheshyam Jadhav reports Full Article India File
pe Nearly 40,000 people living in 1 sq km By www.thehindubusinessline.com Published On :: Tue, 10 Mar 2020 10:12:10 +0530 Full Article India File
pe The Delhi riot as it happened By www.thehindubusinessline.com Published On :: Tue, 10 Mar 2020 10:19:03 +0530 Full Article India File
pe ‘Aviation sector’s expectation of govt bailout unrealistic’ By www.thehindubusinessline.com Published On :: Mon, 06 Apr 2020 20:56:29 +0530 Full Article India File
pe How Covid-19 has disrupted shipping operations and seafarers' lives By www.thehindubusinessline.com Published On :: Mon, 13 Jul 2020 21:18:04 +0530 Covid-19 has dealt a cruel blow to over two lakh seafarers and their families, by disrupting shipping operations and schedules. P Manoj reports Full Article India File
pe Exit co-ops, enter farmer producer cooperatives By www.thehindubusinessline.com Published On :: Tue, 11 Aug 2020 16:31:47 +0530 FPOs have emerged as an antidote to the ills of the cooperative sector in Maharashtra. Will they live up to their potential? Full Article India File
pe India goes bananas over export prospects By www.thehindubusinessline.com Published On :: Mon, 07 Sep 2020 22:44:41 +0530 India is the world’s largest producer of bananas, but a minor exporter. The tide is turning in its favour, thanks largely to a global pest attack. Vishwanath Kulkarni reports Full Article India File
pe How policies shape high-performance building standards and climate goals By www.thehindu.com Published On :: Tue, 22 Oct 2024 08:30:00 +0530 Governments are trying to adopt high-performance buildings through policies and financing mechanisms that promote energy efficiency, resource management, and carbon neutrality. India has made significant progress through initiatives under its National Action Plan on Climate Change Full Article Environment
pe Leaders urge world to pay up to save nature as COP16 talks open By www.thehindu.com Published On :: Wed, 23 Oct 2024 14:17:35 +0530 Two years earlier, countries adopted the landmark Kunming-Montreal Global Biodiversity Framework agreement with a list of 23 goals to help halt nature loss by 2030. Full Article Environment
pe India spells out finance needs for biodiversity, conservation By www.thehindu.com Published On :: Fri, 01 Nov 2024 19:26:45 +0530 Indian officials at the convention in Colombia (COP-16) say international finance will be necessary to meet goals Full Article Environment
pe UN COP16 nature summit creates permanent body for Indigenous peoples By www.thehindu.com Published On :: Sat, 02 Nov 2024 11:16:59 +0530 Nearly 200 countries convened in the city of Cali, aiming to implement the 2022 Kunming-Montreal Global Biodiversity Framework agreement Full Article Environment
pe COP16 suspended without agreement on new fund for nature By www.thehindu.com Published On :: Sun, 03 Nov 2024 04:44:56 +0530 COP16 aimed at assessing the progress on the agreement reached in 2022 in Canada to halt biodiversity loss, with more funding for biodiversity protection being a central issue. Full Article Environment
pe Ahead of COP29, rich countries expect private money to fill green funding gap | Analysis By www.thehindu.com Published On :: Mon, 04 Nov 2024 09:54:53 +0530 At the COP16 negotiations in Colombia, countries failed to figure out how they would mobilise $200 billion a year in conservation funding by 2030 Full Article Environment
pe Climate experts worry about Donald Trump’s re-election impact By www.thehindu.com Published On :: Wed, 06 Nov 2024 22:12:58 +0530 Climate experts anxious about American commitment to carbon mitigation efforts, particularly the Trump campaign’s espousal for fracking and distrust of scientific consensus on the impacts of greenhouse gas warming Full Article Environment
pe FM Sitharaman urges India Inc to propel Viksit Bharat By www.thehindubusinessline.com Published On :: Tue, 27 Feb 2024 12:47:14 +0530 BJP’s third term pledges support for space, AI and warehousing; Next-generation reforms agenda to touch all factors of production including digital infrastructure Full Article Economy
pe Gennova Biopharmaceuticals launches a paediatric pack of pegaspargase, to treat rare blood cancer By www.thehindubusinessline.com Published On :: Fri, 08 Mar 2024 20:33:12 +0530 The drug, marketed as Hamsyl – Junior will now be available in a 1500 IU pack, and is priced at ₹Rs 20,970, a company official told businessline Full Article Science
pe India flight tests missile-assisted torpedo release system By www.thehindubusinessline.com Published On :: Wed, 01 May 2024 15:13:10 +0530 The system was launched around 8.30 am from the ground mobile launcher. Full Article Science
pe ‘Reduce delays, expedite R&D’ By www.thehindubusinessline.com Published On :: Wed, 08 May 2024 22:00:05 +0530 ‘The space programme is always a work-in-progress’ Full Article Elections 2024
pe Of diets and weight-loss drugs, India could take a leaf out of Japan’s experience, says author By www.thehindubusinessline.com Published On :: Mon, 13 May 2024 09:04:36 +0530 Obesity has “exploded” around the world, and it’s not because people are lazy or weak-willed - Johann Hari, Author Full Article Science
pe Combating superbugs: How Indian drugmakers can address the global shortfall in antibiotic development By www.thehindubusinessline.com Published On :: Thu, 06 Jun 2024 15:40:53 +0530 Emphasising the importance of expanding access to high-burden regions, the report calls for strategic initiatives to enable the production and distribution of life-saving antibiotics and antifungals Full Article Science
pe Innovative 3D-printed pedestrian bridge installed at IIT-Hyderabad campus By www.thehindubusinessline.com Published On :: Thu, 20 Jun 2024 17:01:35 +0530 The 7.50-meter bridge, developed by a team led by KVL Subramaniam from the Department of Civil Engineering, promises added flexibility in printed forms and efficient structural systems Full Article Science
pe Ant surgeons: Florida carpenter ants perform life-saving amputations By www.thehindubusinessline.com Published On :: Wed, 03 Jul 2024 04:38:16 +0530 The study, led by entomologist Erik Frank from the University of Würzburg, highlights the ants’ sophisticated medical behaviour, with amputations proving highly effective in ensuring survival Full Article Variety
pe First test flight of Gaganyaan is expected in December 2024: ISRO Chairman By www.thehindubusinessline.com Published On :: Fri, 16 Aug 2024 15:34:46 +0530 ‘All the systems for the Gaganyaan rocket - codenamed G1 - will reach SDSC in November this year and the target for the rocket flight is December’ Full Article Science
pe New hope for millions of diabetes patients By www.thehindubusinessline.com Published On :: Sat, 17 Aug 2024 10:54:37 +0530 Potential of zinc oxide nanoparticles to combat diabetic nephropathy uncovered Full Article Science
pe Climate change can hamper wind resources in India, impact renewable energy By www.thehindubusinessline.com Published On :: Mon, 02 Sep 2024 21:07:52 +0530 ‘Visual data suggests wind speeds in key regions of India are gradually declining, which could have significant implications for the wind energy sector’ Full Article Science
pe Europa Clipper: NASA’s billion-dollar mission to explore the potential for life on Jupiter’s Moon By www.thehindubusinessline.com Published On :: Tue, 15 Oct 2024 07:37:34 +0530 Embarking on a 1.8 million-mile journey from Kennedy Space Centre, the spacecraft is set to reach Jupiter in 5 1/2 years, utilising gravity assists from Mars and Earth Full Article Science
pe Tax Query: Tax relief for arrear pension By www.thehindubusinessline.com Published On :: Sat, 02 Nov 2024 19:21:52 +0530 Under Section 89(1) of the Income Tax Act, 1961, you may claim tax relief on arrear pension received from previous years Full Article Personal Finance
pe Copper futures likely to rally, go long By www.thehindubusinessline.com Published On :: Mon, 04 Nov 2024 12:55:39 +0530 The November contract can touch ₹875 Full Article Commodity Calls
pe Weekly Rupee View: Rupee set to witness higher volatility By www.thehindubusinessline.com Published On :: Tue, 05 Nov 2024 17:00:15 +0530 US election and the Fed policy announcement are the key events Full Article Technical Analysis
pe Copper: Can oscillate in a range By www.thehindubusinessline.com Published On :: Mon, 11 Nov 2024 12:07:25 +0530 MCX Copper Futures contract can trade in a range of ₹820-₹865 Full Article Commodity Calls
pe Two options for using custom properties By www.quirksmode.org Published On :: Tue, 04 May 2021 15:16:56 +0100 Recently I interviewed Stefan Judis for my upcoming book. We discussed CSS custom properties, and something interesting happened. We had a period of a few minutes where we were talking past one another, because, as it turns out, we have completely opposite ideas about the use of CSS custom properties. I had never considered his approach, and I found it interesting enough to write this quick post. Option 1 Take several site components, each with their own link and hover/focus colours. We want to use custom properties for those colours. Exactly how do we do that? Before my discussion with Stefan that wasn’t even a question for me. I would do this: .component1 { --linkcolor: red; --hovercolor: blue; } .component2 { --linkcolor: purple; --hovercolor: cyan; } a { color: var(--linkcolor); } a:hover,a:focus { color: var(--hovercolor) } I set the normal and hover/focus colour as a custom property, and leave the definition of those properties to the component the link appears in. The first and second component each define different colours, which are deployed in the correct syntax. Everything works and all’s well with the world. As far as I can see now this is the default way of using CSS custom properties. I wasn’t even aware that another possibility existed. Option 2 Stefan surprised me by doing almost the complete opposite. He uses only a single variable and changes its value where necessary: .component1 { --componentcolor: red; } .component1 :is(a:hover,a:focus) { --componentcolor: blue; } .component2 { --componentcolor: purple; } .component2 :is(a:hover,a:focus) { --componentcolor: cyan; } a { color: var(--componentcolor) } At first I was confused. Why would you do this? What’s the added value of the custom property? Couldn’t you just have entered the colour values in the component styles without using custom properties at all? Well, yes, you could. But that’s not Stefan’s point. The point In practice, component definitions have way more styles than just colours. There’s a bunch of box-model properties, maybe a display, and possibly text styling instructions. In any case, a lot of lines of CSS. If you use custom properties only for those CSS properties that will change you give future CSS developers a much better and quicker insight in how your component works. If the definition uses a custom property that means the property may change in some circumstances. If it uses a fixed definition you know it’s a constant. Suppose you encounter this component definition in a codebase you just inherited: .component { --color: red; --background: blue --layout: flex; --padding: 1em; --borderWidth: 0.3em; display: var(--layout); color: var(--color); background: var(--background); padding: var(--padding); border: var(--borderWidth) solid black; margin: 10px; border-radius: 2em; grid-template-columns: repeat(3,1fr); flex-wrap: wrap; } Now you essentially found a definition file. Not only do you see the component’s default styles, you also see what might change and what will not. For instance, because the margin and border-radius are hard-coded you know they are never changed. In the case of the border, only the width changes, not the style or the colour. Most other properties can change. The use of display: var(--layout) is particularly revealing. Apparently something somewhere changes the component’s layout from grid to flexbox. Also, if it’s a grid it has three equal columns, while if it’s a flexbox it allows wrapping. This suggests that the flexbox layout is used on narrower screens, switching to a grid layout on wider screens. Where does the flexbox change to a grid? As a newbie to this codebase you don’t know, but you can simply search for --layout: grid and you’ll find it, probably neatly tucked away in a media query somewhere. Maybe there is a basic layout as well, which uses neither flexbox nor grid? Search for --layout: block and you’ll know. Thus, this way of using custom properties is excellently suited for making readable code bases that you can turn over to other CSS developers. They immediately know what changes and what doesn’t. Teaching aid? There’s another potential benefit as well: this way of using custom properties, which are essentially variables, aligns much more with JavaScript’s use of variables. You set an important variable at the start of your code, and change it later on if necessary. This is what you do in JavaScript all the time. Thus this option may be better suited to teaching CSS to JavaScripters, which remains one of my preoccupations due to the upcoming book. Picking an option Which option should you pick? That’s partly a matter of personal preference. Since the second option is still fairly new to me, and I rarely work on large projects, I am still feeling my way around it. Right at this moment I prefer the first way because I’m used to it. But that might change, given some extra time. Still, I think Stefan is on to something. I think that his option is very useful in large codebases that can be inherited by other developers. I think it deserves careful consideration. Full Article CSS for JavaScripters
pe aspect-ratio and grid By www.quirksmode.org Published On :: Tue, 11 May 2021 13:42:23 +0100 I’m currently investigating the new aspect-ratio declaration and plan to write an article about it. However, I got stuck on aspect ratios in a grid context. Chrome/Safari and Firefox do something different here, and I understand neither approach. So I hope I can get some help. aspect-ratio is currently supported by Chrome 90, by Firefox 88 with the correct flag enabled, and by Safari Technology Preview. I tested mostly in the first two — for complicated reasons I cannot install STP right now, but a kind Twitter follower sent me a few screenshots. It behaves as Chrome. First, a general remark. aspect-ratio is intentionally a fairly weak declaration. It gives way if other constraints on boxes make the requested aspect ratio impossible. Take this example: .my-box { width: 100px; height: 50px; aspect-ratio: 16/9; } The box has a fixed width and height, and they overrule the aspect-ratio. The box will thus have a 2/1 aspect ratio, as dictated by its width and height, and not a 16/9 one. Flexbox With that in mind, let’s first look at aspect-ratio in a flexbox environment. I think I understand what’s going on here, and the browsers all do the same, so this is a good reference point for the grid problems we’ll encounter later. Flex items take their width from the flexbox environment. In my example they have a flex-basis: 30%, but they could also have a width or even no width/flex-basis definition at all. In all cases the flexbox algorithm decides on the width of each item. Once the width has been determined, it’s time for the height. Let’s assume it’s not set. In flexbox, height: auto means not “as high as you need to be for your content” but “as high as the highest box in your row.” That is, naturally flexbox would give the boxes an equal width (because that’s what my flex declarations say) and an equal height (because that always happens in flexbox). Apparently, this counts as a set height for the aspect-ratio algorithm. As a result the 16/9 value is ignored because the 4/3 results in a larger height, and this value is therefore the one that determines the height of the entire row. As you see, the third box in this example does have the correct aspect ratio. That’s because it has an explicit height: min-content: set your height to whatever your content needs, and, more importantly, ignore the row height of the flex box. This, apparently, gives the aspect ratio algorithm the opening it needs to set the height to the one requested by the aspect-ratio: 16/9. I’m not sure if my reasoning is right. I am very certain that this works in all browsers, though, so you can use height: min-content in production straight away. (max-content also works. There’s no real difference between the two in height declarations.) flex aspect-ratio and min-content The problem: grid Now we get to the problem: grid. To follow along, please look at the example below in Firefox 88 with the aspect-ratio flag on, and in either Chrome or Safari Technology Preview. I expected grid to more or less behave the same as flexbox: the widths are set by the grid, the heights by the row height, and getting the proper aspect ratio would require height: min-content. That last clause is correct: the min-content trick works as it does in flexbox. It’s the behaviour of th 16/9 box without min-content that surprises me. Here, again, the third box has height: min-content and takes the correct aspect ratio, which means not obeying the row height, in all browsers. grid aspect-ratio and min-content Firefox first. All boxes get their correct aspect ratio and they all have the same width, as the repeat: (3,1fr) grid template dictates. That means their height differs. More importantly, the grid container box now becomes only as high as is necessary to contain the items as they would have been without their aspect ratio. I am 99% certain that the grid container behaviour is a bug. I am less certain whether the aspect-ratio being obeyed is also a bug. In Chrome, the second and third box behave as expected: the last box becomes less high than the row height because of height: min-content, and the second box dictates the row height with its 4/3 aspect ratio. But what’s up with the first box? It appears that it takes the row height as a given, but then sets the width to the value dictated by the 16/9 aspect ratio, ignoring the fact that this box now overflows its proper grid placement. Is this a bug? Or does height count for more than width in a grid context? I don’t know. In the second example all grid items have min-height: 100px. In all browsers they they calculate their width from their aspect ratio. Thus they break the grid-defined widths. This is understandable, given that the explicit height declaration is “stronger” than the implied widths from the grid definition. (Or rather: I devoutly hope I’m right here and not talking nonsense.) grid aspect-ratio and min-height: 100px; Thus maybe Firefox on the one hand and Chrome/Safari on the other are not as far apart as one would think from the first grid example. Still, something is buggy in that example. I just can’t figure out what it is. Stumped. Please help. Full Article CSS for JavaScripters pe aspect-ratio By www.quirksmode.org Published On :: Wed, 19 May 2021 11:35:27 +0100 This week we’ll take a look at the new aspect-ratio declaration and its use. Una Kravets wrote the introductory article, but there are some additional technical points to be made. I also wrote a little fallback that you might use if you need aspect-ratio right now. At the time of writing aspect-ratio is supported by Chrome 90, by Safari Technology Preview, and by Firefox 88 if you set the aspect-ratio flag in about:config. You need one of these browsers to see the examples below — except for the fallback, which should work in all browsers that support custom properties. Weak declaration aspect-ratio defines the ratio between the width and height of a box, but it is a weak declaration. If the box has a specified width and height the browser uses those values and ignores the aspect ratio. Width and height might be specified by explicit width and height declarations or by other means, as we’ll see below. aspect-ratio In this example all three boxes have aspect-ratio: 16/9. The first box has width: auto; height: auto; i.e. as much width as you can take, and as little height as you need. aspect-ratio takes the width, converts it to pixels, and applies the defined aspect ratio to calculate the height. The second box has a height: 50px; width: auto. The height is strong, but the auto width is weak and allows aspect-ratio to override it. Thus the box’s width is calculated by taking the height and applying the aspect ratio. The third box has a fixed width: 150px; height: 100px as well as an aspect-ratio: 16/9. Now both width and height are strong and the aspect ratio is ignored. Rounding Even if aspect-ratio works fine the browser must find an integer number of device pixels for the box’s width and height. Fractions are discarded somewhere along the way. That’s why the calculated aspect ratio of a box is rarely 100% exact. In the examples you’ll often see a narrow stripe of red poking from underneath the background image. That image has the same aspect ratio as the box it appears in, but apparently uses a different calculation. In normal circumstances these tiny differences are not visible to the naked eye, so you can safely ignore them. Fat red stripes, such as in the last box in the first example, are a sign of trouble, though. min- and max-width and -height grid aspect-ratio and min- and max-height You can set a min/max-width/height on the boxes. These are obeyed as normal, and aspect-ratio is obeyed as well. In this example the first box has a min-height: 100px, the second a max-height: 50px, and the third min-width: 100px. As you see they stretch up or down to their defined maximum and minimum and retain their aspect-ratio. box-sizing: border-box! Now we come to a trickier topic unearthed originally by Ana Tudor — and this entire article is a good read that I recommend. If it works, aspect-ratio sets either the width or the height of a box to match the other side and the defined aspect ratio. However, the exact effect depends on how width and height are defined; on box-sizing, in other words. width may mean either the content width, without padding and border (box-sizing: content-box; the default), or the width of content + padding + border (box-sizing: border-box). In general, the latter is what we want. aspect-ratio and box-sizing In the next example the boxes have padding: 10%. Percentual padding is always calculated relative to the width of the parent element. Thus this box has a padding of 10% of its parent element’s width, even at the top and the bottom. Since the padding is equal on all four sides, it may break the box’s aspect ratio. This depends on box-sizing. If you use the default box-sizing: content-box the width and height have the correct aspect ratio, but they define only the content area. An equal amoung of padding is added on all sides, and the aspect ratio is destroyed. This problem is easy to solve: set box-sizing: border-box. Now width and height define the content, padding, and border combined, and this entire area is given the correct aspect ratio. Thus the padding is seamlessly integrated with the proper aspect ratio. In fact, you should always set box-sizing: border-box in all your sites. content-box was a mistake, as W3C itself admitted (and as I said back in 2002). The fact that it fixes aspect-ratio merely gives us an extra reason to do so. aapect-ratio in flexbox In a flex or grid context, aspect-ratio can appear not to work. In fact, running into these problems was what caused me to write this article in the first place. Look at the example below. It doesn’t work! Oh noesies! What’s going on? flex aspect-ratio What happens here is default flexbox behaviour. First the widths of the items are calculated (here from flex-basis: 30%; grow: 1), and once that’s done the height of all items is set. These heights are calculated by applying their aspect ratio, but the tallest box is used to set the height of all items in the row. In our example that is the 1/1 box, so the 16/9 and 4/3 boxes also have an aspect ratio of 1/1. This default behaviour is ruled by align-items: stretch, which is part of the flexbox default. If you use any other value the boxes’ height is set to auto and they take their proper aspect ratio. flex-start is the most obvious choice, but see CSS Tricks’ great flexbox guide for more options. flex aspect-ratio and align-items If for some reason you want to overrule the height stretch on only a single item you can give that item either align-self: flex-start or any other value, or height: min-content. Both work fine. The third box in the next example has height: min-content. flex aspect-ratio and height: min-content aspect-ratio and grid In a grid context aspect-ratio encounters the same problems as in a flexbox environment, only with added browser bugs that I wrote about last week. I expected the same behaviour as in a flexbox context, but that’s not entirely what’s happening. The good news is that align-items, align-self, and height: min-content all work exactly as with flexbox. They negate the default grid behaviour of stretching the height of all elements in a row to the height of the highest element. grid aspect-ratio and align-items The problems are in the default rendering of aspect-ratio. Chrome and Safari implement this in one incorrect way, and Firefox is a quite different, equally incorrect way. If all boxes in the example below have the same width and height the bugs have been solved. They get the same height for the reasons I explained under flexbox — grid works the same in this respect (I hope). grid aspect-ratio with browser bugs Firefox obeys the aspect-ratio while I think it shouldn’t. Instead, like in the flexbox example, it should stretch the boxes to the height of the highest in the row. In addition it calculates the height of the entire grid by assuming its items have the minimum height needed for their content — and since my example boxes do not have any content that height is 0. Thus the grid container is way too small. Both are clearly bugs that will probably be fixed soon. Chrome and Safari TP size the grid container correctly, but seem to take the height as reference and size the width accordingly instead of taking the width as reference and sizing the height. Thus the 16/9 and 4/3 items become way too wide. I think this is also a bug — if it isn’t someone will have to carefully explain to me what’s going on. Fortunately this bug goes away if you use align-items — which you’re going to want to do in any case. A fallback (After writing this fallback I found that Ana Tudor wrote pretty much the same one in her article. I mean, why do I even bother competing with scarily smart people like her? But I came by it independently, honest.) 5/1 3/1 16/9 4/3 9/16 Since browser support isn’t quite there yet we need to continue to use the old padding-top trick as a fallback, as I do in this paragraph. It is supposed to have an aspect ratio even in browsers that do not support aspect-ratio. The core of the fallback is the following CSS. Fair warning: this solution is only lightly tested; I went from conception to successful execution in about 30 minutes — though I spent 90 more minutes on a custom property issue. The extra <span> is ugly, but I don’t see a way around it. If your aspect-ratioed boxes do not contain text you can leave it out. <p class="test"><span>The text</span></p> p.test { --aspectRatio: 16/9; --padding: 0.5em; border: 1px solid; padding: var(--padding); aspect-ratio: var(--aspectRatio); box-sizing: border-box; } @supports not (aspect-ratio: 16/9) { p.test { padding: 0; padding-top: calc((1 / (var(--aspectRatio)))*100%); position: relative; } p.test > span { display: block; position: absolute; top: var(--padding); left: var(--padding); } } Store the desired aspect ratio in --aspectRatio. Set aspect-ratio to that value. If the browser doesn’t support aspect-ratio, set the padding-top to 1 / the aspect ratio as a percentage. The script that runs in this page changes the value of --aspectRatio. The trick here is that percentual padding is calculated relative to the parent element’s width. If the box spans its parent’s entire width, you can take that width, multiply it by 1 divided by the aspect ratio (so for instance 9/16th when the aspect ratio is 16/9) and convert the result to a percentage. Now the padding stretches the box to the desired aspect ratio. If the box has any real content we have to wrap it in an extra HTML element and give that element position: absolute so that it does not influence the box’s height. Then we place it in the box, with a top and left coordinate equal to the box’s padding. Now the text appears to flow naturally. You don’t need this trick if the box only has a background image or gradient; those ignore padding anyway. Or you can wait a few months until all browsers support aspect-ratio. It won’t be long now. I may write a separate article about the incredible number of brackets we need in the padding-top line. Full Article CSS for JavaScripters pe Custom properties and @property By www.quirksmode.org Published On :: Wed, 21 Jul 2021 14:18:40 +0100 You’re reading a failed article. I hoped to write about @property and how it is useful for extending CSS inheritance considerably in many different circumstances. Alas, I failed. @property turns out to be very useful for font sizes, but does not even approach the general applicability I hoped for. Grandparent-inheriting It all started when I commented on what I thought was an interesting but theoretical idea by Lea Verou: what if elements could inherit the font size of not their parent, but their grandparent? Something like this: div.grandparent { /* font-size could be anything */ } div.parent { font-size: 0.4em; } div.child { font-size: [inherit from grandparent in some sort of way]; font-size: [yes, you could do 2.5em to restore the grandparent's font size]; font-size: [but that's not inheriting, it's just reversing a calculation]; font-size: [and it will not work if the parent's font size is also unknown]; } Lea told me this wasn’t a vague idea, but something that can be done right now. I was quite surprised — and I assume many of my readers are as well — and asked for more information. So she wrote Inherit ancestor font-size, for fun and profit, where she explained how the new Houdini @property can be used to do this. This was seriously cool. Also, I picked up a few interesting bits about how CSS custom properties and Houdini @property work. I decided to explain these tricky bits in simple terms — mostly because I know that by writing an explanation I myself will understand them better — and to suggest other possibilities for using Lea’s idea. Alas, that last objective is where I failed. Lea’s idea can only be used for font sizes. That’s an important use case, but I had hoped for more. The reasons why it doesn’t work elsewhere are instructive, though. Tokens and values Let’s consider CSS custom properties. What if we store the grandparent’s font size in a custom property and use that in the child? div.grandparent { /* font-size could be anything */ --myFontSize: 1em; } div.parent { font-size: 0.4em; } div.child { font-size: var(--myFontSize); /* hey, that's the grandparent's font size, isn't it? */ } This does not work. The child will have the same font size as the parent, and ignore the grandparent. In order to understand why we need to understand how custom properties work. What does this line of CSS do? --myFontSize: 1em; It sets a custom property that we can use later. Well duh. Sure. But what value does this custom property have? ... errr ... 1em? Nope. The answer is: none. That’s why the code example doesn’t work. When they are defined, custom properties do not have a value or a type. All that you ordered the browsers to do is to store a token in the variable --myFontSize. This took me a while to wrap my head around, so let’s go a bit deeper. What is a token? Let’s briefly switch to JavaScript to explain. let myVar = 10; What’s the value of myVar in this line? I do not mean: what value is stored in the variable myVar, but: what value does the character sequence myVar have in that line of code? And what type? Well, none. Duh. It’s not a variable or value, it’s just a token that the JavaScript engine interprets as “allow me to access and change a specific variable” whenever you type it. CSS custom properties also hold such tokens. They do not have any intrinsic meaning. Instead, they acquire meaning when they are interpreted by the CSS engine in a certain context, just as the myVar token is in the JavaScript example. So the CSS custom property contains the token 1em without any value, without any type, without any meaning — as yet. You can use pretty any bunch of characters in a custom property definition. Browsers make no assumptions about their validity or usefulness because they don’t yet know what you want to do with the token. So this, too, is a perfectly fine CSS custom property: --myEgoTrip: ppk; Browsers shrug, create the custom property, and store the indicated token. The fact that ppk is invalid in all CSS contexts is irrelevant: we haven’t tried to use it yet. It’s when you actually use the custom property that values and types are assigned. So let’s use it: background-color: var(--myEgoTrip); Now the CSS parser takes the tokens we defined earlier and replaces the custom property with them: background-color: ppk; And only NOW the tokens are read and intrepreted. In this case that results in an error: ppk is not a valid value for background-color. So the CSS declaration as a whole is invalid and nothing happens — well, technically it gets the unset value, but the net result is the same. The custom property itself is still perfectly valid, though. The same happens in our original code example: div.grandparent { /* font-size could be anything */ --myFontSize: 1em; /* just a token; no value, no meaning */ } div.parent { font-size: 0.4em; } div.child { font-size: var(--myFontSize); /* becomes */ font-size: 1em; /* hey, this is valid CSS! */ /* Right, you obviously want the font size to be the same as the parent's */ /* Sure thing, here you go */ } In div.child he tokens are read and interpreted by the CSS parser. This results in a declaration font-size: 1em;. This is perfectly valid CSS, and the browsers duly note that the font size of this element should be 1em. font-size: 1em is relative. To what? Well, to the parent’s font size, of course. Duh. That’s how CSS font-size works. So now the font size of the child becomes the same as its parent’s, and browsers will proudly display the child element’s text in the same font size as the parent element’s while ignoring the grandparent. This is not what we wanted to achieve, though. We want the grandparent’s font size. Custom properties — by themselves — don’t do what we want. We have to find another solution. @property Lea’s article explains that other solution. We have to use the Houdini @property rule. @property --myFontSize { syntax: "<length>"; initial-value: 0; inherits: true; } div { border: 1px solid; padding: 1em; } div.grandparent { /* font-size could be anything */ --myFontSize: 1em; } div.parent { font-size: 0.4em; } div.child { font-size: var(--myFontSize); } Now it works. Wut? Yep — though only in Chrome so far. This is the grandparent This is the parent This is the child What black magic is this? Adding the @property rule changes the custom property --myFontSize from a bunch of tokens without meaning to an actual value. Moreover, this value is calculated in the context it is defined in — the grandfather — so that the 1em value now means 100% of the font size of the grandfather. When we use it in the child it still has this value, and therefore the child gets the same font size as the grandfather, which is exactly what we want to achieve. (The variable uses a value from the context it’s defined in, and not the context it’s executed in. If, like me, you have a grounding in basic JavaScript you may hear “closures!” in the back of your mind. While they are not the same, and you shouldn’t take this apparent equivalency too far, this notion still helped me understand. Maybe it’ll help you as well.) Unfortunately I do not quite understand what I’m doing here, though I can assure you the code snippet works in Chrome — and will likely work in the other browsers once they support @property. Misson completed — just don’t ask me how. Syntax You have to get the definition right. You need all three lines in the @property rule. See also the specification and the MDN page. @property --myFontSize { syntax: "<length>"; initial-value: 0; inherits: true; } The syntax property tells browsers what kind of property it is and makes parsing it easier. Here is the list of possible values for syntax, and in 99% of the cases one of these values is what you need. You could also create your own syntax, e.g. syntax: "ppk | <length>" Now the ppk keyword and any sort of length is allowed as a value. Note that percentages are not lengths — one of the many things I found out during the writing of this article. Still, they are so common that a special value for “length that may be a percentage or may be calculated using percentages” was created: syntax: "<length-percentage>" Finally, one special case you need to know about is this one: syntax: "*" MDN calls this a universal selector, but it isn’t, really. Instead, it means “I don’t know what syntax we’re going to use” and it tells browsers not to attempt to interpret the custom property. In our case that would be counterproductive: we definitely want the 1em to be interpreted. So our example doesn’t work with syntax: "*". initial-value and inherits An initial-value property is required for any syntax value that is not a *. Here that’s simple: just give it an initial value of 0 — or 16px, or any absolute value. The value doesn’t really matter since we’re going to overrule it anyway. Still, a relative value such as 1em is not allowed: browsers don’t know what the 1em would be relative to and reject it as an initial value. Finally, inherits: true specifies that the custom property value can be inherited. We definitely want the computed 1em value to be inherited by the child — that’s the entire point of this experiment. So we carefully set this flag to true. Other use cases So far this article merely rehashed parts of Lea’s. Since I’m not in the habit of rehashing other people’s articles my original plan was to add at least one other use case. Alas, I failed, though Lea was kind enough to explain why each of my ideas fails. Percentage of what? Could we grandfather-inherit percentual margins and paddings? They are relative to the width of the parent of the element you define them on, and I was wondering if it might be useful to send the grandparent’s margin on to the child just like the font size. Something like this: @property --myMargin { syntax: "<length-percentage>"; initial-value: 0; inherits: true; } div.grandparent { --myMargin: 25%; margin-left: var(--myMargin); } div.parent { font-size: 0.4em; } div.child { margin-left: var(--myMargin); /* should now be 25% of the width of the grandfather's parent */ /* but isn't */ } Alas, this does not work. Browsers cannot resolve the 25% in the context of the grandparent, as they did with the 1em, because they don’t know what to do. The most important trick for using percentages in CSS is to always ask yourself: “percentage of WHAT?” That’s exactly what browsers do when they encounter this @property definition. 25% of what? The parent’s font size? Or the parent’s width? (This is the correct answer, but browsers have no way of knowing that.) Or maybe the width of the element itself, for use in background-position? Since browsers cannot figure out what the percentage is relative to they do nothing: the custom property gets the initial value of 0 and the grandfather-inheritance fails. Colours Another idea I had was using this trick for the grandfather’s text colour. What if we store currentColor, which always has the value of the element’s text colour, and send it on to the grandchild? Something like this: @property --myColor { syntax: "<color>"; initial-value: black; inherits: true; } div.grandparent { /* color unknown */ --myColor: currentColor; } div.parent { color: red; } div.child { color: var(--myColor); /* should now have the same color as the grandfather */ /* but doesn't */ } Alas, this does not work either. When the @property blocks are evaluated, and 1em is calculated, currentColor specifically is not touched because it is used as an initial (default) value for some inherited SVG and CSS properties such as fill. Unfortunately I do not fully understand what’s going on, but Tab says this behaviour is necessary, so it is. Pity, but such is life. Especially when you’re working with new CSS functionalities. Conclusion So I tried to find more possbilities for using Lea’s trick, but failed. Relative units are fairly sparse, especially when you leave percentages out of the equation. em and related units such as rem are the only ones, as far as I can see. So we’re left with a very useful trick for font sizes. You should use it when you need it (bearing in mind that right now it’s only supported in Chromium-based browsers), but extending it to other declarations is not possible at the moment. Many thanks to Lea Verou and Tab Atkins for reviewing and correcting an earlier draft of this article. Full Article CSS for JavaScripters pe Ruhani Sharma: I play a close-to-reality cop in ‘HER’; there is no scope for ‘Singham’ style of histrionics By www.thehindu.com Published On :: Tue, 18 Jul 2023 19:06:24 +0530 Ruhani Sharma talks about headlining the Telugu cop drama franchise ‘HER’, says she never imagined herself as a sharpshooter Full Article Movies pe Director Sai Rajesh: ‘Baby’ has been a learning experience; henceforth I will be more cautious in my writing By www.thehindu.com Published On :: Wed, 19 Jul 2023 16:16:44 +0530 Sai Rajesh, the writer-director of the Telugu romantic drama ‘Baby’ that has been eliciting extreme responses, says he did not intend to make a toxic film Full Article Movies «1..2..195493 494 495..581..774..967..1160..1353..1546..17391922» Recent Trending The Finish Line: Types of EIFS The Finish Line: Foam Shapes Revisited The Finish Line: Inspecting Eifs The Finish Line: EIFS Inspection The Greenest Low Slope Roofing Solution Only 12 per cent of leading charities publicly recognise a trade union, analysis suggests Ultrabond ECO 885 Premium Grade Polyolefin Backed Carpet Adhesive The First Sealer to Give a Beautiful, Luxurious Appearance Cooperativa Ceramica d'Imola North America Debuts 5 New Programs BOLYU unveils the new String of Pearls Collection Propex to Showcase Isis Modular Tile Backing at FloorTek Expo 24 hours in Copenhagen The Carpet and Rug Institute Presents the 2024 Joseph J.Smrekar Memorial Award TISE 2025 Opens Entries for Best of Awards Carpet Industry Leaders Navigate Global Growth, Sustainability Policies at CRI Annual Meeting Subscribe To Our Newsletter
pe aspect-ratio By www.quirksmode.org Published On :: Wed, 19 May 2021 11:35:27 +0100 This week we’ll take a look at the new aspect-ratio declaration and its use. Una Kravets wrote the introductory article, but there are some additional technical points to be made. I also wrote a little fallback that you might use if you need aspect-ratio right now. At the time of writing aspect-ratio is supported by Chrome 90, by Safari Technology Preview, and by Firefox 88 if you set the aspect-ratio flag in about:config. You need one of these browsers to see the examples below — except for the fallback, which should work in all browsers that support custom properties. Weak declaration aspect-ratio defines the ratio between the width and height of a box, but it is a weak declaration. If the box has a specified width and height the browser uses those values and ignores the aspect ratio. Width and height might be specified by explicit width and height declarations or by other means, as we’ll see below. aspect-ratio In this example all three boxes have aspect-ratio: 16/9. The first box has width: auto; height: auto; i.e. as much width as you can take, and as little height as you need. aspect-ratio takes the width, converts it to pixels, and applies the defined aspect ratio to calculate the height. The second box has a height: 50px; width: auto. The height is strong, but the auto width is weak and allows aspect-ratio to override it. Thus the box’s width is calculated by taking the height and applying the aspect ratio. The third box has a fixed width: 150px; height: 100px as well as an aspect-ratio: 16/9. Now both width and height are strong and the aspect ratio is ignored. Rounding Even if aspect-ratio works fine the browser must find an integer number of device pixels for the box’s width and height. Fractions are discarded somewhere along the way. That’s why the calculated aspect ratio of a box is rarely 100% exact. In the examples you’ll often see a narrow stripe of red poking from underneath the background image. That image has the same aspect ratio as the box it appears in, but apparently uses a different calculation. In normal circumstances these tiny differences are not visible to the naked eye, so you can safely ignore them. Fat red stripes, such as in the last box in the first example, are a sign of trouble, though. min- and max-width and -height grid aspect-ratio and min- and max-height You can set a min/max-width/height on the boxes. These are obeyed as normal, and aspect-ratio is obeyed as well. In this example the first box has a min-height: 100px, the second a max-height: 50px, and the third min-width: 100px. As you see they stretch up or down to their defined maximum and minimum and retain their aspect-ratio. box-sizing: border-box! Now we come to a trickier topic unearthed originally by Ana Tudor — and this entire article is a good read that I recommend. If it works, aspect-ratio sets either the width or the height of a box to match the other side and the defined aspect ratio. However, the exact effect depends on how width and height are defined; on box-sizing, in other words. width may mean either the content width, without padding and border (box-sizing: content-box; the default), or the width of content + padding + border (box-sizing: border-box). In general, the latter is what we want. aspect-ratio and box-sizing In the next example the boxes have padding: 10%. Percentual padding is always calculated relative to the width of the parent element. Thus this box has a padding of 10% of its parent element’s width, even at the top and the bottom. Since the padding is equal on all four sides, it may break the box’s aspect ratio. This depends on box-sizing. If you use the default box-sizing: content-box the width and height have the correct aspect ratio, but they define only the content area. An equal amoung of padding is added on all sides, and the aspect ratio is destroyed. This problem is easy to solve: set box-sizing: border-box. Now width and height define the content, padding, and border combined, and this entire area is given the correct aspect ratio. Thus the padding is seamlessly integrated with the proper aspect ratio. In fact, you should always set box-sizing: border-box in all your sites. content-box was a mistake, as W3C itself admitted (and as I said back in 2002). The fact that it fixes aspect-ratio merely gives us an extra reason to do so. aapect-ratio in flexbox In a flex or grid context, aspect-ratio can appear not to work. In fact, running into these problems was what caused me to write this article in the first place. Look at the example below. It doesn’t work! Oh noesies! What’s going on? flex aspect-ratio What happens here is default flexbox behaviour. First the widths of the items are calculated (here from flex-basis: 30%; grow: 1), and once that’s done the height of all items is set. These heights are calculated by applying their aspect ratio, but the tallest box is used to set the height of all items in the row. In our example that is the 1/1 box, so the 16/9 and 4/3 boxes also have an aspect ratio of 1/1. This default behaviour is ruled by align-items: stretch, which is part of the flexbox default. If you use any other value the boxes’ height is set to auto and they take their proper aspect ratio. flex-start is the most obvious choice, but see CSS Tricks’ great flexbox guide for more options. flex aspect-ratio and align-items If for some reason you want to overrule the height stretch on only a single item you can give that item either align-self: flex-start or any other value, or height: min-content. Both work fine. The third box in the next example has height: min-content. flex aspect-ratio and height: min-content aspect-ratio and grid In a grid context aspect-ratio encounters the same problems as in a flexbox environment, only with added browser bugs that I wrote about last week. I expected the same behaviour as in a flexbox context, but that’s not entirely what’s happening. The good news is that align-items, align-self, and height: min-content all work exactly as with flexbox. They negate the default grid behaviour of stretching the height of all elements in a row to the height of the highest element. grid aspect-ratio and align-items The problems are in the default rendering of aspect-ratio. Chrome and Safari implement this in one incorrect way, and Firefox is a quite different, equally incorrect way. If all boxes in the example below have the same width and height the bugs have been solved. They get the same height for the reasons I explained under flexbox — grid works the same in this respect (I hope). grid aspect-ratio with browser bugs Firefox obeys the aspect-ratio while I think it shouldn’t. Instead, like in the flexbox example, it should stretch the boxes to the height of the highest in the row. In addition it calculates the height of the entire grid by assuming its items have the minimum height needed for their content — and since my example boxes do not have any content that height is 0. Thus the grid container is way too small. Both are clearly bugs that will probably be fixed soon. Chrome and Safari TP size the grid container correctly, but seem to take the height as reference and size the width accordingly instead of taking the width as reference and sizing the height. Thus the 16/9 and 4/3 items become way too wide. I think this is also a bug — if it isn’t someone will have to carefully explain to me what’s going on. Fortunately this bug goes away if you use align-items — which you’re going to want to do in any case. A fallback (After writing this fallback I found that Ana Tudor wrote pretty much the same one in her article. I mean, why do I even bother competing with scarily smart people like her? But I came by it independently, honest.) 5/1 3/1 16/9 4/3 9/16 Since browser support isn’t quite there yet we need to continue to use the old padding-top trick as a fallback, as I do in this paragraph. It is supposed to have an aspect ratio even in browsers that do not support aspect-ratio. The core of the fallback is the following CSS. Fair warning: this solution is only lightly tested; I went from conception to successful execution in about 30 minutes — though I spent 90 more minutes on a custom property issue. The extra <span> is ugly, but I don’t see a way around it. If your aspect-ratioed boxes do not contain text you can leave it out. <p class="test"><span>The text</span></p> p.test { --aspectRatio: 16/9; --padding: 0.5em; border: 1px solid; padding: var(--padding); aspect-ratio: var(--aspectRatio); box-sizing: border-box; } @supports not (aspect-ratio: 16/9) { p.test { padding: 0; padding-top: calc((1 / (var(--aspectRatio)))*100%); position: relative; } p.test > span { display: block; position: absolute; top: var(--padding); left: var(--padding); } } Store the desired aspect ratio in --aspectRatio. Set aspect-ratio to that value. If the browser doesn’t support aspect-ratio, set the padding-top to 1 / the aspect ratio as a percentage. The script that runs in this page changes the value of --aspectRatio. The trick here is that percentual padding is calculated relative to the parent element’s width. If the box spans its parent’s entire width, you can take that width, multiply it by 1 divided by the aspect ratio (so for instance 9/16th when the aspect ratio is 16/9) and convert the result to a percentage. Now the padding stretches the box to the desired aspect ratio. If the box has any real content we have to wrap it in an extra HTML element and give that element position: absolute so that it does not influence the box’s height. Then we place it in the box, with a top and left coordinate equal to the box’s padding. Now the text appears to flow naturally. You don’t need this trick if the box only has a background image or gradient; those ignore padding anyway. Or you can wait a few months until all browsers support aspect-ratio. It won’t be long now. I may write a separate article about the incredible number of brackets we need in the padding-top line. Full Article CSS for JavaScripters
pe Custom properties and @property By www.quirksmode.org Published On :: Wed, 21 Jul 2021 14:18:40 +0100 You’re reading a failed article. I hoped to write about @property and how it is useful for extending CSS inheritance considerably in many different circumstances. Alas, I failed. @property turns out to be very useful for font sizes, but does not even approach the general applicability I hoped for. Grandparent-inheriting It all started when I commented on what I thought was an interesting but theoretical idea by Lea Verou: what if elements could inherit the font size of not their parent, but their grandparent? Something like this: div.grandparent { /* font-size could be anything */ } div.parent { font-size: 0.4em; } div.child { font-size: [inherit from grandparent in some sort of way]; font-size: [yes, you could do 2.5em to restore the grandparent's font size]; font-size: [but that's not inheriting, it's just reversing a calculation]; font-size: [and it will not work if the parent's font size is also unknown]; } Lea told me this wasn’t a vague idea, but something that can be done right now. I was quite surprised — and I assume many of my readers are as well — and asked for more information. So she wrote Inherit ancestor font-size, for fun and profit, where she explained how the new Houdini @property can be used to do this. This was seriously cool. Also, I picked up a few interesting bits about how CSS custom properties and Houdini @property work. I decided to explain these tricky bits in simple terms — mostly because I know that by writing an explanation I myself will understand them better — and to suggest other possibilities for using Lea’s idea. Alas, that last objective is where I failed. Lea’s idea can only be used for font sizes. That’s an important use case, but I had hoped for more. The reasons why it doesn’t work elsewhere are instructive, though. Tokens and values Let’s consider CSS custom properties. What if we store the grandparent’s font size in a custom property and use that in the child? div.grandparent { /* font-size could be anything */ --myFontSize: 1em; } div.parent { font-size: 0.4em; } div.child { font-size: var(--myFontSize); /* hey, that's the grandparent's font size, isn't it? */ } This does not work. The child will have the same font size as the parent, and ignore the grandparent. In order to understand why we need to understand how custom properties work. What does this line of CSS do? --myFontSize: 1em; It sets a custom property that we can use later. Well duh. Sure. But what value does this custom property have? ... errr ... 1em? Nope. The answer is: none. That’s why the code example doesn’t work. When they are defined, custom properties do not have a value or a type. All that you ordered the browsers to do is to store a token in the variable --myFontSize. This took me a while to wrap my head around, so let’s go a bit deeper. What is a token? Let’s briefly switch to JavaScript to explain. let myVar = 10; What’s the value of myVar in this line? I do not mean: what value is stored in the variable myVar, but: what value does the character sequence myVar have in that line of code? And what type? Well, none. Duh. It’s not a variable or value, it’s just a token that the JavaScript engine interprets as “allow me to access and change a specific variable” whenever you type it. CSS custom properties also hold such tokens. They do not have any intrinsic meaning. Instead, they acquire meaning when they are interpreted by the CSS engine in a certain context, just as the myVar token is in the JavaScript example. So the CSS custom property contains the token 1em without any value, without any type, without any meaning — as yet. You can use pretty any bunch of characters in a custom property definition. Browsers make no assumptions about their validity or usefulness because they don’t yet know what you want to do with the token. So this, too, is a perfectly fine CSS custom property: --myEgoTrip: ppk; Browsers shrug, create the custom property, and store the indicated token. The fact that ppk is invalid in all CSS contexts is irrelevant: we haven’t tried to use it yet. It’s when you actually use the custom property that values and types are assigned. So let’s use it: background-color: var(--myEgoTrip); Now the CSS parser takes the tokens we defined earlier and replaces the custom property with them: background-color: ppk; And only NOW the tokens are read and intrepreted. In this case that results in an error: ppk is not a valid value for background-color. So the CSS declaration as a whole is invalid and nothing happens — well, technically it gets the unset value, but the net result is the same. The custom property itself is still perfectly valid, though. The same happens in our original code example: div.grandparent { /* font-size could be anything */ --myFontSize: 1em; /* just a token; no value, no meaning */ } div.parent { font-size: 0.4em; } div.child { font-size: var(--myFontSize); /* becomes */ font-size: 1em; /* hey, this is valid CSS! */ /* Right, you obviously want the font size to be the same as the parent's */ /* Sure thing, here you go */ } In div.child he tokens are read and interpreted by the CSS parser. This results in a declaration font-size: 1em;. This is perfectly valid CSS, and the browsers duly note that the font size of this element should be 1em. font-size: 1em is relative. To what? Well, to the parent’s font size, of course. Duh. That’s how CSS font-size works. So now the font size of the child becomes the same as its parent’s, and browsers will proudly display the child element’s text in the same font size as the parent element’s while ignoring the grandparent. This is not what we wanted to achieve, though. We want the grandparent’s font size. Custom properties — by themselves — don’t do what we want. We have to find another solution. @property Lea’s article explains that other solution. We have to use the Houdini @property rule. @property --myFontSize { syntax: "<length>"; initial-value: 0; inherits: true; } div { border: 1px solid; padding: 1em; } div.grandparent { /* font-size could be anything */ --myFontSize: 1em; } div.parent { font-size: 0.4em; } div.child { font-size: var(--myFontSize); } Now it works. Wut? Yep — though only in Chrome so far. This is the grandparent This is the parent This is the child What black magic is this? Adding the @property rule changes the custom property --myFontSize from a bunch of tokens without meaning to an actual value. Moreover, this value is calculated in the context it is defined in — the grandfather — so that the 1em value now means 100% of the font size of the grandfather. When we use it in the child it still has this value, and therefore the child gets the same font size as the grandfather, which is exactly what we want to achieve. (The variable uses a value from the context it’s defined in, and not the context it’s executed in. If, like me, you have a grounding in basic JavaScript you may hear “closures!” in the back of your mind. While they are not the same, and you shouldn’t take this apparent equivalency too far, this notion still helped me understand. Maybe it’ll help you as well.) Unfortunately I do not quite understand what I’m doing here, though I can assure you the code snippet works in Chrome — and will likely work in the other browsers once they support @property. Misson completed — just don’t ask me how. Syntax You have to get the definition right. You need all three lines in the @property rule. See also the specification and the MDN page. @property --myFontSize { syntax: "<length>"; initial-value: 0; inherits: true; } The syntax property tells browsers what kind of property it is and makes parsing it easier. Here is the list of possible values for syntax, and in 99% of the cases one of these values is what you need. You could also create your own syntax, e.g. syntax: "ppk | <length>" Now the ppk keyword and any sort of length is allowed as a value. Note that percentages are not lengths — one of the many things I found out during the writing of this article. Still, they are so common that a special value for “length that may be a percentage or may be calculated using percentages” was created: syntax: "<length-percentage>" Finally, one special case you need to know about is this one: syntax: "*" MDN calls this a universal selector, but it isn’t, really. Instead, it means “I don’t know what syntax we’re going to use” and it tells browsers not to attempt to interpret the custom property. In our case that would be counterproductive: we definitely want the 1em to be interpreted. So our example doesn’t work with syntax: "*". initial-value and inherits An initial-value property is required for any syntax value that is not a *. Here that’s simple: just give it an initial value of 0 — or 16px, or any absolute value. The value doesn’t really matter since we’re going to overrule it anyway. Still, a relative value such as 1em is not allowed: browsers don’t know what the 1em would be relative to and reject it as an initial value. Finally, inherits: true specifies that the custom property value can be inherited. We definitely want the computed 1em value to be inherited by the child — that’s the entire point of this experiment. So we carefully set this flag to true. Other use cases So far this article merely rehashed parts of Lea’s. Since I’m not in the habit of rehashing other people’s articles my original plan was to add at least one other use case. Alas, I failed, though Lea was kind enough to explain why each of my ideas fails. Percentage of what? Could we grandfather-inherit percentual margins and paddings? They are relative to the width of the parent of the element you define them on, and I was wondering if it might be useful to send the grandparent’s margin on to the child just like the font size. Something like this: @property --myMargin { syntax: "<length-percentage>"; initial-value: 0; inherits: true; } div.grandparent { --myMargin: 25%; margin-left: var(--myMargin); } div.parent { font-size: 0.4em; } div.child { margin-left: var(--myMargin); /* should now be 25% of the width of the grandfather's parent */ /* but isn't */ } Alas, this does not work. Browsers cannot resolve the 25% in the context of the grandparent, as they did with the 1em, because they don’t know what to do. The most important trick for using percentages in CSS is to always ask yourself: “percentage of WHAT?” That’s exactly what browsers do when they encounter this @property definition. 25% of what? The parent’s font size? Or the parent’s width? (This is the correct answer, but browsers have no way of knowing that.) Or maybe the width of the element itself, for use in background-position? Since browsers cannot figure out what the percentage is relative to they do nothing: the custom property gets the initial value of 0 and the grandfather-inheritance fails. Colours Another idea I had was using this trick for the grandfather’s text colour. What if we store currentColor, which always has the value of the element’s text colour, and send it on to the grandchild? Something like this: @property --myColor { syntax: "<color>"; initial-value: black; inherits: true; } div.grandparent { /* color unknown */ --myColor: currentColor; } div.parent { color: red; } div.child { color: var(--myColor); /* should now have the same color as the grandfather */ /* but doesn't */ } Alas, this does not work either. When the @property blocks are evaluated, and 1em is calculated, currentColor specifically is not touched because it is used as an initial (default) value for some inherited SVG and CSS properties such as fill. Unfortunately I do not fully understand what’s going on, but Tab says this behaviour is necessary, so it is. Pity, but such is life. Especially when you’re working with new CSS functionalities. Conclusion So I tried to find more possbilities for using Lea’s trick, but failed. Relative units are fairly sparse, especially when you leave percentages out of the equation. em and related units such as rem are the only ones, as far as I can see. So we’re left with a very useful trick for font sizes. You should use it when you need it (bearing in mind that right now it’s only supported in Chromium-based browsers), but extending it to other declarations is not possible at the moment. Many thanks to Lea Verou and Tab Atkins for reviewing and correcting an earlier draft of this article. Full Article CSS for JavaScripters
pe Ruhani Sharma: I play a close-to-reality cop in ‘HER’; there is no scope for ‘Singham’ style of histrionics By www.thehindu.com Published On :: Tue, 18 Jul 2023 19:06:24 +0530 Ruhani Sharma talks about headlining the Telugu cop drama franchise ‘HER’, says she never imagined herself as a sharpshooter Full Article Movies
pe Director Sai Rajesh: ‘Baby’ has been a learning experience; henceforth I will be more cautious in my writing By www.thehindu.com Published On :: Wed, 19 Jul 2023 16:16:44 +0530 Sai Rajesh, the writer-director of the Telugu romantic drama ‘Baby’ that has been eliciting extreme responses, says he did not intend to make a toxic film Full Article Movies