Html 2“样式”内联css img标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15000239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
2 "style" inline css img tags?
提问by user2095044
I have the following tag
我有以下标签
<img src="http://img705.imageshack.us/img705/119/original120x75.png"style="height:100px;"
style="width:100px;" alt="25"/>
I have put two incline CSS commands in
我已经将两个倾斜 CSS 命令放入
style="width:100px;"
style="height:100px;"
For some reason the picture has 100px height but no width.
I assume this is because you can't write two of these in a row in the same tag.
If this is true, is there a way to assign both the height and width?
I have already assigned a different image size on my external CSS, and I don't think you can add img
properties in the div
tag properties on the external CSS.
thanks
出于某种原因,图片有 100 像素的高度但没有宽度。我认为这是因为你不能在同一个标签中连续写两个。如果这是真的,有没有办法同时分配高度和宽度?我已经在我的外部 CSS 上分配了不同的图像大小,我认为您不能在外部 CSSimg
的div
标签属性中添加属性。谢谢
回答by Oded
You don't need 2 style attributes - just use one:
您不需要 2 个样式属性 - 只需使用一个:
<img src="http://img705.imageshack.us/img705/119/original120x75.png"
style="height:100px;width:100px;" alt="25"/>
Consider, however, using a CSS class instead:
但是,请考虑使用 CSS 类:
CSS:
CSS:
.100pxSquare
{
width: 100px;
height: 100px;
}
HTML:
HTML:
<img src="http://img705.imageshack.us/img705/119/original120x75.png"
class="100pxSquare" alt="25"/>
回答by Malcolm Murray
Do not use more than one style attribute. Just seperate styles in the style attribute with ;
It is a block of inline CSS, so think of this as you would do CSS in a separate stylesheet.
不要使用多个样式属性。只需将 style 属性中的样式与;
它分开,它是一个内联 CSS 块,因此可以将此视为在单独的样式表中处理 CSS。
So in this case its:
style="height:100px;width:100px;"
所以在这种情况下:
style="height:100px;width:100px;"
You can use this for any CSS style, so if you wanted to change the colour of the text to white:
style="height:100px;width:100px;color:#ffffff"
and so on.
您可以将它用于任何 CSS 样式,因此如果您想将文本的颜色更改为白色:
style="height:100px;width:100px;color:#ffffff"
等等。
However, it is worth using inline CSS sparingly, as it can make code less manageable in future. Using an external stylesheet may be a better option for this. It depends really on your requirements. Inline CSS does make for quicker coding.
然而,谨慎使用内联 CSS 是值得的,因为它可以使代码在未来更难管理。为此,使用外部样式表可能是更好的选择。这实际上取决于您的要求。内联 CSS 确实可以加快编码速度。
回答by Sanober Malik
You should use :
你应该使用:
<img src="http://img705.imageshack.us/img705/119/original120x75.png" style="height:100px;width:100px;" alt="25"/>
That should work!!
那应该有效!!
If you want to create class then :
如果你想创建类然后:
.size {
width:100px;
height:100px;
}
and then apply it like :
然后像这样应用它:
<img src="http://img705.imageshack.us/img705/119/original120x75.png" class="size" alt="25"/>
by creating a class you can use it at multiple places.
通过创建一个类,您可以在多个地方使用它。
If you want to use only at one place then use inline CSS. Also Inline CSS overrides other CSS.
如果您只想在一个地方使用,请使用内联 CSS。此外,内联 CSS 会覆盖其他 CSS。
回答by Md. Amran Hossan
if use Inline CSS you use
如果使用内联 CSS 你使用
<img src="http://img705.imageshack.us/img705/119/original120x75.png" style="height:100px;width:100px;" alt="705"/>
Otherwise you can use class properties which related with a separate css file (styling your website) as like In CSS File
否则,您可以使用与单独的 css 文件(设计您的网站)相关的类属性,就像 在 CSS 文件中一样
.imgSize {height:100px;width:100px;}
In HTML File
在 HTML 文件中
<img src="http://img705.imageshack.us/img705/119/original120x75.png" style="height:100px;width:100px;" alt="705"/>