简体   繁体   English

保证金在CSS中不起作用

[英]Margin not working in CSS

I've been looking for solutions everywhere but I can't understand how to separate the text from the iframe. 我一直在寻找解决方案,但我不明白如何将文本与iframe分开。 Everything I tried did not work (for example, this answer). 我尝试的所有方法均无效(例如, 答案)。 This is a screenshot to have an idea: 这是一个有想法的屏幕截图:

问题

this is the HTML (I used it very rarely in my life and never worked with containers before, so I'm sure the error is clearly visible to someone more skilled than me): 这是HTML(我一生中很少使用它,并且以前从未使用过容器,因此,我敢肯定比我更熟练的人可以清楚看到该错误):

<div class="container">
  <iframe src="link" width="500px" height="500px" align="left" style="border: 1px solid #ccc" frameborder=0></iframe>
  <article>
    <font face="calibri" size="30" style="background-color: powderblue;">title</font>
    <h4></h4>
    <font face="verdana">text</font>
  </article>
</div>

This is the CSS (I was testing margin-left: 10px but 10 or 1000px won't change anything): 这是CSS(我正在测试margin-left: 10px但10或1000px不会改变任何内容):

article {
    margin-left: 10px;
    border-left: 1px solid gray;
    padding: 1em;
    overflow: hidden;
}

body {
    max-width: 100%;
}

div.container {
    width: 100%;
    border: 1px solid gray;
}

iframe {
    float: left;
    margin-right: 30px;
    margin-bottom: 20px;
    margin-left: 20px;
}

I think you could solve it by setting position: relative; 我认为您可以通过以下方式解决此问题position: relative; to your article tag. 到您的文章标签。 This way, you could then specify the position offset that you want it to have using the left property instead of using the margin-left property. 这样,您就可以使用left属性而不是margin-left属性来指定希望它具有的位置偏移量。

I mean: 我的意思是:

article {
    position: relative;
    left: 10px;
    border-left: 1px solid gray;
    padding: 1em;
    overflow: hidden;
}

body {
    max-width: 100%;
}

div.container {
    width: 100%;
    border: 1px solid gray;
}

iframe {
    float: left;
    margin-right: 30px;
    margin-bottom: 20px;
    margin-left: 20px;
}

If this is not exactly what you wanted, I also think that the position property, together with the left , right , top and bottom properties, seem quite suitable for your problem, so I suggest you should take a look of them. 如果这不是您想要的,我也认为position属性以及leftrighttopbottom属性似乎非常适合您的问题,因此我建议您看一下它们。

HTML5不支持iframe样式,因此无法通过样式表进行设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM