问题,包括cssin html [英] problems including cssin html

查看:87
本文介绍了问题,包括cssin html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

何时使用#"和."设计CSS时?

例如
有什么区别
html,body
{}

#info
{}

.infoitem
{}

我很困惑.如何将它们包含在我的html中.

解决方案

简单地说,有三种基本情况:

以''.''开头-指的是类
以``#''开头-引用id
都不以开头-引用标签名称


.myClass-这将选择所有带有class ="myClass''
的项目 #myId-这将选择id =''myId''
的单个项目 元素-这将选择标记元素< element>
的所有项目

 <  样式 > ; 
    . firstItem  {颜色 : 红色; }
    # secondItem  {颜色 : 绿色; }
     p  {颜色 : 蓝色; }
</ 样式 >  


 <   div      ='  firstItem' > 应为RED <  /div 

span> > < div =' > 应为GREEN /div < p > BLUE < /p >


CSS ID:
与类相似,因为它们为元素定义了特殊情况.以下是CSS ID的示例.
CSS代码:

p#e1 {background-color:white; }


HTML代码:

此段落的ID名称为
"exampleID1"并具有白色的CSS定义背景



CSS类别:一个类别可以使用多次,而ID只能使用一次

CSS代码:

p.myclass {background-color:#013370;颜色:白色;}

HTML代码:

检查我的课程


所有内容都相同,包括HTML.对于包含在html中,#info和.info之间没有区别.

但是,如果声明#footer,则您的div的ID应该是页脚,如下所示:-

div id ="footer"

如果声明.footer,则div的class属性应为footer,如下所示:-

div id ="div1" class ="footer"


Hello,

When to use "#" and "." while designing CSS??

e.g. What is difference between

html,body
{ }

#info
{ }

.infoitem
{ }

I am confused. How to include them in my html.

解决方案

Simply put, there are three basic cases:

Starts with a ''.'' - refers to class
Starts with a ''#'' - refers to id
Starts with neither - refers to tag name


.myClass - this will select all items with class=''myClass''
#myId - this will select the single item with id=''myId''
element - this will select all items of tag element <element>

<style>
    .firstItem { color: red; }
    #secondItem { color: green; }
    p { color: blue; }
</style>


<div class='firstItem'>This should be RED</div>
<div id='secondItem'>This should be GREEN</div>
<p>This should be BLUE</p>


CSS IDs :
are similar to classes in that they define a special case for an element. Below is an example of a CSS ID.
CSS Code:

p#e1 { background-color: white; }


HTML Code:

This paragraph has an ID name of
"exampleID1" and has a white CSS defined background



CSS Class:A class can be used several times, while an ID can only be used once

CSS Code:

p.myclass { background-color: #013370; color: white;}

HTML Code:

Check my class


same for all Including in HTML. For including in html there is no difference between #info and .info.

But if declare #footer then your div''s ID should be footer just like given below:-

div id="footer"

if you declare .footer then your div''s class property should be footer just like given below:-

div id="div1" class="footer"


这篇关于问题,包括cssin html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆