【问题标题】:css with object tag带有对象标签的 CSS
【发布时间】:2012-02-28 16:31:19
【问题描述】:

我正在尝试将 pdf 文件置于网页中间,但它不允许我将边距自动设置为 0,就像对普通内容所做的那样。

我可以通过绝对定位来实现这一点,但是为什么正常的边距属性不起作用?

<html>
<style>
#ob{
    width:800px;
    height:800px;
}
#wrapper{
    margin:0 auto;
}

</style>
</head>

<body>

<div id="wrapper">
<object id="ob" class="pdf" data="my_pdf_file.pdf" type="application/pdf">
Your browser does not support PDFs
</object>
</div>


</body>
</html>    

【问题讨论】:

标签: html css object


【解决方案1】:

无论您试图使用边距技术居中,都需要定义宽度。

尝试为包装器设置宽度,或者简单地将 margin:0 px 应用于#ob

【讨论】:

  • OP 确实在对象上定义了宽度。
  • 向对象和包装器添加高度/宽度,然后将边距:0 auto 应用于包装器。但是如果我将边距属性应用于对象,由于某种原因不起作用。嗯,第一个解决方案行得通,所以我不会担心第二个问题。
【解决方案2】:

给包装器一个宽度,这就是为什么它不居中我不知道要在中心比较什么

#wrapper{
    margin:0 auto;
    width: 800px;
}

【讨论】:

    【解决方案3】:

    使用

    text-align:center;
    

    这是一个jsFiddle example

    【讨论】:

      【解决方案4】:

      您将 100% 宽度的包装纸居中,因此已经居中。将边距代码移到对象上,然后重试。

      【讨论】:

        【解决方案5】:

        只需将您的样式标签替换为这个即可解决您的问题,详细信息请查看我在代码中编写的 cmets。

        <style>
            #wrapper{
                width: 800px;   // It will set the width of the wraper
                margin: 0 auto;     // It will help the wrapper div to be centered of the document.
            }
        
            #ob{
                width: 100%;    // It will be streched upto the wrapper fixed width which is 800px
                height: 800px;
            }
        </style>
        

        【讨论】:

          【解决方案6】:

          试试这个:

          <div id="wrapper">
          <center>
          <object id="ob" class="pdf" data="my_pdf_file.pdf" type="application/pdf">
          Your browser does not support PDFs
          </object>
          </center>
          </div>
          

          【讨论】:

          • 中心标签大约在 100 年前被弃用。不要使用它。
          • 最佳实践永远胜过捷径
          猜你喜欢
          • 2021-05-22
          • 2021-08-04
          • 2016-05-23
          • 1970-01-01
          • 2022-08-18
          • 1970-01-01
          • 1970-01-01
          • 2022-08-03
          • 2013-10-07
          相关资源
          最近更新 更多