如何设置从第三方导入的内置评论框的样式


How to style a built-in comment box imported from a third party?

我正在尝试使用从另一个网站导入的内置评论框。我只是把代码(从那里)复制粘贴到我自己的网站上(实际上是在我的PHP文件中)。

现在它运行良好。但我对它的大小和样式不满意。我想调整盒子的大小,并对其进行更多的自定义,使其在我的网站上看起来很好看。如果您查看源代码,您会发现在其上应用样式有点困难,因为它是直接导入的。

好的,特别是,我想通过在CSS中应用margin-left和margin-right属性来减少它的宽度。我试过了,但失败了。那怎么可能呢?

.PHP:

    <!-- begin htmlcommentbox.com -->
 <div id="HCB_comment_box"><a href="http://www.htmlcommentbox.com">Widget</a> is loading comments...</div>
 <link rel="stylesheet" type="text/css" href="//www.htmlcommentbox.com/static/skins/shady/skin.css" />
 <script type="text/javascript" id="hcb"> /*<!--*/ if(!window.hcb_user){hcb_user={};} (function(){var s=document.createElement("script"), l=(""+window.location).replace(/'/g,"%27") || hcb_user.PAGE, h="//www.htmlcommentbox.com";s.setAttribute("type","text/javascript");s.setAttribute("src", h+"/jread?page="+encodeURIComponent(l).replace("+","%2B")+"&mod=%241%24wq1rdBcg%240AZD2uQKdE.%2FVMQ.EuI3B0"+"&opts=17276&num=20");if (typeof s!="undefined") document.getElementsByTagName("head")[0].appendChild(s);})(); hcb_user.submit="";/*-->*/ </script>
<!-- end htmlcommentbox.com -->

.CSS:

    #HCB_comment_box{
margin-left:98px;
margin-right:98px;
}

我不太确定js是如何加载文本框的,但你可以试试这些:

1-在标签之间移动下面的代码:

<link rel="stylesheet" type="text/css" href="//www.htmlcommentbox.com/static/skins/shady/skin.css" />

2-现在你可以内联样式(即使不推荐,也只在必要时使用):

 <div id="HCB_comment_box" style='margin-left:98px !important;margin-right:98px !important;'><a href="http://www.htmlcommentbox.com">Widget</a> is loading comments...</div>

3-但我猜你正试图将div居中,所以我建议这样做:

<div id="HCB_comment_box" style='margin:0px auto !important;'><a href="http://www.htmlcommentbox.com">Widget</a> is loading comments...</div>

"!important"是强制或确保这些规则得到应用。