简体   繁体   English

CSS未应用

[英]CSS isn't get applied

I am trying to block a piece of code using a Div open and close tag as such: 我试图使用这样的Div打开和关闭标签来阻止一段代码:

<div id="header"> 
  <a href="www.hugowolfdesigns.tumblr.com">
    <img src="http://i596.photobucket.com/albums/tt48/stizzo96/hugowolf_zps386e6f4e.png" alt=" photo hugowolf_zps386e6f4e.png" class="header"/>
  </a>
</div>

However if I try and code in css using #header it won't follow any of the rules? 但是,如果我尝试使用#header在CSS中进行编码,它将不会遵循任何规则? I am new to HTML and CSS so please excuse my ignorance. 我是HTML和CSS的新手,请原谅我的无知。

EDIT: Here is the required CSS needed to help me. 编辑:这是帮助我所需的必需CSS。 Sorry for forgetting it, again I am new here. 抱歉忘记了,我还是新来的。

.header{ 
    width:300px; 
    height:300px;
    display:block; 
    margin: auto;
    transition: opacity .25s ease-in-out;
    -moz-transition: opacity .25s ease-in-out;
    -webkit-transition: opacity .25s ease-in-out;} 

The last part was copied from a help website as it allows it to fade in and out when the mouse hovers over it. 最后一部分是从帮助网站复制的,因为当鼠标悬停在帮助网站上时,它可以淡入和淡出。 Every time I try changing the '.' 每次我尝试更改“。” with a '#' it completely neglects the rules. 如果使用“#”,它将完全忽略规则。

The CSS in the answer is for the class header and not for the id header: .header { . 答案中的CSS用于头,而不用于id头: .header { In CSS the . 在CSS中. refers to a class and a # to an ID. 指代一个类, #表示ID。 The CSS is currently applied on the image: http://jsfiddle.net/BjgvY/ 该CSS当前应用于图像: http : //jsfiddle.net/BjgvY/

No idea what your CSS is because you haven't included it, but I'm guessing that you're referring to the fact that you are trying to do things like this: 不知道您的CSS是什么,因为您还没有包含CSS,但是我想您是指您正在尝试执行以下操作:

#header {
    height:50px;
}

And nothing is happening. 而且什么也没有发生。 This is because #header has a overflow value of 'visible' by default, and as the image is much larger, it'll overflow and take up as much room as needed. 这是因为默认情况下,#header的溢出值是“ visible”,并且随着图像的增大,它将溢出并占用所需的空间。

If you don't want this to happen, you'll have to alter the overflow to a different value, for example: 如果您不希望发生这种情况,则必须将溢出更改为其他值,例如:

#header {
    height:50px;
    overflow: hidden;
}

will hide any content that goes over the 50px height limit of the header. 将隐藏超出标题的50px高度限制的所有内容。

If you're trying to alter the size of the image, set the height/width attributes on the image, not the header. 如果您要更改图像的大小,请在图像上设置高度/宽度属性,而不是在页眉上。 Or preferably, link to a more suitably sized image; 或者,最好链接到更合适尺寸的图像; there's no point loading a ~1000x800 image if you're only going to scale it down to something like 200x160. 如果只要将其缩小到200x160之类的大小,则加载〜1000x800的图像毫无意义。

It's also probably a bad idea to have an ID and class with the same name. 具有相同名称的ID和类可能也是一个坏主意。 Just for clarity, if you're trying to get the image with the class 'header' to follow some css styling, you want to use the 为了清楚起见,如果您尝试使用“ header”类获取图像以遵循某些CSS样式,则需要使用

.header {
}

selector, and not 选择器,而不是

#header {
}

If you post your CSS, I could provide a more relateable answer, other than just a shot in the dark based on what I think you might be doing wrong. 如果您发布CSS,除了根据我认为可能做错的事情在黑暗中拍摄之外,我还可以提供更相关的答案。

Edit: 编辑:

It seems like you're having difficulty with CSS selectors, 似乎您在使用CSS选择器时遇到困难,

#header {
}

will refer to any elements that have an ID of header, such as 将引用具有标头ID的任何元素,例如

<div id="header"></div>

whilst the css selector 而CSS选择器

.header {
}

refers to elements that have a CLASS of header, such as 指的是具有CLASS标头的元素,例如

<div class="header"></div>

So back to your code 回到您的代码

<div id="header"> 
  <a href="www.hugowolfdesigns.tumblr.com">
    <img src="http://i596.photobucket.com/albums/tt48/stizzo96/hugowolf_zps386e6f4e.png" alt=" photo hugowolf_zps386e6f4e.png" class="header"/>
  </a>
</div>

    #header { // these styles will apply to your div with ID header
    }

    .header { // these styles will apply to your image with the class header
    }

It may seem like an annoyance, but if your new to CSS, i'd heavily recommend you read up about selectors. 看起来似乎很烦,但是如果您是CSS新手,我强烈建议您阅读有关选择器的文章。 As they are pretty much vital to doing anything in CSS. 因为它们对于使用CSS进行任何操作都至关重要。

Here's the documentation 这是文档

Chapter 5.8.3 talks about class selectors 第5.8.3章讨论了类选择器

Chapter 5.9 talks about ID selectors 第5.9章讨论了ID选择器

(Off topic) (无关)

Your link is incorrect, and should either be 您的链接不正确,应该是

 <a href="http://www.hugowolfdesigns.tumblr.com">

if it's pointing to a different website, or it can just be 如果它指向另一个网站,或者只是

 <a href="/">

if it's pointing to the homepage of the same website 如果它指向同一网站的主页

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM