あなたの@mediaクエリに含まれるコードの重要な部分は、あなたのページの要素に動的スタイルのプロパティを追加するのに効果的な方法ですが、簡単なメンテナンスのためにあなたのデフォルトのCSSをそのまま残しておきます。
例:
<html>
<head>
<style>
@media all and (max-width: 768px) {
/* CSS styles targeting screens of smaller sizes and/or resolutions (IE phones and tablets) */
#semantically-named-element p
{ width: 60% !important;
background: rgba(0,0,255,1)!important;
margin: auto !important; }
#semantically-named-element span
{ display: none !important; }
}
/* Look ma no media queries needed for default CSS below! Very easy to discern default styles, when the default code is the stuff not wrapped in queries. Period. */
/* Default CSS style attributes for any viewports that do not fit into the low or high resolution/screen size parameters set above and below. Also the fallback for browsers that still disregard CSS media queries */
#semantically-named-element p
{ width: 90%;
background: rgba(255,0,0,1);
margin: auto; }
#semantically-named-element span
{ display: block;
background: rgba(0,0,0,0.8);
color: #FFF;
text-align: center;}
@media all and (min-width: 968px) {
/* CSS styles targeting very large or very high resolution viewports at the 769 pixels wide "break-point" */
#semantically-named-element p
{ width: 80% !important;
background: rgba(0,255,0,1)!important;
margin: auto !important; }
#semantically-named-element span
{ display: block !important;
background: rgba(0,0,0,0.8)!important;
color: #FFF !important; font-size: 200%; }
}
</style>
</head>
<body>
<div id="semantically-named-element">
<p> Usage of !important inside of the code contained within your @media queries is an effective way to add dynamic style properties to your pages elements, while leaving your 'default' css intact for easy maintenance.<span>hidden until tablet greater 768 viewport pixel width</span></p>
</div>
</body>
</html>
あなたのコードは私のシステムで正常に動作しています。私はMacでFirefox、Chrome、Safariをテストしました。あなたのテスト環境は何ですか? – Anji
遅く返事を申し訳ありません。私はなぜそれが機能していないのかを考えようとしていました。ここにあります:http://jsfiddle.net/TUL6h/3/サイズを変更して色を青くしてみてください。それは決して起こらない – jQuerybeast
それはCSSのセクションの最後の色だけを選ぶでしょう。 – jQuerybeast