18910140161

JavaScript-为什么不'在我的CSS文件-堆栈溢出

顺晟科技

2022-10-18 13:25:47

92

中,设置我的图像通过其类或ID分配样式

每当我在JavaScript(使用react.JS)中将类名或ID分配给我的IMG标记,然后分配引用该ID或类的样式时,该样式不会得到应用,但是当我对DIV执行同样的操作时,一切正常。

<;--JavaScript-->;

import React from "react";
import TitleImage from './Images/TitleBG.png'
import TitleImage2 from './Images/TitleMG.png'
import TitleImage3 from './Images/TitleCG.png'
import './heade.css'; 

const TopHeading = () => {

    return(

        //Here is a div with the ID "TopHeading", this style gets applied.

        <div id="TopHeading">

            {/*This image with class "image1" does not get its style applied.*/}

            <img className="image1" alt="Dofus" src={TitleImage}/>
            <img width='auto' alt = "Memory Game" height='50px' src={TitleImage2}/>
            <img width='auto' alt = "Character" height='50px' src={TitleImage3}/>
            <div className="aDiv"></div>
        </div>
    );
};

<;--CSS-->;

#TopHeading{
    display: grid;
    align-items: center;
    justify-items: center;
  
    background-color: rgb(131, 192, 131);
    height: 300px;
};

.image1{
    border-style: solid;
    width: auto; 
    height:250px;
}

.aDiv{
    size: 50px;
    border-style: solid;

在这里,您可以看到将ID的样式应用于DIV.

This shows that the ID gets applied to the div

下面是类的样式由于某种原因被忽略的图像:

img tag class ignored


顺晟科技:

CSS中类规则前

的分号使选择器无效。不要在规则的花括号{ }外使用分号。

这不管用

<代码>;第{高度:50px;宽度:50px;背景:红色;}
<代码><;DIV>;<;/DIV>;

虽然这个有

<代码>DIV{高度:50px;宽度:50px;背景:红色;}
<代码><;DIV>;<;/DIV>;

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航