【问题标题】:how to overwrite css that is included in the css [duplicate]如何覆盖css中包含的css [重复]
【发布时间】:2016-01-19 16:11:20
【问题描述】:

我在一个复杂的 webapp 中有代码 - 就像这样创建代码

<img src="foobar.png" style="width:369px;height:200px;">

如何插入 css(通过 .css 文件包含)以覆盖宽度和高度?

谢谢

【问题讨论】:

    标签: html css


    【解决方案1】:

    您可以像下面的方法一样覆盖此图像样式

    img[style]{
            height:100px !important;
            width:200px !important;
        }
    &lt;img src="http://www.keenthemes.com/preview/conquer/assets/plugins/jcrop/demos/demo_files/image1.jpg" style="width:369px;height:200px"&gt;

    【讨论】:

      【解决方案2】:

      习惯于!important,并在你的img标签中定义一个class,就像这样

      .imgClass{
      width:400px !important;
      height:400px !important
      }
      

      【讨论】:

        【解决方案3】:

        使用覆盖所有内容的!important 方法强制使用CSS:

        查看fiddle

        img {
          width: 500px !important;
          height: 500px !important;
        }
        

        【讨论】:

          【解决方案4】:

          您应该像这样将!important 添加到您的样式中。

          img {
              height: 200px !important;
              width: 369px !important;
          }
          

          然后我总是建议你不要做内联样式。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2014-01-07
            • 1970-01-01
            • 2014-03-06
            • 1970-01-01
            • 1970-01-01
            • 2014-09-15
            • 1970-01-01
            相关资源
            最近更新 更多