Tumgik
#it probably just doesn't allow hyphenation
sins-of-the-sea · 1 year
Text
Tumblr media
“Don’t you normally hyphenate your surname when you write it out in the Romanized alphabet, Rashid?”
Tumblr media
“Well....”
Tumblr media Tumblr media
“...Racist Santa.”
5 notes · View notes
scintillyyy · 1 year
Text
i know we talk about fanon sometimes like it's a monolith, but actually i have an argument that the fanon(tm) is actually a little more diverse than we think sometimes and i say this because i have categorized and subtyped the various different kinds.
so to start, we have two broad categories: category 1//pre-ethiopia fanon and category 2//post-ethiopia fanon. pre-ethiopia canon is by and large much more simple and straightforward. post-ethiopia is where we start to see more variety and different subtypes.
tim:
pre-ethiopia: probably skipped two grades. bad parents jack and janet simultaneously care immensely about both tim taking over the company one day and also don't care at all about ensuring their son actually survives until adulthood to do so. survival of the fittest, baby, you're a failure of an heir if you can't use the stove independently by age 4. free space of "criminal neglect" being mentioned at some point. camera stalker to the point where he has batman's patrol routes memorized. jason is definitely his idol.
post-ethiopia: subtype (a)//robin: bad parents jack and janet remain (even though janet should have died years ago), leaving tim all alone in the cold drake manor. this 15 year old, rather than reveling in this independence allowing him more freedom to do robin without having to worry about his parents, is immensely sad about this state of affairs. bruce probably hates him for not being jason. jason hates him until he realizes that tim is "just a kid" who has "bad parents" and needs to be saved. physical abuse from his dad highly likely. most likely jason is his idol, but there may be some mention about how much he loves dick. subtype (b)//red robin: addicted to coffee, hasn't slept in weeks. everyone in the batfamily simultaneously hates him and depends on him to keep the entire operation running without any thanks or recognition. nobody loves him, definitely thinks he's not part of the family. they will have to prostrate themselves when they realize the damage they've done to him. subtype (c)//the jerk: a far rarer type of fanon, but still fanon all the same. this subtype is the anti-tim fanon, a backlash fanon, where basically all of tim's bad traits are amplified to the point where he is borderline sociopathic, doesn't really have any sympathy or care for anyone else, and is so super judgemental and snotty to the point that yes, he is no longer recognizable as tim drake and this is officially a fanon. and not that tim doesn't ever show bad traits in canon (he is flawed, like all of them), but really. he does care about other people immensely. he cares about gotham immensely. they all do. even if chuck dixon used him for heavy-handed conservative messages in the 90s, these aren't, like, enduring character traits. most likely to be seen if we're trying to promote another batboy who is getting woobified.
jason:
pre-ethiopia: the only panels that matter are "robin gives me magic" and anything that implies a love of school/good grades. no negative traits, if we give him any negative traits then we are feeding into the idea that he was a "bad" robin just like dc tries to do. so, so focused on the victims and downtrodden of gotham (probably more than dick ever did) which is why tim admires him so much. he is Of The City. immediately zeros in on tim as a victim of terrible parents. ever kind and understanding and sympathetic. a true champion of the people. calls bruce dad, hyphenated his last name. calls dick "dickhead" as a term of loving endearment and dick is seemingly okay with this.
post-ethiopia: subtype (a)//red hood: lazarus pit madness, baby. not at fault for anything he did, it was all the pit. once the anger fades, he realizes that he has turned into the monster who killed him and he feels great shame for this, has to make amends (most likely to tim, for titans tower). subtype (b)//sadboy jason: woobified jason is just sad :( his dad didn't love him, his brother didn't love him, they replaced him. he just wants to go home, desperately. the batfamily must make amends for not grieving him well enough/let him know how much they love and miss him and then he can go home. highly likely was damian's beloved brother in the league and considered talia his mom.
dick:
pre-ethiopia: only eats cereal. comes home every weekend to do his laundry (u know what, good on u dick. i too went home a lot of weekends after i moved out so i wouldn't have to pay for coin laundry at my apartment complex. it's called being smart and strategic.) and hang out with his dad, bruce, and little brother, jason. also has a hyphenated last name. a little dim. always happy. all about the hugs.
post-ethiopia: subtype (a)//nightwing: is allowed to be a good brother to tim, but will never be tim's favorite. feels immensely guilty about how terribly he treated jason as robin, must make amends for this. very bland personality. subtype (b)//post-dickbats: devil incarnate. plays favorites with his brothers and has room in his heart to only love two (neither of which are tim), that is until he realizes how badly he has treated tim and feels immensely bad and guilty that he's ignored tim for so long and then is finally able to redeem himself. probably threatened tim with arkham and told everyone tim was nuts. subtype (c)//dick actually gets to be woobified for once: on rare occasion, dick gets to be the one who gets constantly downtrodden and used by his siblings even if this isn't actually really super in character for them. like i said, super rare. usually seen so that dick can lose his temper at his siblings who are being immature jerks for no reason. cathartic if you're tired of dick being beat down by the writers at dc, but still fanon imo because you have to rely on someone (usually tim) acting more out of character and far more immature towards dick than normal canon and more fanon-y relationship dynamics (such as tim & damian constantly fighting and really hating each other) to get to this point. ....will kind of infantilize an adult man in his mid-twenties.
damian:
pre-ethiopia: actually gets two subtypes!! subtype (a)//doesn't exist: damian who? subtype (b)//young child: we bring him in as a 3 year old, and he's basically a totally different character. probably only meaningful character trait is total adoration for his older brothers.
post-ethiopia: subtype (a)//meanest child in the world: hates tim, is actively trying to murder him constantly and make sure that tim knows he is not a wayne/not welcome in the family. revels in having successfully stolen all of dick's love and attention. no character growth and all the adults just let him be mean without addressing the behavior, everything gets handwaved because of how he was brought up, but it's clear he knows right from wrong and is specifically choosing to do wrong. subtype (b)//he's just a 10 year old, so we have to treat him like *checks notes* a 5 year old: actually incapable of knowing right from wrong because of his upbringing, and he can't be at fault or responsible for any of his behavior because he's only 10 years old, and 10 year olds are too young to know any better when they've grown up in the league, despite extensive education on all subjects growing up likely including philosophy and morality. likely to be the woobified and infantilized one here. needs to be treated like a 3 year old with kid gloves because he's just a kid, after all. when he realizes he is "bad", he is very depressed and sad. often has no knowledge of the outside world, must be taught by his ever patient and loving brothers.
150 notes · View notes
sasubaeuchithot · 1 year
Note
If Sasuke and Naruto did get married who would propose? Or would it be more of a “you wanna get married?” “…yeah” thing. Do you think one would change their surname or like hyphenate or something
genuinely another thing ive literally never thought about lmaoooooo
i think naruto would probably have the idea dawn on him WAY too many years in their relationship. like he sees a pair of his friends have a wedding and is like. "OH. SASUKE AND I CAN DO THIS." and it's a completely new thought in his head. it'd be hilarious if he was just blurted out in the middle of their friend's reception "SASUKE. WE SHOULD DO THIS." and then Sakura has to lecture him that "you don't propose at someone else's wedding" but Naruto didn't think of it as a proposal at all and also doesn't understand why that's something you can't do, but is persuaded by her explaining how proposals are supposed to be grand and romantic (which wigs Sasuke out tremendously). but Naruto makes a vow that he's gunna ask Sasuke to marry him in a way that's going to completely wow him, make him absolutely swoon and cry and it's gunna be the most romantic thing ever just you wait Dattebayo Believe It Teme™.
so Sasuke fully knows Naruto is gunna try to propose to him and does everything in his power to make sure it doesnt happen in public in front of fifty million people like how Sakura described. Sasuke has a lot of anxiety about it, refusing to go out together to eat or to the store, hardly even allowing them to go out to even train, of all things.
thankfully Naruto picks up on Sasuke's anxiety. he waits for a night some several months later when all of Sasuke's walls are down- perhaps they just finished an early round of sex, Naruto carries him to the bath to wash up and spends an hour pampering him.
he doesn't ask until Sasuke gets settled into bed. it's spur of the moment, which it turns out Naruto knew he would have to do to actually catch Sasuke off guard.
i think Sasuke would call Naruto "usuratonkatchi" and Naruto would tease Sasuke about how it was taking him forever to actually say "yes" even though he clearly wanted to. it would break the tension even for Sasuke to "hn" out his agreement to get married, which Naruto would make fun of him even more for. sasuke doesn't swoon, of course he doesn't that would be stupid and pointless and it's just marriage anyway why does it matter (he clings onto Naruto practically purring into his chest for the entire night, and spends the rest of the week hardly stepping away from Naruto's side).
i don't think either would change their name. neither of them really understand the semantics of it, and both are too attached to their family names to want to give it up or modify it.
44 notes · View notes
Note
Hi!
Hope you are doing well :) Just a fun and silly question ....
How do you think Sara and Grissom would react now if Sara were referred to as Mrs. Grissom?
I think there have only been two scenarios (I could be wrong) this has happened on CSI – in 10x2, Sara refers to herself as Mrs. Grissom, and in 11x13, the Two Mrs. Grissoms – in which both times it was explicitly made clear she kept her last name.
I realize that it’s the 21st century and it’s not uncommon that women keep their surname after marriage so no biggie that Sara, for all (personal and professional) purposes has kept her last name. But the GSR-fan in me was really hoping someone – either by way of humour or not – would refer to Sara as Mrs. Grissom on CSI: Vegas (in front of the hubby) and we get a reaction. (we got a "my husband" and a "my wife" so can't really complain here)
The version of GSR we got in CSI: Vegas was more jovial. They probably would have teased each other about it?
(I mean she could have gone by ‘Sidle-Grissom’, no?)
Thanks for taking the time to share your thoughts!
hi, @renb80s!
good to hear from you again!
so this topic is one that tends to be polarizing in the gsr fandom, with some people really hating the idea of sara taking grissom's last name (even as part of a hyphenate) and some people really liking it/wishing tptb would have gone that route in canon (either in the original series and/or the reboot).
regardless of one's personal feelings on the matter, the facts are these:
as you point out, sara is twice in canon referred to as "mrs. grissom," once in episode 10x02 "ghost town" and once in episode 11x13 "the two mrs. grissoms."
she is also referenced as one of the two titular "mrs. grissoms" of the latter episode in an extratextual sense.
in the first case, she refers to herself that way, albeit in jest.
in the second, she is referred to that way by julia holden.
in both instances, her reaction to being called "mrs. grissom" is to smile widely and blush.
while she does in the former case correct brass's mistaken impression that she has legally taken grissom's name and in the latter case allow her mother-in-law to correct julia holden's mistaken impression that she has taken grissom's name on her behalf, she doesn't, in either instance, appear at all offended by the mistaken impressions themselves. her responses are both very mild.
i'll take things from there after the "keep reading," if you're interested.
__
now.
canon never delves into why sara doesn't legally take grissom's last name.
the choice could be a personal one on her part.
given the attitudes she expresses in episode 06x21 "rashomama" re: women being treated as exchanged property in marriage, she could be opposed to taking her husband's last name after marriage on feminist grounds.
in a similar vein, maybe she feels maintaining her own identity even within the context of her marriage is important and so doesn't want to either give up her name or merge it with grissom's.
alternatively, perhaps on a more intimate note she wants to keep her family name as something of a testament to herself: to prove her legacy is not determined by her family of origin and that she can be a good, just person while still bearing the last name sidle; to show herself and the world her whole lineage isn't cursed/broken (“everything that happens to us—good and bad—is a part of us. it took me a long time to realize that it doesn’t have to define who we are. we get to decide”).
as an aside: i've always found it interesting sara doesn't change her name upon her emancipation from the foster care system. not only might one expect her to change her name because many former foster kids do once they age out (a fact sara herself even remarks upon in episode 07x16 "monster in the box"), but also because one might think, given her feelings about her family and her childhood trauma, she might be eager to get a fresh start under a new identity once she has the chance to. that she sticks with sidle even after she is at liberty to do otherwise is curious. whether she opts to retain her family name for the personal reason detailed above or perhaps only because legally changing her name would be prohibitively expensive for her (particularly as a financially insecure young adult), we're never told. however, the fact that she still bears her father and mother's last name 25+ years on from her father's murder is certainly fascinating.
i wonder if she was ever worried while she worked for the sfpd that someday someone might discover a link between her somewhat unique surname—according to this tracker, there are fewer than 1,000 sidles (spelled sara's way) worldwide—and a particular 1970s marin county homicide case?
more inanely, maybe she opts to stick with sidle because grissom is commonly called by his last name by their close friends/found family, to the extent she feels her being "grissom," as well, would just be too strange/confusing.
maybe she just likes the way her maiden name sounds due to the alliteration.
maybe she doesn't want her initials to be "sag."
maybe grissom (for whatever reason) never actually offers her his last name and she, not wanting to be presumptuous, never asks if she could take it and so just ultimately doesn't.
maybe she reasons since she and grissom aren't planning to have children, there isn't much imperative for them to all have the same name.
maybe she and grissom talk about the matter and make the mutual decision they don't want to take each other's names or hyphenate (for whatever reasons).
of course, the choice also could be more of a practical one for her.
maybe, like many professional women who have earned degrees, published, been awarded accolades, and built their careers under their maiden names, she doesn't want to separate herself from 20+ years of work and accomplishments.
conversely, her surname status may be more a reflection of the circumstances under which she gets married than anything else: under costa rican law, not only do women not automatically assume their husband's names upon marriage, but foreign citizens who get married in costa rica must use the same name that appears on their passports on their marriage certificates. while a foreign citizen who gets married in costa rica can opt to legally change their name in their country of residence once their costa rican marriage license is sent there, that step is 100% optional and is something the person must undertake to do on their own time/at their own expense ex post facto. that so, if grissom and sara have their wedding in costa rica (which i tend to think they do), then it's entirely possible sara ends up remaining a sidle after marriage by default: because that name is the one on her costa rican marriage license, and she doesn't take the time/pay the fees to make an official change stateside. this option may be especially likely if we consider she probably spends very little time in the states as a newlywed before moving immediately to france.
similarly, even if sara and grissom do marry in the us, she may end up a sidle not due to any strong personal feelings about the matter or professional considerations but simply because the process of legally changing one's name is, frankly, a pain in the ass: while in nevada, people can change their names upon marriage simply by making note of their intentions on their marriage certificates, there are still various costs associated with changing over all of one's legal, professional, and financial information to match one's new name, typically to the tune of about $100-$500. the process can also be time consuming/involved, often requiring in-person visits to prove one's identity at the dmv, bank, city hall, etc. figuring out what all you have to change and what documentation you need in order to make said changes can be confusing/laborious. maybe sara, after initially mulling changing her name, considers the time, expense, and effort required of the endeavor and simply says, "to hell with it," figuring since most people in her life would still know her as sara sidle anyhow, it isn't worth her while to jump through all those obnoxious hoops.
case in point: my mother, who has been married to my father and had his name for forty years, only recently discovered she apparently never changed over her social security number from her maiden name. the process of getting it changed over required dozens of phone calls and filings on her part (made difficult as, four decades on, she doesn't have much documentation linking her to her maiden name left to use for verification purposes) and took her several weeks to complete.
alternatively, maybe sara does initially intend to change her name and is maybe even in the process of doing so but never actually gets around to finishing the job due to the fact that, as a newlywed, she is so frequently in and out of the country, is extremely busy, (once she gets back to the states) works night hours, etc., etc.
maybe there is a paperwork glitch that makes the process difficult enough she doesn't elect to push the issue, even if perhaps she had initially been interested in taking grissom's name to start out with.
as a former ward of the state of california, she would not have access to her original birth certificate and was likely issued a new social security number when her mother's parental rights were severed. though she in theory has a redacted birth certificate and new ssn that are valid for legal purposes, maybe when, after her costa rican wedding, she goes to the state of nevada with her redacted/reissued documents looking to file her legal name change, they give her a hard time about them because they look funny ("how come your birth certificate says you were born in 1971 but according to this database your ssn was issued in 1980?") and require additional verification she simply cannot be bothered to provide.
it's also worth noting that while she doesn't legally take grissom's name either the first time she's married to him or the second (at least insofar as we know), her reasons for making that choice may be different in marriage 1.0 vs. marriage 2.0—for example, maybe the first go-around, she doesn't change her name due to the whole "we got married in costa rica" thing, whereas the second, she figures that after a 25+ year career, she wants to maintain the same name she built her reputation on.
of course, without knowing sara's exact reason or reasons for keeping her maiden name, we can't say with 100% certainty what her feelings on the matter of being "mrs. grissom" are—whether or not it's an issue she has strong feelings about, one way or another; if it's a decision she intends to stick with forever or if she ever might consider changing her name to grissom eventually; etc.
however, based on the two reactions to people referring to her that way we see in canon, i think, at the very least, we can infer she isn't adamantly opposed to being called mrs. grissom socially, even if she didn't take his name legally—and, indeed, may even be somewhat tickled by the experience, finding the notion amusing, if not even cute.
that so, i tend to imagine if someone were to refer to her as mrs. grissom or sara grissom during the events of the reboot, she would probably react much in the same way we see her do in s10 and s11: she'd get a big smile on her face, fluster a bit, and look to grissom, if he were with her. then, either she or he would, laughingly, point out she hadn't changed her name (at least not legally). maybe there'd be some playful banter about why she hadn't ("eh, i thought about it, but living in international waters? it would be a pain to file" "just say the words, and i'll take you to the consulate's office next time we're in guam, darlin'").
my take—and, full disclosure, i'm in the camp that doesn't mind the idea of her changing her name or even just going by grissom's surname more informally/on occasion (as is probably obvious from the fact that i often label my gsr gifsets as "the grissoms")—is that while she's never made the effort to actually legally change her name to grissom's and maybe even sees some advantages to keeping her maiden name for professional reasons, she has no problem being associated with his name socially and in fact kind of gets a kick out of it, which is why she sometimes refers to herself that way unprompted and doesn't really go out of her way to correct people who make mistakes about what she's called.
i can very easily imagine that after sara and grissom leave vegas at the end of csi: vegas s1, a few weeks later, a postcard arrives at the lab addressed to max, postmarked from panama, bearing no inscription other than a signoff "from the grissoms," written in sara's hand.
thanks for the question! please feel welcome to send another any time.
also, shameless plug: for those of you reading "an opposite of echoes," eventually, you'll get to see sara react to being called "mrs. grissom" in that story (on multiple occasions).
15 notes · View notes
Note
For the fact that Bruce Jenner is a man with reproductive sexual organs of man same as me and how the fuck does that make him different than any other man? when in fact he is a man. How the fuck do you think he is woman just like yourself a natural born female? If you think he is a women how come he cannot get periods or goes through what a woman´s body goes through and if younger how would that man get pregnant? like to hear your leftists logic on men like him who think he is a woman.
Here's the thing about Caitlyn Jenner
Obviously she is biologically male. Obviously she is not the same as a biological woman. She's also not trying to tell anyone that she gets pms or should be allowed to compete against women in sports (quite the opposite of that, in fact). As far as I can tell, she's just trying to live as normal a life as someone like her is able but she's under no illusions that she will ever be quite the same and she's not trying to change the rest of us to make herself feel more normal.
I'm totally fine with this. She's not bothering me. She's not doing anything that affects anyone else.
So yeah I'm going to call her Caitlyn and refer to her as 'she' and all that. She hasn't gone by Bruce in ten years. My friend just got married and took her husband's last name. That doesn't make her biologically a Smith. But she's part of the family now so we're going to call her Smith. Caitlyn Jenner is not biologically a woman but as far as I'm concerned, refusing to acknowledge that she is living the way the rest of us do is just as silly as refusing to call my friend by her new last name. I can think it's a little weird, just like I'd think it was a little weird if my friend had decided to hyphenate her last name instead of just going with Smith, but so what?
I don't care what adults want to do with their own body and what they want to call themselves. I only care when they start to impose on others.
As far as all the other trans stuff goes...
I think there are a lot of kids who would have been goth or emo when I was growing up but these days are being told that they are probably trans or whatever. They just feel out of place and are searching for something that makes them feel understood. And while I don't really see the harm in letting them buy some new clothes and cut their hair a certain way to see if they feel better, there is no good reason for any medical procedures to be performed on them. I think there are a lot of well intentioned but misguided people trying to help them and I think there are a lot of sick fucks trying to take advantage for politics or profit.
I think there are also a lot more sick fucks who like to pretend to be trans whenever it's convenient and gives them access to someone they can prey upon. But let's just be adults here for a second - I'm pretty sure we can all tell the difference between someone like Caitlyn Jenner and some creep that just got convicted of raping four women and has decided suddenly that he would like to serve his sentence in the women's prison. Come on.
Locker rooms, bathrooms, and prisons are sex segregated for a reason and should stay that way. I would be perfectly happy to see some more gender neutral locker rooms and bathrooms in addition to the women's and men's rooms - but I am vehemently opposed to making either one of those the new gender neutral space.
I am not going to entertain the idea that transwomen are identical to the rest of us. Sports are sex segregated for a reason as well. I don't really know what would be fair to trans athletes but I know for sure that making the women's team the 'everyone team' is not fair to anyone. Anyone pushing that is just willfully blinded by politics.
I am not going to refer to mothers as 'birthing people' or gynecology patients as 'people with vaginas' or any of that nonsense. I am also not going to say 'people with two legs' to be sensitive to people who have fewer. We all know what we're talking about and if you are offended by your own differences, then I'm sorry but that's not something some sparkly new language is going to fix for you. I'm certainly not going to entertain the idea of changing the definition of 'woman.' I'm not going change how I refer to myself to appease anyone else. I will call you whatever name you want but you don't get to redefine who I am.
And if you pick a really stupid name or fake pronoun for yourself, don't be shocked when someone makes fun of it the way we all make fun of Xitter or some millennial naming her kid MacKeighleigh.
But here's the other thing about Caitlyn Jenner - she is not any of those people. Actually I don't think most trans people are any of those people. I think almost all of that garbage comes from people who are misappropriating the label or who fancy themselves activists and they're giving the actual trans community a bad rap. I think most trans people are pretty normal aside from the obvious.
We have a handful of legitimate issues to work out in regards to the bathrooms and sports and I'm sure that is a little uncomfortable to have to hash out but I think if we stop trying to be assholes on purpose, we can figure it out.
8 notes · View notes
emocka · 2 years
Text
Lines about y/n and how the guys admire her
Aether: y/n is a great person and I love her. How they manage everyday life while blind amazes me...what do you mean? She asking why I choose her out of everyone else to date? She beautiful fun and I feel the need to protect her....I don't know when ill pop the question...no! It'll be a private one!
Xiao: she annoying...im aware were married still annoying. Im impressed that she doesn't let her disability stop her from fighting....her Phoenix form is nice.....what? I don't know what your talking about. She can get around by herself just fine. If she can throw a book at someone bothering her she fine. No need for me to guide her around. She the same age as me.
Kazuha: she's wonderful. The fact that she manages to take in account of her condition makes her a great person....yes she still recovering from the attack....oh you mean the kitsune made of anemo? I don't mind it but it does take away quality time when if guides her around...oh here she comes.
Gorou: I love her for everything she does. Yea we fought in the past but things have changed....what? She has adeptus blood that why she has the cats ears? So what?...who told you that? Fine yes it true I wrap my tail around her waist when we walk around watasumi Island on dates. Besides I don't want her walking off places. She still adjust to her condition and doing the best she can.
Ayato: that sly little princess of mine you say? How does she pull her prank while blind? Well she has enhanced hearing and a great sense of smell....how was she able to enjoy the wedding? How did she find the right kimono? My sister helped find one as for the first question it was a small one before the decree was issued we only invited ten people to watch us exchange our vows....hm? How does she manage to use her polearm? I don't know but archon knows I don't want to be on the other end of her and that weapon.
Scaramouche: I don't know how she managed to set the building on fire but I grew to respect her after that....no I still won't show her around. Tartaglia lies i never walked around with her and she never took my hat.....ok fine it was a one time thing....who told you?!! We don't sleep in the same bed!...I don't know how she manages the claymore while blind and I do not care to know.
Diluc: she a fine wife and I love her....how does she know what stage the baby is in? The nuns make a model and she is able to touch it....oh you mean the colorless vision she has on the necklace. Its a old friends who died protecting her. They were able to keep her safe but lost their life doing it.....yes she still beats herself up over that....yea it was small but they should have been able to guess we were married. She did take my last name and hyphen it with hers...yes I let her keep her last name.
Childe: I don't know how she does it while blind but she kicked my butt several times already. Yea I was their when she got her vision. Randomly fell on her head knocking her out in the process....oh the catalyst she uses? That a one of a kind. No one can replicate it. It a old family weapon passed down. Her family specialized in the stars so she always fight with the zodiac constellations when in battle. Ooooh I wanna see if I can beat her this time!!! And she not allowed to use the Aquarius constellation!! HEY Y/N FIGHT ME!!
Zhongli: ah y/n she been around since the seven rose to victory.She earned the right to be call the queen of the flowers....hm? How does she manage to wield the bow? I wonder too but it probably best i don't know. Yes she was involved in the war 500 years ago. She was the only one who could protect the children in the woods that day. She was also the one who took care of the fallen and heal with wounded...yes she has ridden my dragon form....what her form? I believe its a crystalfly.....oh its not? Oh its a crane. I haven't see her crane from in a long time....oh I suspect her family has always had the ability to take on the form of animals.
Itto: oh y/n? I don't know how she does it but she s great fighter? N-no! I do not love her....ok so maybe I'm a big dummy for an oni but yes I fell in love.
Kaeya: oh your asking how she got her vision even though she can't see? She was very determined to prove people wrong and mastered the sword. I was there when it showed up in her hands....I call her firefly because her vision glows so brightly it looks like a red firefly.
Albedo: y/n? She very beautiful. I have offered her to find a cure for her condition but she said no....oh you mean the beast that follows her? I drew that and brought it to life....why? She still learning how to wield the catalyst. It helps guide her around and defend her....love? So that what I feel when I see her....oh? She's coming?
11 notes · View notes
suzanneshannon · 5 years
Text
An Introduction and Guide to the CSS Object Model (CSSOM)
If you've been writing JavaScript for some time now, it's almost certain you've written some scripts dealing with the Document Object Model (DOM). DOM scripting takes advantage of the fact that a web page opens up a set of APIs (or interfaces) so you can manipulate and otherwise deal with elements on a page.
But there's another object model you might want to become more familiar with: The CSS Object Model (CSSOM). Likely you've already used it but didn't necessarily realize it.
In this guide, I'm going to go through many of the most important features of the CSSOM, starting with stuff that's more commonly known, then moving on to some more obscure, but practical, features.
What is the CSSOM?
According to MDN:
The CSS Object Model is a set of APIs allowing the manipulation of CSS from JavaScript. It is much like the DOM, but for the CSS rather than the HTML. It allows users to read and modify CSS style dynamically.
MDN's info is based on the official W3C CSSOM specification. That W3C document is a somewhat decent way to get familiar with what's possible with the CSSOM, but it's a complete disaster for anyone looking for some practical coding examples that put the CSSOM APIs into action.
MDN is much better, but still largely lacking in certain areas. So for this post, I've tried to do my best to create useful code examples and demos of these interfaces in use, so you can see the possibilities and mess around with the live code.
As mentioned, the post starts with stuff that's already familiar to most front-end developers. These common features are usually lumped in with DOM scripting, but they are technically part of the larger group of interfaces available via the CSSOM (though they do cross over into the DOM as well).
Inline Styles via element.style
The most basic way you can manipulate or access CSS properties and values using JavaScript is via the style object, or property, which is available on all HTML elements. Here's an example:
document.body.style.background = 'lightblue';
Most of you have probably seen or used that syntax before. I can add to or change the CSS for any object on the page using that same format: element.style.propertyName.
In that example, I'm changing the value of the background property to lightblue. Of course, background is shorthand. What if I want to change the background-color property? For any hyphenated property, just convert the property name to camel case:
document.body.style.backgroundColor = 'lightblue';
In most cases, a single-word property would be accessed in this way by the single equivalent word in lowercase, while hyphenated properties are represented in camel case. The one exception to this is when using the float property. Because float is a reserved word in JavaScript, you need to use cssFloat (or styleFloat if you're supporting IE8 and earlier). This is similar to the HTML for attribute being referenced as htmlFor when using something like getAttribute().
Here's a demo that uses the style property to allow the user to change the background color of the current page:
See the Pen Using the style Object to Change the Background Color by Louis Lazaris (@impressivewebs) on CodePen.
So that's an easy way to define a CSS property and value using JavaScript. But there's one huge caveat to using the style property in this way: This will only apply to inline styles on the element.
This becomes clear when you use the style property to read CSS:
document.body.style.backgroundColor = 'lightblue'; console.log(document.body.style.backgroundColor); // "lightblue"
In the example above, I'm defining an inline style on the <body> element, then I'm logging that same style to the console. That's fine. But if I try to read another property on that element, it will return nothing — unless I've previously defined an inline style for that element in my CSS or elsewhere in my JavaScript. For example:
console.log(document.body.style.color); // Returns nothing if inline style doesn't exist
This would return nothing even if there was an external stylesheet that defined the color property on the <body> element, as in the following CodePen:
See the Pen element.style Reads Only Inline Styles by Louis Lazaris (@impressivewebs) on CodePen.
Using element.style is the simplest and most common way to add styles to elements via JavaScript. But as you can see, this clearly has some significant limitations, so let's look at some more useful techniques for reading and manipulating styles with JavaScript.
Getting Computed Styles
You can read the computed CSS value for any CSS property on an element by using the window.getComputedStyle() method:
window.getComputedStyle(document.body).background; // "rgba(0, 0, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box"
Well, that's an interesting result. In a way, window.getComputedStyle() is the style property's overly-benevolent twin. While the style property gives you far too little information about the actual styles on an element, window.getComputedStyle() can sometimes give you too much.
See the Pen The getComputedStyle() Method Can Read any CSS Property by Louis Lazaris (@impressivewebs) on CodePen.
In the example above, the background property of the <body> element was defined using a single value. But the getComputedStyle() method returns all values contained in background shorthand. The ones not explicitly defined in the CSS will return the initial (or default) values for those properties.
This means, for any shorthand property, window.getComputedStyle() will return all the initial values, even if none of them is defined in the CSS:
See the Pen window.getComputedStyle() Returns All Longhand Values for a Shorthand Property by Louis Lazaris (@impressivewebs) on CodePen.
Similarly, for properties like width and height, it will reveal the computed dimensions of the element, regardless of whether those values were specifically defined anywhere in the CSS, as the following interactive demo shows:
See the Pen window.getComputedStyle() Returns Width and Height Values Even if Not Defined in the CSS by Louis Lazaris (@impressivewebs) on CodePen.
Try resizing the parent element in the above demo to see the results. This is somewhat comparable to reading the value of window.innerWidth, except this is the computed CSS for the specified property on the specified element and not just a general window or viewport measurement.
There are a few different ways to access properties using window.getComputedStyle(). I've already demonstrated one way, which uses dot-notation to add the camel-cased property name to the end of the method. You can see three different ways to do it in the following code:
// dot notation, same as above window.getComputedStyle(el).backgroundColor; // square bracket notation window.getComputedStyle(el)['background-color']; // using getPropertyValue() window.getComputedStyle(el).getPropertyValue('background-color');
The first line uses the same format as in the previous demo. The second line is using square bracket notation, a common JavaScript alternative to dot notation. This format is not recommended and code linters will warn about it. The third example uses the getPropertyValue() method.
The first example requires the use of camel casing (although in this case both float and cssFloat would work) while the next two access the property via the same syntax as that used in CSS (with hyphens, often called "kebab case").
Here's the same demo as the previous, but this time using getPropertyValue() to access the widths of the two elements:
See the Pen Using window.getComputedStyle() along with getPropertyValue() by Louis Lazaris (@impressivewebs) on CodePen.
Getting Computed Styles of Pseudo-Elements
One little-known tidbit about window.getComputedStyle() is the fact that it allows you to retrieve style information on pseudo-elements. You'll often see a window.getComputedStyle() declaration like this:
window.getComputedStyle(document.body, null).width;
Notice the second argument, null, passed into the method. Firefox prior to version 4 required a second argument, which is why you might see it used in legacy code or by those accustomed to including it. But it's not required in any browser currently in use.
That second optional parameter is what allows me to specify that I'm accessing the computed CSS of a pseudo-element. Consider the following CSS:
.box::before { content: 'Example'; display: block; width: 50px; }
Here I'm adding a ::before pseudo-element inside the .box element. With the following JavaScript, I can access the computed styles for that pseudo-element:
let box = document.querySelector('.box'); window.getComputedStyle(box, '::before').width; // "50px"
See the Pen Using getComputedStyle() to get styles from a pseudo-element by Louis Lazaris (@impressivewebs) on CodePen.
You can also do this for other pseudo-elements like ::first-line, as in the following code and demo:
let p = document.querySelector('.box p'); window.getComputedStyle(p, '::first-line').color;
See the Pen Using getComputedStyle() to get styles from a pseudo-element by Louis Lazaris (@impressivewebs) on CodePen.
And here's another example using the ::placeholder pseudo-element, which apples to <input> elements:
let input = document.querySelector('input'); window.getComputedStyle(input, '::placeholder').color
See the Pen Using getComputedStyle() to get styles from a ::placeholder pseudo-element by Louis Lazaris (@impressivewebs) on CodePen.
The above works in the latest Firefox, but not in Chrome or Edge (I've filed a bug report for Chrome).
It should also be noted that browsers have different results when trying to access styles for a non-existent (but valid) pseudo-element compared to a pseudo-element that the browser doesn't support at all (like a made up ::banana pseudo-element). You can try this out in various browsers using the following demo:
See the Pen Testing getComputedStyle() on non-existent pseudo-elements by Louis Lazaris (@impressivewebs) on CodePen.
As a side point to this section, there is a Firefox-only method called getDefaultComputedStyle() that is not part of the spec and likely never will be.
The CSSStyleDeclaration API
Earlier when I showed you how to access properties via the style object or using getComputedStyle(), in both cases those techniques were exposing the CSSStyleDeclaration interface.
In other words, both of the following lines will return a CSSStyleDeclaration object on the document's body element:
document.body.style; window.getComputedStyle(document.body);
In the following screenshot you can see what the console produces for each of these lines:
Tumblr media
In the case of getComputedStyle(), the values are read-only. In the case of element.style, getting and setting the values is possible but, as mentioned earlier, these will only affect the document's inline styles.
setProperty(), getPropertyValue(), and item()
Once you've exposed a CSSStyleDeclaration object in one of the above ways, you have access to a number of useful methods to read or manipulate the values. Again, the values are read-only in the case of getComputedStyle(), but when used via the style property, some methods are available for both getting and setting.
Consider the following code and demo:
let box = document.querySelector('.box'); box.style.setProperty('color', 'orange'); box.style.setProperty('font-family', 'Georgia, serif'); op.innerHTML = box.style.getPropertyValue('color'); op2.innerHTML = `${box.style.item(0)}, ${box.style.item(1)}`;
See the Pen Using Three Different Methods of the CSSStyleDeclaration API by Louis Lazaris (@impressivewebs) on CodePen.
In this example, I'm using three different methods of the style object:
The setProperty() method. This takes two arguments, each a string: The property (in regular CSS notation) and the value you wish to assign to the property.
The getPropertyValue() method. This takes a single argument: The property whose value you want to obtain. This method was used in a previous example using getComputedStyle(), which, as mentioned, likewise exposes a CSSStyleDeclaration object.
The item() method. This takes a single argument, which is a positive integer representing the index of the property you want to access. The return value is the property name at that index.
Keep in mind that in my simple example above, there are only two styles added to the element's inline CSS. This means that if I were to access item(2), the return value would be an empty string. I'd get the same result if I used getPropertyValue() to access a property that isn't set in that element's inline styles.
Using removeProperty()
In addition to the three methods mentioned above, there are two others exposed on a CSSStyleDeclaration object. In the following code and demo, I'm using the removeProperty() method:
box.style.setProperty('font-size', '1.5em'); box.style.item(0) // "font-size" document.body.style.removeProperty('font-size'); document.body.style.item(0); // ""
See the Pen Using the removeProperty() method of the CSSSTyleDeclaration API by Louis Lazaris (@impressivewebs) on CodePen.
In this case, after I set font-size using setProperty(), I log the property name to ensure it's there. The demo then includes a button that, when clicked, will remove the property using removeProperty().
In the case of setProperty() and removeProperty(), the property name that you pass in is hyphenated (the same format as in your stylesheet), rather than camel-cased. This might seem confusing at first, but the value passed in is a string in this example, so it makes sense.
Getting and Setting a Property's Priority
Finally, here's an interesting feature that I discovered while researching this article: The getPropertyPriority() method, demonstrated with the code and CodePen below:
box.style.setProperty('font-family', 'Georgia, serif', 'important'); box.style.setProperty('font-size', '1.5em'); box.style.getPropertyPriority('font-family'); // important op2.innerHTML = box.style.getPropertyPriority('font-size'); // ""
See the Pen Using getPropertyPriority() to get a property's "importance" by Louis Lazaris (@impressivewebs) on CodePen.
In the first line of that code, you can see I'm using the setProperty() method, as I did before. However, notice I've included a third argument. The third argument is an optional string that defines whether you want the property to have the !important keyword attached to it.
After I set the property with !important, I use the getPropertyPriority() method to check that property's priority. If you want the property to not have importance, you can omit the third argument, use the keyword undefined, or include the third argument as an empty string.
And I should emphasize here that these methods would work in conjunction with any inline styles already placed directly in the HTML on an element's style attribute.
So if I had the following HTML:
<div class="box" style="border: solid 1px red !important;">
I could use any of the methods discussed in this section to read or otherwise manipulate that style. And it should be noted here that since I used a shorthand property for this inline style and set it to !important, all of the longhand properties that make up that shorthand will return a priority of important when using getPropertyPriority(). See the code and demo below:
// These all return "important" box.style.getPropertyPriority('border')); box.style.getPropertyPriority('border-top-width')); box.style.getPropertyPriority('border-bottom-width')); box.style.getPropertyPriority('border-color')); box.style.getPropertyPriority('border-style'));
See the Pen Using getPropertyPriority() to check the priority of longhand properties by Louis Lazaris (@impressivewebs) on CodePen.
In the demo, even though I explicitly set only the border property in the style attribute, all the associated longhand properties that make up border will also return a value of important.
The CSSStyleSheet Interface
So far, much of what I've considered deals with inline styles (which often aren't that useful) and computed styles (which are useful, but are often too specific).
A much more useful API that allows you to retrieve a stylesheet that has readable and writable values, and not just for inline styles, is the CSSStyleSheet API. The simplest way to access information from a document's stylesheets is using the styleSheets property of the current document. This exposes the CSSStyleSheet interface.
For example, the line below uses the length property to see how many stylesheets the current document has:
document.styleSheets.length; // 1
I can reference any of the document's stylesheets using zero-based indexing:
document.styleSheets[0];
If I log that stylesheet to my console, I can view the methods and properties available:
Tumblr media
The one that will prove useful is the cssRules property. This property provides a list of all CSS rules (including declaration blocks, at-rules, media rules, etc.) contained in that stylesheet. In the following sections, I'll detail how to utilize this API to manipulate and read styles from an external stylesheet.
Working with a Stylesheet Object
For the purpose of simplicity, let's work with a sample stylesheet that has only a handful of rules in it. This will allow me to demonstrate how to use the CSSOM to access the different parts of a stylesheet in a similar way to accessing elements via DOM scripting.
Here is the stylesheet I'll be working with:
* { box-sizing: border-box; } body { font-family: Helvetica, Arial, sans-serif; font-size: 2em; line-height: 1.4; } main { width: 1024px; margin: 0 auto !important; } .component { float: right; border-left: solid 1px #444; margin-left: 20px; } @media (max-width: 800px) { body { line-height: 1.2; } .component { float: none; margin: 0; } } a:hover { color: lightgreen; } @keyframes exampleAnimation { from { color: blue; } 20% { color: orange; } to { color: green; } } code { color: firebrick; }
There's a number of different things I can attempt with this example stylesheet and I'll demonstrate a few of those here. First, I'm going to loop through all the style rules in the stylesheet and log the selector text for each one:
let myRules = document.styleSheets[0].cssRules, p = document.querySelector('p'); for (i of myRules) { if (i.type === 1) { p.innerHTML += `<c​ode>${i.selectorText}</c​ode><br>`; } }
See the Pen Working with CSSStyleSheet - Logging the Selector Text by Louis Lazaris (@impressivewebs) on CodePen.
A couple of things to take note of in the above code and demo. First, I cache a reference to the cssRules object for my stylesheet. Then I loop over all the rules in that object, checking to see what type each one is.
In this case, I want rules that are type 1, which represents the STYLE_RULE constant. Other constants include IMPORT_RULE (3), MEDIA_RULE (4), KEYFRAMES_RULE (7), etc. You can view a full table of these constants in this MDN article.
When I confirm that a rule is a style rule, I print the selectorText property for each of those style rules. This will produce the following lines for the specified stylesheet:
* body main .component a:hover code
The selectorText property is a string representation of the selector used on that rule. This is a writable property, so if I want I can change the selector for a specific rule inside my original for loop with the following code:
if (i.selectorText === 'a:hover') { i.selectorText = 'a:hover, a:active'; }
See the Pen Working with the CSSStyleSheet API – Changing the Selector Text by Louis Lazaris (@impressivewebs) on CodePen.
In this example, I'm looking for a selector that defines :hover styles on my links and expanding the selector to apply the same styles to elements in the :active state. Alternatively, I could use some kind of string method or even a regular expression to look for all instances of :hover, and then do something from there. But this should be enough to demonstrate how it works.
Accessing @media Rules with the CSSOM
You'll notice my stylesheet also includes a media query rule and a keyframes at-rule block. Both of those were skipped when I searched for style rules (type 1). Let's now find all @media rules:
let myRules = document.styleSheets[0].cssRules, p = document.querySelector('.output'); for (i of myRules) { if (i.type === 4) { for (j of i.cssRules) { p.innerHTML += `<c​ode>${j.selectorText}</c​ode><br>`; } } }
Based on the given stylesheet, the above will produce:
body .component
See the Pen Working with the CSSStyleSheet API – Accessing @media Rules by Louis Lazaris (@impressivewebs) on CodePen.
As you can see, after I loop through all the rules to see if any @media rules exist (type 4), I then loop through the cssRules object for each media rule (in this case, there's only one) and log the selector text for each rule inside that media rule.
So the interface that's exposed on a @media rule is similar to the interface exposed on a stylesheet. The @media rule, however, also includes a conditionText property, as shown in the following snippet and demo:
let myRules = document.styleSheets[0].cssRules, p = document.querySelector('.output'); for (i of myRules) { if (i.type === 4) { p.innerHTML += `<c​ode>${i.conditionText}</c​ode><br>`; // (max-width: 800px) } }
See the Pen Working with the CSSStyleSheet API – Accessing @media Rules by Louis Lazaris (@impressivewebs) on CodePen.
This code loops through all media query rules and logs the text that determines when that rule is applicable (i.e. the condition). There's also a mediaText property that returns the same value. According to the spec, you can get or set either of these.
Accessing @keyframes Rules with the CSSOM
Now that I've demonstrated how to read information from a @media rule, let's consider how to access a @keyframes rule. Here's some code to get started:
let myRules = document.styleSheets[0].cssRules, p = document.querySelector('.output'); for (i of myRules) { if (i.type === 7) { for (j of i.cssRules) { p.innerHTML += `<c​ode>${j.keyText}</c​ode><br>`; } } }
See the Pen Working with the CSSStyleSheet API – Accessing @keyframes Rules by Louis Lazaris (@impressivewebs) on CodePen.
In this example, I'm looking for rules that have a type of 7 (i.e. @keyframes rules). When one is found, I loop through all of that rule's cssRules and log the keyText property for each. The log in this case will be:
"0%" "20%" "100%"
You'll notice my original CSS uses from and to as the first and last keyframes, but the keyText property computes these to 0% and 100%. The value of keyText can also be set. In my example stylesheet, I could hard code it like this:
// Read the current value (0%) document.styleSheets[0].cssRules[6].cssRules[0].keyText; // Change the value to 10% document.styleSheets[0].cssRules[6].cssRules[0].keyText = '10%' // Read the new value (10%) document.styleSheets[0].cssRules[6].cssRules[0].keyText;
See the Pen Working with the CSSStyleSheet API – Setting @keyframes Rules by Louis Lazaris (@impressivewebs) on CodePen.
Using this, we can dynamically alter an animation's keyframes in the flow of a web app or possibly in response to a user action.
Another property available when accessing a @keyframes rule is name:
let myRules = document.styleSheets[0].cssRules, p = document.querySelector('.output'); for (i of myRules) { if (i.type === 7) { p.innerHTML += `<c​ode>${i.name}</c​ode><br>`; } }
See the Pen Working with the CSSStyleSheet API – Getting the name of a @keyframes rule by Louis Lazaris (@impressivewebs) on CodePen.
Recall that in the CSS, the @keyframes rule looks like this:
@keyframes exampleAnimation { from { color: blue; } 20% { color: orange; } to { color: green; } }
Thus, the name property allows me to read the custom name chosen for that @keyframes rule. This is the same name that would be used in the animation-name property when enabling the animation on a specific element.
One final thing I'll mention here is the ability to grab specific styles that are inside a single keyframe. Here's some example code with a demo:
let myRules = document.styleSheets[0].cssRules, p = document.querySelector('.output'); for (i of myRules) { if (i.type === 7) { for (j of i.cssRules) { p.innerHTML += `<c​ode>${j.style.color}</c​ode><br>`; } } }
See the Pen Working with the CSSStyleSheet API – Accessing Property Values inside @keyframes Rules by Louis Lazaris (@impressivewebs) on CodePen.
In this example, after I find the @keyframes rule, I loop through each of the rules in the keyframe (e.g. the "from" rule, the "20%" rule, etc). Then, within each of those rules, I access an individual style property. In this case, since I know color is the only property defined for each, I'm merely logging out the color values.
The main takeaway in this instance is the use of the style property, or object. Earlier I showed how this property can be used to access inline styles. But in this case, I'm using it to access the individual properties inside of a single keyframe.
You can probably see how this opens up some possibilities. This allows you to modify an individual keyframe's properties on the fly, which could happen as a result of some user action or something else taking place in an app or possibly a web-based game.
Adding and Removing CSS Declarations
The CSSStyleSheet interface has access to two methods that allow you to add or remove an entire rule from a stylesheet. The methods are: insertRule() and deleteRule(). Let's see both of them in action manipulating our example stylesheet:
let myStylesheet = document.styleSheets[0]; console.log(myStylesheet.cssRules.length); // 8 document.styleSheets[0].insertRule('article { line-height: 1.5; font-size: 1.5em; }', myStylesheet.cssRules.length); console.log(document.styleSheets[0].cssRules.length); // 9
See the Pen Working with the CSSStyleSheet API – Inserting Rules by Louis Lazaris (@impressivewebs) on CodePen.
In this case, I'm logging the length of the cssRules property (showing that the stylesheet originally has 8 rules in it), then I add the following CSS as an individual rule using the insertRule() method:
article { line-height: 1.5; font-size: 1.5em; }
I log the length of the cssRules property again to confirm that the rule was added.
The insertRule() method takes a string as the first parameter (which is mandatory), comprising the full style rule that you want to insert (including selector, curly braces, etc). If you're inserting an at-rule, then the full at-rule, including the individual rules nested inside the at-rule can be included in this string.
The second argument is optional. This is an integer that represents the position, or index, where you want the rule inserted. If this isn't included, it defaults to 0 (meaning the rule will be inserted at the beginning of the rules collection). If the index happens to be larger than the length of the rules object, it will throw an error.
The deleteRule() method is much simpler to use:
let myStylesheet = document.styleSheets[0]; console.log(myStylesheet.cssRules.length); // 8 myStylesheet.deleteRule(3); console.log(myStylesheet.cssRules.length); // 7
See the Pen Working with the CSSStyleSheet API – Deleting Rules by Louis Lazaris (@impressivewebs) on CodePen.
In this case, the method accepts a single argument that represents the index of the rule I want to remove.
With either method, because of zero-based indexing, the selected index passed in as an argument has to be less than the length of the cssRules object, otherwise it will throw an error.
Revisiting the CSSStyleDeclaration API
Earlier I explained how to access individual properties and values declared as inline styles. This was done via element.style, exposing the CSSStyleDeclaration interface.
The CSSStyleDeclaration API, however, can also be exposed on an individual style rule as a subset of the CSSStyleSheet API. I already alluded to this when I showed you how to access properties inside a @keyframes rule. To understand how this works, compare the following two code snippets:
<div style="color: lightblue; width: 100px; font-size: 1.3em !important;"></div>
.box { color: lightblue; width: 100px; font-size: 1.3em !important; }
The first example is a set of inline styles that can be accessed as follows:
document.querySelector('div').style
This exposes the CSSStyleDeclaration API, which is what allows me to do stuff like element.style.color, element.style.width, etc.
But I can expose the exact same API on an individual style rule in an external stylesheet. This means I'm combining my use of the style property with the CSSStyleSheet interface.
So the CSS in the second example above, which uses the exact same styles as the inline version, can be accessed like this:
document.styleSheets[0].cssRules[0].style
This opens up a single CSSStyleDeclaration object on the one style rule in the stylesheet. If there were multiple style rules, each could be accessed using cssRules[1], cssRules[2], cssRules[3], and so on.
So within an external stylesheet, inside of a single style rule that is of type 1, I have access to all the methods and properties mentioned earlier. This includes setProperty(), getPropertyValue(), item(), removeProperty(), and getPropertyPriority(). In addition to this, those same features are available on an individual style rule inside of a @keyframes or @media rule.
Here's a code snippet and demo that demonstrates how these methods would be used on an individual style rule in our sample stylesheet:
// Grab the style rules for the body and main elements let myBodyRule = document.styleSheets[0].cssRules[1].style, myMainRule = document.styleSheets[0].cssRules[2].style; // Set the bg color on the body myBodyRule.setProperty('background-color', 'peachpuff'); // Get the font size of the body myBodyRule.getPropertyValue('font-size'); // Get the 5th item in the body's style rule myBodyRule.item(5); // Log the current length of the body style rule (8) myBodyRule.length; // Remove the line height myBodyRule.removeProperty('line-height'); // log the length again (7) myBodyRule.length; // Check priority of font-family (empty string) myBodyRule.getPropertyPriority('font-family'); // Check priority of margin in the "main" style rule (!important) myMainRule.getPropertyPriority('margin');
See the Pen Working with the style object of an individual style rule in an external Stylesheet by Louis Lazaris (@impressivewebs) on CodePen.
The CSS Typed Object Model... The Future?
After everything I've considered in this article, it would seem odd that I'd have to break the news that it's possible that one day the CSSOM as we know it will be mostly obsolete.
That's because of something called the CSS Typed OM which is part of the Houdini Project. Although some people have noted that the new Typed OM is more verbose compared to the current CSSOM, the benefits, as outlined in this article by Eric Bidelman, include:
Fewer bugs
Arithmetic operations and unit conversion
Better performance
Error handling
CSS property names are always strings
For full details on those features and a glimpse into the syntax, be sure to check out the full article.
As of this writing, CSS Typed OM is supported only in Chrome. You can see the progress of browser support in this document.
Final Words
Manipulating stylesheets via JavaScript certainly isn't something you're going to do in every project. And some of the complex interactions made possible with the methods and properties I've introduced here have some very specific use cases.
If you've built some kind of tool that uses any of these APIs I'd love to hear about it. My research has only scratched the surface of what's possible, but I'd love to see how any of this can be used in real-world examples.
I've put all the demos from this article into a CodePen collection, so you can feel free to mess around with those as you like.
The post An Introduction and Guide to the CSS Object Model (CSSOM) appeared first on CSS-Tricks.
An Introduction and Guide to the CSS Object Model (CSSOM) published first on https://deskbysnafu.tumblr.com/
0 notes