2016-07-28 6 views
-1

私は私のような私のCSSに「共通クラス」と呼ぶものを追加するために使用: -CSS - 'Common Classes'悪い習慣かどうか?

.text-color{color:#2da8d9;} 
.text-white{color:#fff;} 
.text-lgrey{color:#919D9D !important;} 
.text-dgrey{color:#879798 !important;} 
.text-dkgrey{color:#656d6e !important;} 
.text-dblue{color:#15355C;} 
.text-lblue{color:#1466B1;} 
.nopadding{padding: 0 !important; margin: 0 !important;} 
.margin0{margin:0px !important;} 
.margint5{margin-top:5px !important;} 
.margint10{margin-top:10px !important;} 
.margint20{margin-top:20px !important;} 
.margint30{margin-top:30px !important;} 
.margint40{margin-top:40px !important;} 
.margint50{margin-top:50px !important;} 
.margint60{margin-top:60px !important;} 
.margint70{margin-top:70px !important;} 
.margint80{margin-top:80px !important;} 
.margint90{margin-top:90px !important;} 
.margint100{margin-top:100px !important;} 
.margint120{margin-top:120px !important;} 
.marginb10{margin-bottom:10px !important;} 
.marginb20{margin-bottom:20px !important;} 
.marginb30{margin-bottom:30px !important;} 
.marginb40{margin-bottom:40px !important;} 
.marginb60{margin-bottom:60px !important;} 
.marginb80{margin-bottom:80px !important;} 
.marginb90{margin-bottom:90px !important;} 
.marginb100{margin-bottom:100px !important;} 
.marginb120{margin-bottom:120px !important;} 
.pleftnone{padding-left:0 !important;} 
.padrl20{padding:0 20px;} 
.padrl50{padding:0 50px;} 
.marginl20{margin-left:20px;} 
.padt20{padding-top:20px;} 
.padt40{padding-top:40px;} 
.padt80{padding-top:80px;} 
.padt60{padding-top:60px;} 
.padb30{padding-bottom:30px;} 
.padb40{padding-bottom:40px;} 
.padb60{padding-bottom:60px;} 
.padb80{padding-bottom:80px;} 
.padb100{padding-bottom:100px;} 
.pad5{padding:5px;} 
.pad10{padding:10px;} 
.pad20{padding:20px;} 
.pad30{padding:30px;} 
.text-center{text-align:center} 
.text-right{text-align:right} 
.text-left{text-align:left} 
.relative-position{position:relative !important} 

そして、私はそれらを使用する必要がある場合、誰かがそれがこれを行うには非常に悪い習慣だ私に言ったまで、そしてちょうどクラスを追加?

子要素などの絶対配置を使用するときにかなり多くの要素にposition: relative;を追加していますが、毎回CSSで追加するのではなく、クラスを追加するのは簡単です。私はそれがあなたのクラスを追加するとHTMLサイズに追加されますが、すべてのクラスに同じスタイルを追加しないのでCSSが少なくなることは理解できますか?

ベストプラクティスを明確にしたいだけです。これについて話す場所でない場合は、事前にお詫びください。

+0

この質問は広すぎる、**意見に基づいて**または議論を必要とするので、スタックオーバーフローに関するトピックはありません。具体的な、解決可能な、プログラミングの問題がある場合は、詳細を記入してください。 –

+0

またはコードレビューに移動します。 – 3rdthemagical

+0

構造化には問題ないと思いますが、スタイリングは、構造化よりも抽象化のレベルが高いため、スタイリング(カラー/フォントスタイル/ "テキストはX色になりますが、この色は数多くの要素で共有できます。使用された後はユーティリティクラスを変更できないので、どこでも変更が必要な場合は本当に難しいでしょう。 –

答えて

2

悪いです。クラスtext-white margint5 marginb10 padrl20 padb40 text-center relative-positionの要素を想像してください。それは醜いです。 余白32pxが必要な場合はどうすればよいですか?新しいクラスmargint32を追加しますか?すべてのCSSプロパティのクラスを追加しますか? border-radius、font-size、font-weightなどがあります。

BEMについて読んでください。

+0

公正になるためには、一度にクラスの1つを使用することができますが、私はあなたが意味することを理解することができます。マージンが必要な場合:32pxより具体的ですので、要素のIDまたはクラスに追加します – nsilva

+0

クラスtext-whiteでたくさんのボタンがあるとします。そして今、すべてのボタンは別の色を持っている必要があります。あなたは何をしますか?プロジェクトとリライトクラスのすべてのボタンを検索しなければなりませんでした。 – 3rdthemagical

+0

@ 3rdthemagical - 'text-white'の代わりに' color-one'クラスを呼び出した場合、 'color:#ffffff 'を持つすべてのものを見つけて置き換えるのではなく、そのスタイルを変更することができます; ' – Pete

0

レスポンシブウェブデザインでサイトがモバイルフレンドリーでない場合は、一般的なクラスを使用することは好ましくありません。 例:モバイルデバイス上でmargin10クラスを使用してその値を20に変更したいとし、mediaqueriesに同じ値を書き込んだとすると、class margin10を持つすべての要素のマージンが変更され、多くの問題が発生する可能性があります。

関連する問題