簡體   English   中英

外部樣式未應用於img標簽

[英]External styling not being applied on the img tag

外部樣式不是僅應用於img標簽。 盡管它被應用於同一文件中的其他標簽。

Home.php

<link rel="stylesheet" href="styles.css" type="text/css"/>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<script src="jquery-3.1.0.js"></script>
<script src="js/bootstrap.min.js" ></script>
<div class="col-sm-3 thumbnail" style="height: 350px;">
    <img src="Images/1000px-Htc_new_logo.svg.png">
    <p class="test" >
        this is just  for testing the css link
    </p>
</div>

styles.css

img{
    height: 300px;
    width: 100%;
    border: solid 1px;
}
p{
    border: solid 1px;
}

p標簽工作正常

在自定義css文件之前添加供應商css(引導程序等),以便在需要時可以覆蓋默認供應商樣式。

您可以嘗試的幾種選擇,

1)換一張圖片試試看。 但不要使用此1000px-Htc_new_logo.svg.png

2)由於您加載了多個CSS文件,因此可以使用Firebug查看是否有一些CSS規則被覆蓋。

3)您可以將css與添加到style.css中的“!important”一起使用,僅用於測試,以查看是否可以將外部樣式應用於img標簽。 請注意!重要的做法不是一個好習慣,只需將其用於調試即可。

img{
height: 300px !important;  /* just use important for debug  */
width: 100% !important; /* just use important for debug  */
border: solid 1px !important;  /* just use important for debug  */

}

嘗試避免使用!important,這不是最佳實踐。 它將在任何地方覆蓋代碼。 而是要更具體一些,在這里我的意思是向這些圖像添加一個類,然后更改該類的屬性。

img .imageStyling {
    height: 300px;
    width: 100%;
    border: solid 1px;
}

造型<div>和<img>即使應用了相同的樣式,使用 URL 也不起作用?</div><div id="text_translate"><p> 我有以下示例,其中我在 div 上使用相同的圖像樣式。</p><p> 關鍵是 div 上的屬性使圖像看起來更好,但圖像上的屬性使圖像失真。 這是怎么回事? 我對兩者都使用了相同的樣式,但不知何故,它並沒有按應有的方式應用。 <a href="https://codesandbox.io/s/react-mui-forked-d7cufe?file=/index.js" rel="nofollow noreferrer">代碼沙箱示例</a></p></div>

[英]styling <div> and <img> using URL is not working even if same styled has been applied?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM