投稿時間:2022-02-28 17:42:26 RSSフィード2022-02-28 17:00 分まとめ(47件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
TECH Engadget Japanese Apple Watch Series 8(仮)は体温測定もできる?アクティビティ追跡も大幅進化か https://japanese.engadget.com/applewatch-series8-new-activity-features-073058248.html applewatch 2022-02-28 07:30:58
ROBOT ロボスタ Pepperの集客・接客向け提供プランがリニューアル 契約期間を1年間に短縮 1か月単位で利用できるスポットプランも登場 https://robotstart.info/2022/02/28/pepper-corporate-plan-renewal.html 2022-02-28 07:47:06
ROBOT ロボスタ NECが独自AI「模倣学習」をリハビリ介入プログラム作成支援に活用 北原病院の技術検証で立案の正確性が46%も向上 https://robotstart.info/2022/02/28/nec-ai-kitahara-hosp.html 2022-02-28 07:40:34
IT ITmedia 総合記事一覧 [ITmedia News] 保険金、電子マネーで受け取り可能に 損保ジャパンが5月提供予定 https://www.itmedia.co.jp/news/articles/2202/28/news168.html itmedia 2022-02-28 16:41:00
IT ITmedia 総合記事一覧 [ITmedia ビジネスオンライン] セブン、サンドイッチを5~12%値上げ 同時にリニューアル https://www.itmedia.co.jp/business/articles/2202/28/news156.html itmedia 2022-02-28 16:21:00
IT ITmedia 総合記事一覧 [ITmedia ビジネスオンライン] バンダイ、新卒の給与を30%引き上げ 全社員平均27%月収増へ https://www.itmedia.co.jp/business/articles/2202/28/news164.html itmedia 2022-02-28 16:20:00
IT ITmedia 総合記事一覧 [ITmedia PC USER] コクヨ、ノートPCにも対応したワークツール収納バッグ https://www.itmedia.co.jp/pcuser/articles/2202/28/news162.html bizrack 2022-02-28 16:07:00
IT ITmedia 総合記事一覧 [ITmedia Mobile] KDDI、5G SAでプレイステーションのゲームストリーミングと8K映像の配信に成功 https://www.itmedia.co.jp/mobile/articles/2202/28/news161.html itmediamobilekddi 2022-02-28 16:02:00
python Pythonタグが付けられた新着投稿 - Qiita Google ColaboratoryからBigQueryを実行する方法 https://qiita.com/shoku-pan/items/a40581344aed3b7e5f5c run関数は、実際にクエリを実行して結果をdataframeとして返す関数。 2022-02-28 16:48:33
python Pythonタグが付けられた新着投稿 - Qiita pythonでMetatrader5からヒストリカルデータをダウンロードする方法 https://qiita.com/komo135/items/5d97aef63ec683c4a151 pythonでMetatraderからヒストリカルデータをダウンロードする方法Metatraderのダウンロード、設定このリンクからMetatraderをダウンロードし、インストールしてください。 2022-02-28 16:29:44
js JavaScriptタグが付けられた新着投稿 - Qiita 【Vue】v-forで配列を指定回数だけループさせて出力させる https://qiita.com/minami0601/items/eac5057a6be675706466 いろいろと調べてみた結果配列をフィルタリングした後にvforでループさせれるvforとvifを組み合わせる上記点の記事が多くでてきました。 2022-02-28 16:43:47
js JavaScriptタグが付けられた新着投稿 - Qiita 【JavaScript】Mochaについて https://qiita.com/s_ryota/items/00e59a34461ed8b51f7f 上記のようにmocha自体はアサーションの機能がないため、今回はchaiを使用した。 2022-02-28 16:39:41
Ruby Rubyタグが付けられた新着投稿 - Qiita mysql5.7での所有権エラーを直そう!! https://qiita.com/jinkun/items/3d74b3f2a6eeeb2073a6 sudormrfmysqlsockmysqlsocklockプロセスを削除してください。 2022-02-28 16:23:29
Ruby Rubyタグが付けられた新着投稿 - Qiita 画面遷移するとjQueryが動かないときはTurbolinksが悪さをしているかもしれない https://qiita.com/Terao-Takumi/items/47c2cf931062d8d50ca2 documentreadyfunction処理これが意味するのは、「ページが読み込まれたら、以下のファンクションを起動します」というもので、謂わばトリガー条件を書いていることになる。 2022-02-28 16:15:52
AWS AWSタグが付けられた新着投稿 - Qiita 【ハンズオン】EC2のオンデマンドキャパシティ予約を行う手順 https://qiita.com/hamham/items/553424df17997e337289 また、インスタンスの利用資格に関して、「一致する詳細を持つ任意のインスタンス」を選択すると、「インスタンスの詳細」で設定したインスタイプ・OS・AZのECを起動した場合、自動的にキャパシティ予約の内数としてカウントされます。 2022-02-28 16:24:52
Ruby Railsタグが付けられた新着投稿 - Qiita 【Rails】Active Jobのテストの書き方 https://qiita.com/tomoronn3/items/1f1967a87cf5d9af0940 【Rails】ActiveJobのテストの書き方初めにActivejobのテストはEEテストですることができますが、job単体のテストをしたい時に書き方がわからなかったのでここに残しておきます。 2022-02-28 16:43:56
Ruby Railsタグが付けられた新着投稿 - Qiita mysql5.7での所有権エラーを直そう!! https://qiita.com/jinkun/items/3d74b3f2a6eeeb2073a6 sudormrfmysqlsockmysqlsocklockプロセスを削除してください。 2022-02-28 16:23:29
Ruby Railsタグが付けられた新着投稿 - Qiita 画面遷移するとjQueryが動かないときはTurbolinksが悪さをしているかもしれない https://qiita.com/Terao-Takumi/items/47c2cf931062d8d50ca2 documentreadyfunction処理これが意味するのは、「ページが読み込まれたら、以下のファンクションを起動します」というもので、謂わばトリガー条件を書いていることになる。 2022-02-28 16:15:52
技術ブログ KAYAC engineers' blog 既存リソースをTerraformでimportする作業を楽にする https://techblog.kayac.com/terraform-import-easier resourcetyperesourcenameidimport対象のリソースが定義ファイルに記述されていない場合はimportに失敗するため、必要に応じて空の定義を追加してimportします。 2022-02-28 16:45:38
技術ブログ Developers.IO Step Functions의 Error Handing를 해봤습니다. https://dev.classmethod.jp/articles/lim-stepfunctions-error/ Step Functions의Error Handing를해봤습니다 안녕하세요 임채정입니다 이번블로그에서는Step Functions의Error Handing에대해알아보고테스트해보겠습니다 Step Functions이뭔지알고싶으신분은아래블로그 2022-02-28 07:54:41
海外TECH DEV Community Exploring DevOps https://dev.to/mithlajkn/exploring-devops-274h devops 2022-02-28 07:44:10
海外TECH DEV Community Jest Testing like a Pro - Tips and tricks https://dev.to/dvddpl/jest-testing-like-a-pro-tips-and-tricks-4o6f Jest Testing like a Pro Tips and tricksWe recently switch to Jest framework when writing Unit and Integration tests in our React and Node applications We used Mocha many years ago and AVA for a few years Changing framework is no big deal once you are used to write tests or even better used to TDD extensively The fundamentals are the same in every framework and every programming language but there are some nuances Jest documentation is very extensive and detailed and I really suggest you reading it and going back to it every time you write a slightly more complex test or assertion but what I d like to share here is a recollection of tips and tricks that can hopefully save you some time and headaches ConcurrentThis is actually one of the main reasons I loved AVA tests are by default run concurrently and for a good reason Tests should not rely on external apis services they should not rely on globals or other objects that are persisted across different tests so why should not be run very slowly one after another when they could and should be run all the same time workers and thread permitting If for some reason and normally this happen only on integration tests we need to preserve a certain order then we can run them in a sequence serially In Jest it is the opposite You need to explicitly tell that a test should be run concurrently see here Each table In some case you have some tests which are basically the same but with slight variations You could create individual tests or you could use each table which basically will run a loop map over your table array and run the test with that specific payload eventually running the assertion on that specific expected result This is a very interesting feature but I would be careful because it is easy to be carried away by reusing and optimizing too much making tests more complicated than they need to be or simply ending up having many of unnecessary duplicated tests Imagine you want to test your sum method const sum a b gt a btest each add i i a b expected gt expect sum a b toBe expected Imho as good as this snippet is to explain how to use each table we should not write such a test Having multiple inputs for such thing would not add any value Unless our method has some weird logic like that over a certain sum the predefined maximum is always returned const cappedSum a b gt const cap const tot a b if tot gt cap return cap else return tot test each add i i a b expected gt expect cappedSum a b toBe expected Still in this case I would probably write simple tests which make this specific behaviour stand more out test Two integers are added if total is below the cap gt expect cappedSum toBe test Cap is always returned if sum of two integers is higher gt expect cappedSum toBe I d rather be redundant here to raise attention to the specifics of this method And also be clearer in case of a failing test Imagine that someone changes the value of the cap and your tests in your table start failing In the results you will find operation › add expect received toBe expected Object is equalityExpected Received which does not make much sense because gives and both the expected or received do not match and you would stare at the error message wondering what the heck Instead reading operation ›Cap is always returned if sum of two integers is higherexpect received toBe expected Object is equalityExpected Received clearly let you figure out that something is wrong with the cap and in this specific case that just the assertion and title are not updated with the updated code describe and generally about test names When you run Jest tests are run by file within that file you can have groups of related tests which you put under a Describe block Although seen in every example around describe is not mandatory so if you have a tiny file with just a bunch of tests you don t need really it In many cases though it is beneficial to group tests which share the same method under test and differ by the input and assertion Grouping and Naming properly is often underrated You must remember that tests suites are supposed to succeed and they can contain hundreds or thousands of tests When something goes wrong locally or on you CI Pipeline you want to be able to immediately have a grasp of what went wrong the more information you have in the test failure message the better The reader should understand your test without reading any other code Name your tests so well that others can diagnose failures from the name alone describe UserCreation gt it returns new user when creation is successful it throws an InvalidPayload error if name is undefined etcThe concatenation of file name describe test name together with the diff among expected and received values assuming you wrote specific enough assertions will allow you to immediately spot the issue and surgically intervene in seconds Imagine that your original implementation of create user returns a new user in this format name john surname doe id And your test will assert those properties it returns new user when creation is successful gt const expected id expect any Number name expect any String surname expect any String const result create expect result toMatchObject expected Reading such a failure message user manager ›UserCreation returns new user when creation is successfulexpect received toMatchObject expected FailingTest will clearly let anyone understand that your method is now returning an object just containing the ID of the new user not all its data I know naming it s hard but be precise and be disciplined in how you name and group your test files test suits and individual tests It will pay off whenever you have to debug a failing test On this topic I really suggest a very interesting article touching many aspects and pitfalls of writing Tests and why writing a test is fundamentally different than coding for production Why good developers write bad tests test structureWhether you are using Jest or not test structure should be clean and explicit Write your test in AAA Style which means Arrange Act Assert ArrangeSet up mock or db connection or service instance etcDefine inputDefine expectation ActRun the code under test passing the input Assertrun the assertion between the result and the expectation The most important thing is keeping the reader within the test following up a tip from the above article Don t worry about redundancy or helper methods Remember that people will go back to a test only when it starts failing and at that point it is important that the purpose of the test the set up and the error is understandable and debuggable quickly without having to click through many other variables or helper methods asyncIf the methods you want to test are asynchronous be it callbacks promises or async it is not a problem with Jest The biggest pitfall I d like to warn you about is when you forget to await or to add a return when you run your expectation This would cause your test to pass even if the asynchronous method is failing simply because Jest is not waiting and when the test fails it is already to late to notify it This happens very often if you jump from one sync test to another consider these examples it loads some data async gt const data await fetchData expect data toBe loaded it loads some data gt return expect fetchData toBe loaded They are similar and do the same thing In the first we are telling jest the test is async and we are awaiting for the method to return the loaded data then we run the assertion In the second example we just return the Expect If you forgot either the async await or the return the test will exit immediately way before the data is loaded and no assertion is done This is very dangerous because it could lead to false positives false positives toThrow and expect assertionIn some cases is useful to add a special Assertion in your test where you tell jest to count and make sure a certain number of expectations are run and passed This is extremely important in the case I mentioned above if you forget to return expect or await your async method But it is also useful if your test has assertions inside try catches or then catch Having assertions within catch blocks is not an approach I would suggest much better to use resolve rejects or other ways but sometimes I found it necessary like the example below it validates payload gt const p some payload that should fail const throwingFunc gt validate p expect throwingFunc toThrow ValidationError If I need to make more assertions on the Error being thrown beside just checking it s type class like ie making sure the error contains some specific inner properties or by regexing its detailed message and I don t want the method to be executed multiple times we need to catch the error and run assertion directly on it it validates payload gt const p some payload that should fail expect assertions try validate p catch error expect error toBeInstanceOf ValidationError expect error toHaveProperty details should have required property username email should match pattern S S If I don t put expect assertions and then for some reason the logic is the validation is changed so that the payload passes or instead of an error a true false is returned the test would pass silently just because jest did not know there were some assertions to run No assertion run means successful test async amp toThrowJust to spice up a bit assertions on errors just remember that when your method is asynchronous the expect syntax is a bit different Of course you can still rely on the catch block but still remember of await and expect assertions but the preferred approach is using rejects it throws USER ALREADY EXISTS when primary key is already in use async gt const p some payload whose Id is already in use const throwingFunc gt createItem p await expect throwingFunc rejects toThrow new RegExp Errors USER ALREADY EXISTS More info about testing Promises and Async code with resolve rejects here mocksMocking within Tests is a chapter per se and I have mixed feelings about it Too many times I have seen overly engineered abstractions with loads of classes and method with dependency injection were tested through super complicated tests where everything was mocked and stubbed Very high code coverage and everything green in the CI pipeline just to see production crash because well the mocks were not really matching reality This is also the reason why expecially with serverless I prefer when possible to have integration tests which hit the real thing not some weird dockerized emulator of some aws service This does not mean we never used aws sdk mock haven t tried yet this version for SDK v check this article for more info but in general I try to write very simple unit tests and very simple integration tests keeping mocks to a minimum If you are a Mock Advocate I really suggest reading Mocking is a code smell by Eric Elliot which few years ago really blew my mind Going back to Mocks in Jest If you just started with Mocks you may look at the documentation and then stare at the code and ask yourself Eh Why What s the point How are you supposed to use that Asserting on the mocked method would make no sense So this bring us to a broader topic that can lead us to dependency injection and inversion of control Using mocks can be hard and tricky because often our methods are just too coupled together and you have no access on the internal methods being used Imagine a method that validates some data creates a payload and passes it to an api to create a user then maps the result or catches errors and returns it const createUser data gt validate data build payload call api then map result to our needs catch and handle results from api If you want to create a Test for this you don t want to invoke the real API and create the user for real for multiple reasons the test could become flaky and depend on network issues or API availability you don t want to unnecessarily creates users which you will have to tear down delete afterwards you don t want to spam endpoint with invalid payloads to test all possible errors This is where mocking comes handy BUT how do you access that internal method that calls the api Some may use Rewire to access internals of a module and overwrite them or you can expose those specific methods in different modules and then mock their implementation or you can rely on dependency injection and closures to decouple the behaviour and then easily mock it without too many headaches const createUser api gt data validate data build payload api call payload lt now this can be the real thing or a mock we don t know and don t care then map result to our needs catch and handle results from api To use that you first partially apply your method injecting the api classconst api new rdPartyApi const userCreatorFunc api then use the real creator function which expects only the payload that is your original method under test userCreatorFunc myData So how do you mock your api const input username john const response ts Date now id name john const apiMock create jest fn mockReturnValue Promise resolve response const createdUser await createUser apiMock input const objToMatch id expect any Number userName expect any String registrationDate expect any Date some other formatting and properties or data manipulation done in our method when we get the response expect createdUser toMatchObject objToMatch From here you can easily mock the faulty responses and make sure you handle everything properly without relying on network nor bothering the real API at all Mocking can go deeper and further you can assert that the mocked method is called and with which parameters imaging you have some conditionals in your method which might or might not call the api based on certain input and so on Honestly for the reasons above I am not a super fan of such mocking Strike a balance and keep it simple When you see it is getting too complicated you are probably doing it wrong And it is likely the case you should refactor your method in the first place keeping things simple is also one of the reasons why TDD is so good you start small with the tests and the code naturally evolves in a way that is simple logical decouple and easy to test Just dropping here a mock example of Axios calls which might be useful if you don t want or can t refactor your code to inject your external dependencies doing network calls import axios from axios test should throw an error if received a status code other than async gt ts ignore axios post mockImplementationOnce gt Promise resolve status statusText Bad Request data config headers as AxiosResponse const user await createUser input In this example if your createUser method uses axios to invoke an api you are mocking axios entirely so that the requests will not be made but your mocked response will be triggered toMatchObject amp property matchersOften we want to assert that our method returns a specific object but we don t want to hardcode lots of values in our setup assertion Or we don t care to assert every single property in the object which is returned Imagine some dynamic values like Ids or dates timestamps and so on In this case asserting for equality would cause the error to fail toMatchObject is here very handy const result createRandomUser davide const expected name davide email expect stringContaining isVerified expect any Boolean id expect any Number lastUpdated expect any Date countryCode expect stringMatching A Z result might contain some other props we are not intersted in asserting expect result toMatchObject expected Using toMatchObject in combination with other expect globals like ANY is very powerful to have tests that are generic enough but still validate the type of object being returned todoMarking a test as TODO is very handy when you are jotting down ideas of possible test scenarios or if you are preparing a list of tests for a junior dev or trainee you are mentoring or simply to leave a trace of possible improvements technical debt onlyOnly can be used when debugging a test Be very careful when committing after you are done You might screw the entire Build pipeline and even risk putting something broken in production because the only tests you are actually running are well those that you marked as only To avoid such problems you can use a git hook check Husky and DotOnlyHunter which scans your tests making sure you are not pushing any test where you forgot to remove only failingthis is actually a feature I am missing in jest which was available in AVASometimes a test is failing but for some reason you want to keep it without just skipping it When if the implementation is fixed you are notified that the failing test now is succeeding I can t tell you when and why I used that but I found it very useful and apparently I am not the only one since there is github issue about it Until the issue is closed we have to use a simple skip use the debuggerThis is valid basically for every step of your development process Drop those console log s and start to use the Debugger and Breakpoints no matter what your IDE is here an example for VisualStudioCode this allows to interrupt the running code and expect props and methods and move step by step in the execution A very useful fast and pratical way of understanding what is really going on remember to make your test fail It does not matter if you are doing TDD Test Driven Development meaning you write the tests before you wrote while writing the implementation or writing tests for code you just wrote or you are refactoring Make sure your test fails If you wrote a test and it passes don t just move on taking for granted hoping everything is ok Maybe your assertion is broken maybe Jest is not awaiting your result maybe the edge case you thing you are testing is not really ending up in the code you implemented Prove that your assertion is working and your assumption is correct by having the test failing first ie by passing the wrong payload and then adjust the Arrange part of the test to make it work again Kent C Dodds has a very clear video explanation on how to do that Hope it helps If you have other tips feel free to comment below 2022-02-28 07:19:30
海外TECH DEV Community Amit Zacker portfolio https://dev.to/amitzacker/amit-zacker-portfolio-14pp zacker 2022-02-28 07:02:47
海外TECH DEV Community A Complete Guide To Using CSS Custom Variables https://dev.to/austin642/a-complete-guide-to-using-css-custom-variables-3ohi A Complete Guide To Using CSS Custom VariablesSometimes in CSS values tend to show up multiple times or repeat themselves throughout your code Imagine if you have a much bigger style sheet file you will have to keep reusing these values again and again That s pretty stressful right Well at some point you might want to change every occurrence of a particular value I know you may be asking “can t i just do a find and replace Doing a find and replace will work but there is a much easier way you can change these values and that is where CSS variables come in OutlineThe Basics Of CSS VariablesWhat Are CSS VariablesInheritance Working with Invalid Variables and Fallback ValuesUsing CSS Variables With Inline StylesStoring Single and Multiple Values What You Should Know About CSS VariablesUsing Variables With Media QueriesConclusion The Basics Of CSS VariablesWhat Are CSS VariablesCSS custom variables also known as CSS variables or cascading variables are entities that contain specific values that can be reused throughout a document It is usually set using a custom property notion for example main color black and can be accessed using the var function color var main color When looking at the style sheet below you will notice that there are some values of some elements that keep repeating themselves For example the border radius the color b which we have on the border of the button background color main color for our anchor tags and down on the inverse button and for the images we also use the width and height of rem btn text decoration none color white background color b display inline block padding px border radius px border px solid b btn inverse background color white border color b color b table img width rem height rem border radius Now if you notice these values show up multiple times To get started you have to define your variables inside the root pseudo class and this applies to the entire HTML document root To define a variable you will have to start with a double hyphen and then you input the name of the variable next For instance color primary then put in the value Lets say the b color root color primary b You have now justified the variable by doing this The next thing is to use the variable in your CSS code by replacing that value with var open parenthesis and then you put the name of your variable inside a color var color primary This will make all the anchor links for example to be defined by the variable Remember that color b is also the main color for the anchor tags The awesome thing about this is that you can easily replace the value with another value For instance you can replace the color b with let s say Yellow and all the elements that use that variable will get updated Now instead of find and replace you can just replace all the b or colors in your CSS codes with your variable var color primary Now if you change the color value to let s say yellow every thing else changes to yellow That s pretty awesome right root color primary yellow Let s transform something else into a variable like a border radius for example You can define another variable by imputing borer radius with pixels root color primary b global radius px All you have to do now is replace the border radius with var global radius btn text decoration none color white background color b display inline block padding px border radius var global radius border px solid b card max width rem background color white padding rem border radius var global radius box shadow px px px rgba If you go to border radius and change the value from px to maybe px you will notice the cards and buttons updating automatically As for the case of browser compatibility if you open caniuse you can check the browsers that are compatible with the CSS variables as shown in the image below In this image you can see that it is supported in most of the browsers well except in internet explorer Inheritance Inheritance controls what happens when there is no value specified for a property on an element lt body gt lt div gt lt p gt Hello lt p gt lt h gt Text lt h gt lt body gt Now if you apply styles to the body tag then everything within the body tag will inherit those styles Let s assume we want everything under the body tag to have a font color of blue all you have to do is body color blue and everything under the body tag turns blue Pretty cool right well that s because everything within the body are inheriting that style Let s now say we want everything under the lt div gt tag to be yellow you can do this body color blue div color yellow and everything in the lt div gt tags overrides the inherited styles of the lt body gt tag and turns yellow while the rest remains blue So what if you want only the lt p gt tag to be green even though they already have the lt div gt tag of yellow Well you can just do this body color blue div color yellow p color green Working With Invalid Variables and Fallback ValuesWe are going to be learning what happens when certain CSS variables are invalid and how the browser is going to deal with this coupled with how to provide fallback values for CSS variables Let s get started lt P gt learning css variables lt p gt then inside the CSS you can write this root color rem As you can see this is invalid and we are going to see how the browser deals with it root color rem body display flex height vh align items center justify content center p max width color var color at this point nothing happens because the color variable is invalid i e it has an invalid value for the color property Now the browser checks if the color property can be inherited So it looks at its parents to see if there is a color defined there If you notice the body which is the parent element of the lt P gt tag does not have a color defined In this case the browser will go back to the initial value of the color which is black so the text still appears black Even if you were to set a color of green in the tag it still won t work because of the cascading nature of CSS However let s say we defined color of blue in the body root color rem body display flex height vh align items center justify content center color blue p max width color var color Now the text changes to blue because we have defined the color off the body If you remove the blue the browser will automatically revert to the initial color which is black Hopefully you understood this I am now going to show you how to define some fallback values for CSS variables This is a simple mark up below lt ul class menu gt lt li gt lt i class far fa bell gt lt i gt lt li gt lt li gt lt i class far fa bookmark gt lt i gt lt li gt lt li gt lt i class far fa calendar gt lt i gt lt li gt lt ul gt then for the CSS i added some demo styles for the body body display flex height vh flex direction column gap rem align items center justify content center the next thing is to define our menu by defining some variables body display flex height vh flex direction column gap rem align items center justify content center menu item size rem font size px item color black item color green list style none padding margin display flex gap calc var item size font size var font size trust me it gets interesting from here Now I am going to do this body display flex height vh flex direction column gap rem align items center justify content center menu item size rem font size px item color black item color green list style none padding margin display flex gap calc var item size font size var font size menu li background color var item color red color white width var item size height var item size text align center line height var item size border radius px Now if you are going to use the var function like this by adding a second parameter what you are saying is use item color if it is defined otherwise use the color red So if item color was not defined item color red does not exist You can even do menu li background color var item color blue color white width var item size height var item size text align center line height var item size border radius px what this means is that you can say var and inside the var you are saying if item color does not exist then use item color and if that does not exist use another color e g blue if item color was not defined it uses item color If item color was not defined it uses the fallback which is blue Note that this is not a solution for invalid variables Therefore you cannot use this fallback to fix invalid variables Using CSS Variables With Inline StylesUsing inline styles in production is not recommended in the final stages of your code but it can break the CSS specificity that you defined in your style sheet Although you can use inline styles during development or testing So I will be showing you how variables can help you Lets check out the simple grid i designed below in HTML lt div class grid gt lt div class grid item gt lt img src k amp m amp s a amp w amp h mKM VHxQKNlojPiGmcIRERgtRqMqfPZhnKN gt lt div gt lt div class grid item gt lt img src k amp m amp s a amp w amp h mKM VHxQKNlojPiGmcIRERgtRqMqfPZhnKN gt lt div gt lt div gt Then i have the CSS grid display grid grid template columns repeat auto fill minmax var column width fr grid gap var gap margin button rem grid item background color ae color white display flex align item center justify content center padding rem img width var avatar size height var avatar size border radius border px solid white all you have to do here is define the actual variables and we are going to define them in the root root avatar size rem column width rem gap calc var column width Now let s say during development or during testing you can play around with different values for the grid without opening up the CSS file again You can do this from your browser or HTML using inline styles as seen in the example below lt div class grid style column width rem gt lt div class grid item gt lt img src k amp m amp s a amp w amp h mKM VHxQKNlojPiGmcIRERgtRqMqfPZhnKN gt lt div gt lt div class grid item gt lt img src k amp m amp s a amp w amp h mKM VHxQKNlojPiGmcIRERgtRqMqfPZhnKN gt lt div gt lt div gt You can now play around with the size here For instance you can change the size from rem to rem depending on which one you want to work with Why this is cool is because you don t have to change anything in your CSS file Note please do not use this in your final code Storing Single and Multiple Values In this lesson you will learn about what values you can store inside a CSS variable You will see that you can store multiple values in the same variable Let s start with this simple HTML which is a card with a paragraph and a button inside lt div class card gt lt h gt How are you today lt h gt lt p gt i am fine thank you lt p gt lt a href a class btn gt close window lt a gt lt div gt let s write the CSS body display flex height vh align items center justify content center background color ececec line height CSS variables are not just for holding numbers pixel values or colors They are also capable of holding gradients for example root body bg linear gradient deg ae ecfc body display flex height vh align items center justify content center background color ececec line height now you can go into your body and say root body bg linear gradient deg ae ecfc body background image var body bg display flex height vh align items center justify content center background color ececec line height as i stated above variables are capable of holding multiple values i will be demonstrating with another example using button color root body bg linear gradient deg ae ecfc button color body background image var body bg display flex height vh align items center justify content center background color ececec line height btn background color rgb var button color display inline block color white padding rem rem text decoration none border radius px as you can see you can use the and define the color as rgb What You Should Know About CSS variablesUsing CSS Variables With Media Queries and JavaScriptIn this lesson you are going to learn how to use CSS variables inside media queries and how to change their value with JavaScript For the HTML we are going to use a simple grid lt div class grid gt lt div class grid item gt lt div gt lt div class grid item gt lt div gt lt div class grid item gt lt div gt lt div class grid item gt lt div gt lt div class grid item gt lt div gt lt div gt for the CSS body padding rem grid grid item color ecfc column width gap rem display grid grid template column repeat auto fill minmax var column width fr grid gap var gap grid item background color var grid item color color white display fle align items center padding rem Now this version of the grid will work on all screen sizes but what if you want to split up into multiple columns when it reaches or surpasses a certain screen width all you have to do is use media query as shown in the example below body padding rem grid grid item color ecfc column width gap rem display grid grid template column repeat auto fill minmax var column width fr grid gap var gap grid item background color var grid item color color white display fle align items center padding rem media screen and min width px grid column width rem gap calc var column width Now when we go past pixels you see the changes in the grid from the stacked version to using actual columns all thanks to the media query Now what about JavaScript you can read CSS variables from JavaScript and you can change the color Let me show you in the example below let targetElem document querySelector grid targetElem style setProperty grid item color purple Now you can see that when we go back to the original code i e the one outside the media query it actually changes the color to whatever color you want you can change the purple color to yellow ConclusionWhat I have done in this article is to explain what CSS variables mean and how to use them in your style sheet file In the aspect of web development speed and flexibility is very important and CSS variables helps with these If you implement your CSS variables properly it will make your code more readable and accessible and still provide a semantic meaning to your values 2022-02-28 07:00:58
海外TECH CodeProject Latest Articles Outlook attachments counter, don't send mails without attachments anymore https://www.codeproject.com/Tips/5326224/Outlook-attachments-counter-dont-send-mails-withou Outlook attachments counter don x t send mails without attachments anymoreWhen you forget to attach an invoice and your customer don t alert you well you start thinking on methods to avoid it to happen again 2022-02-28 07:59:00
医療系 医療介護 CBnews コロナワクチンへのアクセス拡大に3つの優先事項-各国製薬団体が共同声明、低・中所得国支援など https://www.cbnews.jp/news/entry/20220228164009 efpia 2022-02-28 17:00:00
医療系 医療介護 CBnews コロナ禍は「こころの健康に無視できない悪影響」-健康日本21第二次の最終評価報告書素案 https://www.cbnews.jp/news/entry/20220228160729 厚生労働省 2022-02-28 16:25:00
金融 RSS FILE - 日本証券業協会 選択権付債券売買取引状況 https://www.jsda.or.jp/shiryoshitsu/toukei/sentaku/index.html 選択 2022-02-28 09:00:00
金融 RSS FILE - 日本証券業協会 短期社債等及び私募社債の取引状況等 https://www.jsda.or.jp/shiryoshitsu/toukei/kokunai/index.html 私募 2022-02-28 09:00:00
金融 RSS FILE - 日本証券業協会 インターネット取引に係る株式売買等データ(月次) https://www.jsda.or.jp/shiryoshitsu/toukei/datakaiji.html 株式 2022-02-28 09:00:00
金融 JPX マーケットニュース [東証]監理銘柄(確認中)の指定:(株)ホウスイ https://www.jpx.co.jp/news/1023/20220228-11.html 監理銘柄 2022-02-28 16:40:00
金融 日本銀行:RSS 日本銀行政策委員会月報(令和4年1月号) http://www.boj.or.jp/announcements/pb_geppo/pbgp2201.pdf 日本銀行政策委員会 2022-02-28 16:30:00
ニュース BBC News - Home Ukraine conflict: Russia doubles interest rate after rouble slumps https://www.bbc.co.uk/news/business-60550992?at_medium=RSS&at_campaign=KARANGA sanctions 2022-02-28 07:55:20
ニュース BBC News - Home Ukrainian cities on alert after night of shelling as a 'crucial' day begins https://www.bbc.co.uk/news/world-europe-60551688?at_medium=RSS&at_campaign=KARANGA russia 2022-02-28 07:49:57
ニュース BBC News - Home Ukraine invasion: Putin puts nuclear forces on high alert https://www.bbc.co.uk/news/world-europe-60547473?at_medium=RSS&at_campaign=KARANGA ukraine 2022-02-28 07:26:57
ニュース BBC News - Home Australia floods: Eight dead in ‘unprecedented’ weather emergency https://www.bbc.co.uk/news/world-australia-60552110?at_medium=RSS&at_campaign=KARANGA emergencyresidents 2022-02-28 07:06:53
北海道 北海道新聞 日ハム新球場運営会社、周辺施設の命名権に名乗り 市道や公園など13施設 北広島市の公募に応募 https://www.hokkaido-np.co.jp/article/650870/ 北海道日本ハム 2022-02-28 16:17:00
北海道 北海道新聞 ロシア大使館、総領事館に抗議 「平和を」「市民殺すな」 https://www.hokkaido-np.co.jp/article/650866/ 東京都港区 2022-02-28 16:08:00
北海道 北海道新聞 渡辺のラプターズ32勝27敗 NBA第19週 https://www.hokkaido-np.co.jp/article/650864/ 渡辺 2022-02-28 16:01:00
マーケティング MarkeZine オロ、富裕層をターゲットとする広告メニューの提供を開始 DSPの選定から施策の実行までを支援 http://markezine.jp/article/detail/38461 開始 2022-02-28 16:30:00
マーケティング MarkeZine 会員数900万人超の通販サイト「BUYMA」から学ぶ、マーケティングDX実践【参加無料】 http://markezine.jp/article/detail/38458 参加無料 2022-02-28 16:15:00
IT 週刊アスキー 『P4U2』リマスター版特別映像「私をリングに連れてって!雪子姫の『P4U2』チャレンジ!」前後編を公開 https://weekly.ascii.jp/elem/000/004/084/4084725/ nintendoswitchpcsteam 2022-02-28 16:55:00
IT 週刊アスキー スマホアプリ『ユージェネ』でアスタリスタ「さくら」の誕生日を記念したイベントを開催! https://weekly.ascii.jp/elem/000/004/084/4084726/ 誕生日 2022-02-28 16:50:00
IT 週刊アスキー 地上約120mの桜装飾ルームでお花見気分! 新横浜プリンスホテル、“おこもりお花見”宿泊プラン https://weekly.ascii.jp/elem/000/004/084/4084723/ 新横浜プリンスホテル 2022-02-28 16:40:00
IT 週刊アスキー 日産自動車、メタバース上で高齢者の安全走行を促進・啓発するための「ハンドルぐるぐる体操」の体験会を実施 https://weekly.ascii.jp/elem/000/004/084/4084702/ nissancrossing 2022-02-28 16:30:00
IT 週刊アスキー 発売直前!『トライアングルストラテジー』応援メッセージキャンペーンが開催中 https://weekly.ascii.jp/elem/000/004/084/4084712/ nintendo 2022-02-28 16:10:00
マーケティング AdverTimes キョロちゃんをプログラムで操作 森永が教育アプリを配信 https://www.advertimes.com/20220228/article378051/ 配信 2022-02-28 07:14:38

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)