css_01|CSS-CSS基礎とセレクタ初認識
24829 ワード
PC ~
“ | ” , , !
css_01
1. CSS ?
2. @import ? ?
3. CSS ?
4. id class ?
5. @charset ?
6. src href ?
7. , link @import ?
8. index.css common.css ,html index.css , ?( )
/*index.css*/
@import "common.css"
body {
font-size:12px
}
/*common.css*/
body {
color: red;
}
✅ common.css , 。
✅ @import "url"; 。
✅ index.css body : :。
❌ font-size:12px 。
前言:前の3つのシリーズの文章を通じて私达はHTMLに対して1つの比较的に详しく理解して、それでは次のいくつかの列の文章、私达は一歩一歩详しくCSSを认识します.その時、私たちが見た任意の静的ページを簡単に、規範的に書くことができると信じています.
1 CSS関連定義
CSS(Cascading Style Sheets積層スタイルシート):HTMLの表現を制御します.CSSはページがきれいかどうかを決めて、アニメーションの効果はクールでクールではありません.
HTML+CSSは静的ページの基本構成です.まるで女の子が基本的な体の五感(HTML)を持ってから、自分に化粧をしたり、髪型をしたり、きれいな服を着たり(CSS).
2 CSS動作原理
再度文章を復習します:《ありふれたURLからページに入力して背後で起こったことを示します》
この「木」には2つのノードがあり、1つはその要素が何なのか.もう1つは、この要素の具体的なパラメータです.幅、高さ、位置、サイズ、枠線などです.
すなわち、ページ上の各要素の位置、各要素間の関係、親子、隣人などを示す豊富なデータを得ることに相当します.この時、私は画板を持って描くことができます.
3 CSSのHTMLへの導入方式
3.1外部スタイルシート:「チェーンイン」CSS(前例)
</code> <code><link/></code> 。</p>
<ul>
<li><code><link/></code> , <code>rel="stylesheet"</code> ,“rel ” HTML , “ ”——stylesheet。</li>
<li> href (html reference 、 ) —— ( <code>.css</code> , CSS , ), URL。</li>
</ul>
<h3 class="heading">3.2 : @import “ ” </h3>
<pre><code><style>
@import url("index.css"); <!--①-->
@import url(index.css); <!--②-->
@import "index2.css"; <!--③-->
@import url("landscape.css") screen and (orientation:landscape); <!--④-->
</style>
<span class="copy-code-btn"></span></code></pre>
<p> ,@import “ ” CSS , CSS 。</p>
<p> ①②③ , 。 <code>.css</code> URL “ ” , <code>;</code> 。</p>
<p> ④ “ ”:<br/><code>screen</code> “ ”, <code>and (orientation:landscape)</code> “ orientation ” “ (landscape)”。<br/>“ ” :portrait。</p>
<h3 class="heading">3.3 : head <code><style/></code> </h3>
<p> :</p>
<pre><code><span class="hljs-meta">
<span class="hljs-tag"><<span class="hljs-name">html</span>></span>
<span class="hljs-tag"><<span class="hljs-name">head</span>></span>
<span class="hljs-tag"><<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">title</span>></span>HTML <span class="hljs-tag"><span class="hljs-name">title</span>></span>
<span class="hljs-tag"><<span class="hljs-name">style</span>></span><span class="css">
<span class="hljs-selector-id">#txa</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
<span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
<span class="hljs-attribute">margin-left</span>: -<span class="hljs-number">12px</span>;
}
</span><span class="hljs-tag"><span class="hljs-name">style</span>></span>
<span class="hljs-tag"><span class="hljs-name">head</span>></span>
<span class="hljs-tag"><<span class="hljs-name">body</span>></span>
……
<span class="copy-code-btn"></span></span></code></pre>
<h3 class="heading">3.4 : style 。</h3>
<pre><code><span class="hljs-tag"><<span class="hljs-name">p</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"background: yellow; font-family: sans-serif;"</span>></span>Oliver !<span class="hljs-tag"><span class="hljs-name">p</span>></span>
<span class="copy-code-btn"></span></code></pre>
<p> :</p>
<ul>
<li> 、 ;</li>
<li> , 。 <code><link/></code> “ ” CSS。</li>
</ul>
<br/>
<h2 class="heading">4 CSS </h2>
<p>CSS “ ” “ ”、“ ” HTML 。<br/> CSS “ ”、“ ”, :</p>
<pre><code><span class="hljs-selector-tag">h1</span> {<span class="hljs-attribute">color</span>: red; <span class="hljs-attribute">background</span>: yellow;}
<span class="copy-code-btn"></span></code></pre>
<h3 class="heading">4.1 </h3>
<pre><code><span class="hljs-selector-tag">p</span> {
<span class="hljs-attribute">color</span>: yellow;
}
<span class="hljs-selector-tag">div</span> {
<span class="hljs-attribute">background</span>: yellow;
}
<span class="hljs-selector-tag">p</span>,<span class="hljs-selector-tag">div</span> {
<span class="hljs-attribute">font-family</span>: sans-serif;
}
<span class="copy-code-btn"></span></code></pre>
<h3 class="heading">4.2 ID </h3>
<p>id ( ):</p>
<pre><code><span class="hljs-meta">
<span class="hljs-tag"><<span class="hljs-name">html</span>></span>
<span class="hljs-tag"><<span class="hljs-name">head</span>></span>
<span class="hljs-tag"><<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">title</span>></span>HTML <span class="hljs-tag"><span class="hljs-name">title</span>></span>
<span class="hljs-tag"><<span class="hljs-name">style</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/css"</span>></span><span class="xml">
#txa { <span class="hljs-comment"><!--①--></span>
width: 300px;
height: 200px;
margin-left: -12px;
}
</span><span class="hljs-tag"><span class="hljs-name">style</span>></span>
<span class="hljs-tag"><span class="hljs-name">head</span>></span>
<span class="hljs-tag"><<span class="hljs-name">body</span>></span>
……
<span class="hljs-tag"><<span class="hljs-name">div</span>></span>
<span class="hljs-tag"><<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"txa"</span>></span> :<span class="hljs-tag"><span class="hljs-name">label</span>></span>
<span class="hljs-tag"><<span class="hljs-name">textarea</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"txa"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"article"</span>></span> ! <span class="hljs-comment"><!--②--></span>
<span class="hljs-tag"><span class="hljs-name">textarea</span>></span>
<span class="hljs-tag"><span class="hljs-name">div</span>></span>
……
<span class="copy-code-btn"></span></span></code></pre>
<p>? :</p>
<ul>
<li> <p> ② <code>id="txa"</code> :“id ” “ ” , id : 、 。<br/> :id , id, id。<br/>id , 。</p> </li>
<li> <p> ① <code>#txa</code> : id , id # 。</p> </li>
</ul>
<h3 class="heading">4.3 </h3>
<p><strong>“ ”:</strong> , ( ) , ( ) —— 。</p>
<p> “ ” :</p>
<ul>
<li> HTML class , “ ” 。</li>
</ul>
<p>⚠️ : , , “ ” “ ” 。</p>
<pre><code><span class="hljs-tag"><<span class="hljs-name">ul</span>></span>
<span class="hljs-tag"><<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"first"</span>></span>fine<span class="hljs-tag"><span class="hljs-name">li</span>></span>
<span class="hljs-tag"><<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"second"</span>></span>thank you<span class="hljs-tag"><span class="hljs-name">li</span>></span>
<span class="hljs-tag"><<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"third done"</span>></span>and you<span class="hljs-tag"><span class="hljs-name">li</span>></span>
<span class="hljs-tag"><span class="hljs-name">ul</span>></span>
<span class="copy-code-btn"></span></code></pre>
<ul>
<li> CSS “ ”(⚠️ : class <code>.</code> )。</li>
</ul>
<pre><code><span class="hljs-selector-class">.first</span> {
<span class="hljs-attribute">font-weight</span>: bold;
}
<span class="hljs-selector-class">.done</span> {
<span class="hljs-attribute">text-decoration</span>: line-through;
}
<span class="copy-code-btn"></span></code></pre>
<p><strong>? :</strong> , “ ” , class; , id。</p>
<h3 class="heading">4.4 </h3>
<p> , “ ”。 :</p>
<pre><code>* {
<span class="hljs-attribute">color</span>: yellow;
}
<span class="copy-code-btn"></span></code></pre>
<p> “ ” color yellow。</p>
<h3 class="heading">4.5 </h3>
<p>“ ” ,“ ” :attribute。</p>
<h4 class="heading">4.5.1 [attr]</h4>
<p> <code>[]</code> , <strong> </strong> :</p>
<pre><code><span class="hljs-selector-tag">li</span><span class="hljs-selector-attr">[class]</span> {
<span class="hljs-attribute">color</span>: red;
<span class="hljs-attribute">background</span>: yellow;
}
<span class="copy-code-btn"></span></code></pre>
<p><em>( <strong> class </strong>( ) li , red, yellow )</em><br/></p>
<h4 class="heading">4.5.2 [attr=val]</h4>
<p> <code>[]</code> “ ” “ ” , <strong> </strong> :</p>
<pre><code><span class="hljs-selector-tag">li</span><span class="hljs-selector-attr">[class="second"]</span> {
<span class="hljs-attribute">color</span>: red;
<span class="hljs-attribute">background</span>: yellow;
}
<span class="copy-code-btn"></span></code></pre>
<p><em>( <strong> class second</strong> li , red, yellow )</em></p>
<p>⚠️ : “ ” , , 。 :<br/><em>( class third done li , red, yellow)</em></p>
<pre><code><span class="hljs-selector-tag">li</span><span class="hljs-selector-attr">[class="third done"]</span> {
<span class="hljs-attribute">color</span>: red;
<span class="hljs-attribute">background</span>: yellow;
}
<span class="copy-code-btn"></span></code></pre>
<p>✘ :</p>
<pre><code><span class="hljs-selector-tag">li</span><span class="hljs-selector-attr">[class="third"]</span> {
<span class="hljs-attribute">color</span>: red;
<span class="hljs-attribute">background</span>: yellow;
}
<span class="copy-code-btn"></span></code></pre>
<h4 class="heading">4.5.3 [attr~=val]</h4>
<p> <code>[]</code> “ ”、 <code>~</code> “ ” , “ ” :</p>
<pre><code><span class="hljs-selector-tag">li</span><span class="hljs-selector-attr">[class~="done"]</span> {
<span class="hljs-attribute">color</span>: red;
<span class="hljs-attribute">background</span>: yellow;
}
<span class="copy-code-btn"></span></code></pre>
<p><em>( <strong> class done</strong> li , red, yellow)</em></p>
<h4 class="heading">4.5.4 <code>^</code> <code>$</code> <code>*</code></h4>
<h5 class="heading">1. <code>^</code></h5>
<pre><code><span class="hljs-selector-tag">li</span><span class="hljs-selector-attr">[class^="se"]</span> {
<span class="hljs-attribute">color</span>: red;
<span class="hljs-attribute">background</span>: yellow;
}
<span class="copy-code-btn"></span></code></pre>
<p><em>( class <strong> </strong> se li , red, yellow )</em></p>
<h5 class="heading">2. <code>$</code></h5>
<pre><code><span class="hljs-selector-tag">li</span><span class="hljs-selector-attr">[class$="ne"]</span> {
<span class="hljs-attribute">color</span>: red;
<span class="hljs-attribute">background</span>: yellow;
}
<span class="copy-code-btn"></span></code></pre>
<p><em>( class <strong> </strong> ne li , red, yellow)</em></p>
<h5 class="heading">3. <code>*</code></h5>
<pre><code><span class="hljs-selector-tag">li</span><span class="hljs-selector-attr">[class*="ir"]</span> {
<span class="hljs-attribute">color</span>: red;
<span class="hljs-attribute">background</span>: yellow;
}
<span class="copy-code-btn"></span></code></pre>
<p><em>( class ir li , red, yellow )</em></p>
<p>? :<code>^</code> (^^) , <em> </em>; <br/><em><code>$</code> , ;</em> <br/><em><code>*</code> , , </em>。</p>
<h4 class="heading">4.5.5 </h4>
<pre><code><span class="hljs-meta">
<span class="hljs-tag"><<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"zh"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">head</span>></span>
<span class="hljs-tag"><<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"utf-8"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">title</span>></span> “ ” <span class="hljs-tag"><span class="hljs-name">title</span>></span>
<span class="hljs-tag"><span class="hljs-name">head</span>></span>
<span class="hljs-tag"><<span class="hljs-name">body</span>></span>
<span class="hljs-tag"><<span class="hljs-name">h1</span>></span> “ ” <span class="hljs-tag"><span class="hljs-name">h1</span>></span>
<span class="hljs-tag"><<span class="hljs-name">dl</span>></span>
<span class="hljs-tag"><<span class="hljs-name">dt</span>></span> <span class="hljs-tag"><span class="hljs-name">dt</span>></span>
<span class="hljs-tag"><<span class="hljs-name">dd</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>></span>Thank you.<span class="hljs-tag"><span class="hljs-name">dd</span>></span>
<span class="hljs-tag"><<span class="hljs-name">dt</span>></span> <span class="hljs-tag"><span class="hljs-name">dt</span>></span>
<span class="hljs-tag"><<span class="hljs-name">dd</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"ja"</span>></span>ありがとう.<span class="hljs-tag"><span class="hljs-name">dd</span>></span>
<span class="hljs-tag"><<span class="hljs-name">dt</span>></span> <span class="hljs-tag"><span class="hljs-name">dt</span>></span>
<span class="hljs-tag"><<span class="hljs-name">dd</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>></span>Merci.<span class="hljs-tag"><span class="hljs-name">dd</span>></span>
<span class="hljs-tag"><<span class="hljs-name">dt</span>></span> <span class="hljs-tag"><span class="hljs-name">dt</span>></span>
<span class="hljs-tag"><<span class="hljs-name">dd</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en-au"</span>></span>Thank you very much.<span class="hljs-tag"><span class="hljs-name">dd</span>></span>
<span class="hljs-tag"><span class="hljs-name">dl</span>></span>
<span class="hljs-tag"><span class="hljs-name">body</span>></span>
<span class="hljs-tag"><span class="hljs-name">html</span>></span>
<span class="copy-code-btn"></span></span></code></pre>
<p><em>( : lang en en- , red, yellow )</em></p>
<pre><code>*<span class="hljs-selector-attr">[lang|="en"]</span> {
<span class="hljs-attribute">color</span>: red;
<span class="hljs-attribute">background</span>: yellow;
}
<span class="copy-code-btn"></span></code></pre>
<p>⚠️ : 。</p>
<br/>
<hr/>
<p><strong> :</strong> , , : 、 、 。<br/>CSS , 、 , 。 : , 。</p>
<p> !</p>
</div>
<p> :https://juejin.im/post/5cb07b7ef265da03ba0e1be0</p>
</div>
</div>
</div>
</div>