HTML - CSS:样式 <object>?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4437614/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:42:43  来源:igfitidea点击:

HTML - CSS: Styling <object>?

htmlcssobject

提问by wepper

If my div container has this:

如果我的 div 容器有这个:

<div id="container"><img src...

I can style the image by this:

我可以这样设计图像:

CSS
#container img{ ... }

For object tag

对于对象标签

<div id="container"><object ...

How do I address it? I tried this:

我该如何解决?我试过这个:

CSS
#container object{ width: 100px; }

But it does not work.

但它不起作用。

Assume the I cant define "id" or "class" for the object tag

假设我不能为对象标签定义“id”或“class”

I am using tinymce to embed to youtube video. And the code will be rendered like this:

我正在使用 tinymce 嵌入到 youtube 视频。代码将呈现如下:

<div id="container">
...

    <div id="content">
      <p>
      <object width="435" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/l9caxMr9RgY">
      <param value="http://www.youtube.com/v/XXXXXX" name="src"></object>
      </p>
    </div>
</div>

采纳答案by Blur

You already add size and width to the object style="width: 100px; height: 100px;"

您已经为对象添加了大小和宽度 style="width: 100px; height: 100px;"

Example

例子

回答by robzolkos

An object tag canbe styled using CSS. Ref link text

可以使用 CSS设置对象标签的样式。参考链接文本

The reason width didn't work in your example is that its a HTML attribute only and not accessible with CSS (see list in link above).

宽度在您的示例中不起作用的原因是它仅是一个 HTML 属性,不能通过 CSS 访问(请参阅上面链接中的列表)。

I would recommend that you put the object into a wrapper div (give the object a width of 100%) and control the width of the wrapper div with css.

我建议您将对象放入包装器 div(为对象提供 100% 的宽度)并使用 css 控制包装器 div 的宽度。

回答by miguelSantirso

You can assign an id or class for the object tat, that is perfectly correct. If you want the object to adapt to the width of its parent, just set its width to 100%. If you are using the <object>to embed flash, set the width for the <embed>tag also.

您可以为对象 tat 分配一个 id 或类,这是完全正确的。如果您希望对象适应其父级的宽度,只需将其宽度设置为 100%。如果您使用<object>嵌入 Flash,请同时设置<embed>标签的宽度。

回答by Robert Peters

To include text, this worked for me in Firefox 43.0. There are 3 files:

要包含文本,这在 Firefox 43.0 中对我有用。有3个文件:

test.html:

测试.html:

<html><head>
<link type="text/css" rel="stylesheet" href="test.css" media="all" />
</head><body>
<h3>Test</h3>
<object type="text/html" data="include.html"></object>
</body></html>

test.css:

测试.css:

object {width:24em;margin-top:-1em;}
.included {background-color:#ffe;font-size:12px;font-family:'Droid Serif';}

include.html - to format text inside the object, tags (like these) seem to be necessary:

include.html - 要格式化对象内的文本,标签(像这些)似乎是必要的:

<link type="text/css" rel="stylesheet" href="test.css" media="all" />
<div class="included">
Your included text here...
</div>