co

Gold, silver shine but correction possible

Underlying forces spurring demand for the metals include geopolitical tensions and uncertainties about the outcome of the U.S. Presidential polls




co

Copper futures likely to rally, go long

The November contract can touch ₹875




co

Today’s Stock Recommendation: November 5, 2024

The stock idea that we have for you today is Angel One




co

Post mixed Q2, India Inc may face tailwinds in second half of FY25

It needs to be seen if fortunes for the consumer segments will reverse




co

When the taxman comes knocking

Here’s a lowdown on notices/ intimations from the I-T department and what they mean for taxpayers




co

Market correction broad-based with 7 of 10 stocks of BSE AllCap seeing a fall

FPI outflows overlapping with earnings slowdown and the return of the dragon weigh in




co

Coming soon, a new asset class to consider

India’s securities regulator is looking to open up a fresh vehicle for investments for people in the mass affluent segment that will be different from existing mutual fund alternatives




co

Copper: Can oscillate in a range

MCX Copper Futures contract can trade in a range of ₹820-₹865




co

fit-content and fit-content()

Today we will look at fit-content and fit-content(), which are special values for width and grid definitions. It’s ... complicated — not as a concept, but in its practical application.

min- and max-content

Before looking at fit-content we have to briefly review two other special width values: min-content and max-content. You need those in order to understand fit-content.

Normally (i.e. with width: auto defined or implied) a box will take as much horizontal space as it can. You can change the horizontal space by giving width a specifc value, but you can also order the browser to determine it from the box’s contents. That’s what min-content and max-content do.

Try them below.

min-content and max-content
width: auto: as much as possible
width: max-content
width: min-content
width: max-content with a long text that runs the danger of disappearing right out of the browser window if it continues for much longer
  • min-content means: the minimal width the box needs to contain its contents. In practice this means that browsers see which bit of content is widest and set the width of the box to that value. The widest bit of content is the longest word in a text, or the widest image or video or other asset.
  • max-content means: the width the box needs to contain all of its contents. In the case of text this means that all text is placed on one line and the box becomes as wide as necessary to contain that entire line. In general this is not a desirable effect. The largest bit of content may also be an image or video other asset; in that case browsers use this width to determine the box’s width.

If you use hyphens: auto or something similar, the browser will break the words at the correct hyphenation points before determining the minimal width. (I turned off hyphenation in the examples.)

Quick Chromia/Android rabbit hole

All Chromium-based browsers on Android (tested in Chrome (v90), Samsung Internet (v87), and Edge (v77)) break off the 'width: max-content' text in the example above at the dash, and thus take the 'width: max-' as the max-content, provided the page does NOT have a meta viewport. No other browser does this — and that includes Chrome on Mac.

Also, Chromia on Android make the font-size a tad smaller when you resize the boxes below the maximum possible width. I will ignore both bugs because this article is about fit-content, and not about these rabbit holes.

These bugs do NOT occur in UC (based on Chromium 78). Seems UC is taking its own decisions here, and is impervious to these particular bugs.

fit-content

Now that we understand these values we also understand fit-content. It is essentially a shorthand for the following:

box {
	width: auto;
	min-width: min-content;
	max-width: max-content;
}

Thus the box sizes with its containing box, but to a minimum of min-content and to a maximum of max-content.

fit-content as width, min-width, and max-width
width: fit-content: trying to find my fit
min-width: fit-content
max-width: fit-content

I’m not sure if this effect is useful outside a grid or flexbox context, but it’s here if you need it.

fit-content as min- or max-width

You can also use fit-content as a min-width or max-width value; see the example above. The first means that the width of the box varies between min-content and auto, while the second means it varies between 0 and max-content.

I find this fairly useless and potentially confusing. What you really mean is min-width: min-content or max-width: max-content. If that’s what you mean, say so. Your CSS will be clearer if you do.

So I believe that it would be better not to use fit-content for min-width or max-width; but only for width.

-moz-

Unfortunately, while fit-content works in all other browsers, Firefox still needs a vendor prefix. So the final code becomes:

box {
	width: -moz-fit-content;
	width: fit-content;
}

(These prefixes get harder and harder to defend as time goes by. fit-content has perfectly fine cross-browser support, so I don’t see why Firefox doesn’t just go over to the regular variant.)

fit-content in flexbox and grid: nope

fit-content does not work in flexbox and grid. In the example below the centre box has width: fit-content; it does not work. If it worked the middle box would have a width of max-content; i.e. as small as it needs to be to contain its text.

Flexbox with fit-content
Test content
fit-content
Test content

The final example on this page has a test where you can see grid doesn’t understand this keyword, either.

Note that grid and flex items have min-width: min-content by default, as you can see in the example above.

fit-content()

Let’s go to the more complex part: fit-content(). Although it’s supposed to work for a normal width, it doesn’t.

fit-content and fit-content() as width
width: fit-content: trying to find my fit
width: fit-content(200px)

Grid

You can use fit-content(value) in grid templates, like:

1fr fit-content(200px) 1fr
Grid with fit-content(200px)
Test content
fit-content(200px)
Test content

It means

1fr min(max-content-size, max(min-content, 200px)) 1fr

The max() argument becomes min-content or 200 pixels, whichever is larger. This is then compared to the maximum content size, which is the actual width available due to the constraints of the grid, but with a maximum of max-content. So the real formula is more like this one, where available-size is the available width in the grid:

1fr min(min(max-content,available-size), max(min-content, 200px)) 1fr

Some syntactic notes:

  • We’re talking fit-content() the function here. fit-content the keyword does not work in grid definitions.
  • Here Firefox does not need -moz-. Go figure.
  • fit-content() needs an argument; an empty function does not work. Also, an argument in fr units is invalid.
  • MDN mentions a value fit-content(stretch). It does not work anywhere, and isn’t referred to anywhere else. I assume it comes from an older version of the spec.

I tested most of these things in the following example, where you can also try the bits of syntax that do not work — maybe they’ll start working later.

And that’s fit-content and fit-content() for you. It’s useful in some situations.

Below you can play around with fit-content() in a grid.

Grid with controls

Set grid-template-columns: to

Test content
fit-content() with some more text



  • CSS for JavaScripters

co

IISc study reveals that picolinic acid can block viruses causing SARS-CoV-2 and influenza A

The study describes the compound’s remarkable ability to disrupt the entry of enveloped viruses into the host’s cell and prevent infection




co

Ruhani Sharma: I play a close-to-reality cop in ‘HER’; there is no scope for ‘Singham’ style of histrionics

Ruhani Sharma talks about headlining the Telugu cop drama franchise ‘HER’, says she never imagined herself as a sharpshooter 




co

Congress leaders project a united stand from Komatireddy’s luncheon meeting

Bus yatra and more interactions with people suggested




co

Rana Daggubati’s Spirit Media to launch ‘Hiranyakashyap’ movie, ‘Minnal Murali’ comic and more at San Diego Comic-Con 2023

Actor-producer Rana Daggubati’s Spirit Media debuts at San Diego Comic-Con 2023 by announcing the mythological film ‘Hiranyakashyap’ and comic based on the superhero film ‘Minnal Murali’ 




co

Carry out Uppal corridor repairs: BJP




co

NIA arrests man from Hyderabad in connection with terror module 




co

India’s first fuel outlet operated by woman convicts inaugurated in Chennai

About 30 woman prisoners will be employed in this petrol outlet in day shift and about 17 men prisoners on the night shift with a salary of ₹6,000 a month




co

Govt to constitute high-level committee to monitor implementation of crop loan waiver, says Harish Rao

CM announced unconditional crop loan waiver twice unlike other States, he said 




co

Vennela Kishore to headline ‘Chaari 111’, a spy action comedy

Telugu comedy actor Vennela Kishore to play the hero in director T.G. Keerthi Kumar’s spy action comedy ‘Chaari 111’




co

Allu Arjun offers a glimpse Of ‘Pushpa 2’ on Instagram’s official account 

Actor Allu Arjun invited Instagram to the sets of his forthcoming Telugu film ‘Pushpa: The Rule’, directed by Sukumar




co

Manoje Nath | Some blunt truths from a top cop

Tales from Banana Republic by Manoje Nath, former Director-General of Police, Bihar, offers a collection of stories that describe the complex interplay of power in politics and governance




co

An ongoing trunk show in Coimbatore showcases luxury fashion brands

Leading design houses from across the country showcase their collections at an ongoing trunk show




co

Decomposed body of woman found at construction site near Hyderabad




co

Tharun Bhascker’s crime comedy ‘Keedaa Cola’, presented by Rana Daggubati, announces its release date

Actor-director Tharun Bhascker Dhaassyam’s Telugu crime comedy ‘Keeda Cola’, presented by Rana Daggubati, will arrive in theatres in November




co

World Tourism Day: Discover cities in India through performance arts

Engage in Tamil kuthu in Chennai, hip-hop in Hyderabad, movement therapy in Bengaluru or Latin folk dance in Kochi. Dancescapes presents a city through performance art curated experiences



  • Life & Style

co

A spiritual confluence at Varanasi

The Sankara Math at Hanuman Ghat has been a beehive of activities with the presence of the Kanchi Sankaracharya




co

Watch | Jazzing up Chennai’s college canteens

From food courts to in-house apps - a look at how canteens in Chennai’s leading colleges have evolved




co

Naga cuisine, an artsy deli, a chocolate nook: Mumbai’s three new cafés

A three-table Naga restaurant, an artsy deli in a 1940s Art Deco mansion and a new chocolate nook: here are three new cafés to check out in Mumbai




co

‘Our goal was to bring intelligent conversations to Hyderabad’

Since 2005 Manthan as a platform succeeded in hosting 450 speakers in their monthly events, and about 65 speakers at the annual Samvaad




co

Actor Vidyullekha Raman looks forward to her upcoming films

After completing 11 years in the industry with 75 films, Vidyullekha Raman says now is the best time for actors as the spotlight is on author-backed roles




co

New menu of Chettinad Canteen in Coimbatore features kavuni arisi appam, bun parotta and more

From feather-light ‘kavanarisi appam’ in coconut milk and ‘kuzhi paniyaram’ served with ‘pepper kaadai’ to the classic ‘adi kumayam’ in ice cream, what makes this new menu tick at the Chettinad Canteen




co

Alcohol and Cancer Risk

A fact sheet that summarizes the evidence linking alcohol consumption to the risk of various cancers. Includes information about factors that affect the risk of alcohol-associated cancers, such as a person’s genes and tobacco use.




co

Secondhand Smoke and Cancer

A fact sheet that summarizes the studies on the health effects of exposure to environmental (secondhand) tobacco smoke.




co

Gauri Khan shares designs secrets from her latest project, the Falguni Shane Peacock store in Kolkata 

This is the third store that Gauri Khan has designed for FSP, after Mumbai and Hyderabad




co

How Bloom In Green festival is attempting to spread the message of community and conscious living

Krishnagiri is set to host the fourth edition Bloom In Green festival from December 15 to 18




co

Araku Pinery, a new community-based eco-tourism project near Visakhapatnam

Enjoy misty winter mornings with a warm cup of coffee at Araku Pinery, a new eco-tourism project by the AP Forest Department in Anjoda, located at a distance of about 130 kilometres from Visakhapatnam




co

The vibrant culture of Gujarat comes alive at Rann Utsav in Kutch

Prized buffaloes, white desert sunsets, stargazing and a Harappan site in India’s westernmost district



  • Life & Style

co

Traversing through time: Exploring Coimbatore through a heritage walk

Discovering nuggets of Coimbatore’s history through the 16th year of the heritage walk by historian Rajesh Govindarajulu




co

Airports to ensure Digi Yatra registration is voluntary and consensual: Scindia

The Aviation Minister’s comments followed complaints from passengers about forceful collection of personal data at airports




co

Spanish woman gang rape case: Crimes against foreigners in India rarely result in convictions | Data

Approximately, one in twenty rape cases in which victims are foreigners results in convictions




co

Powered by powdery snow, Gulmarg is vying to become an international winter sports venue

Indian Olympic Association is working on an international certification for the Gulmarg slopes, which are covered by the powdery snow needed for professional skiing




co

Explore healthy corals at Helengeli in the Maldives

The renovated OBLU NATURE at Helengeli in Maldives offers water villas and memorable dives to see coral reefs busy with banner fish, bluestripe snappers and the occasional black tip reef shark




co

Holiday bookings up this summer vacation, with some impact from upcoming Lok Sabha elections

There is an increase of 30-40% in domestic travel, and 15% in international travel bookings




co

Discover the hidden charm of Anija on the Odisha-Andhra border

Explore a world of greens, caves and rivers at Anija village in the Rayagada district of Odisha




co

Composer Vipin Mishra rides to Zanskar Valley with friends to record nomadic music

The travel resulted in a docu-series titled Folkroad, which was screened recently at the Red Lorry Festival in Mumbai.




co

Tourism authorities yet to explore ways to promote ecotourism destinations in Kozhikode

Monsoon tourism packages such as rain walks and guided trips have not been announced for tourists here despite their popularity in ecotourism destinations outside the State.




co

Karnataka to restart 3,800 bus routes suspended during COVID-19 pandemic

Transport Minister Ramalinga Reddy says besides restarting bus routes, 10,000 trips will be added




co

A Chennai-based medical practitioner’s coffee table book captures the Himalayas across the seasons and terrains over two decades

How life changing is the Himalayan range? Dr Periyathiruvadi, a Chennai-based medical practitioner and founder of Lister Metropolis, has curated a coffee table book of photos from the mountains to answer this question




co

Scoot begins air services from Singapore to Malaysia’s Sibu

The company is operating three weekly flights with a maximum seating capacity of 112 passengers from the Asian financial hub to the city on Borneo Island




co

Explore corals at Havelock island with CGH Earth’s latest property, Tilar Siro

We check into an eco resort set on one of the largest islands in the Andaman chain, famed for its white sand beaches, spectacular sunsets and vibrant marine life. We check into the eco friendly resort to explore Havelock island




co

Ricky Kej’s anthem for Bengaluru airport captures the emotions of departures and homecomings

Ricky Kej’s BLR Airport Anthem, featuring fellow Grammy-winner Lonnie Park, tells stories of travel and connection