[英]margin right doesn't work inside block
I'm trying to set the margins to a text, however margin-right doesn't seem to work inside message. 我正在尝试将边距设置为文本,但是右边距似乎在消息中似乎不起作用。 Why?
为什么?
css: CSS:
message
{
position: fixed;
display: block;
margin-bottom: 0px;
width: 100%;
height: 40px;
background-color: rgba(26, 119, 212, 100);
line-height: 40px;
font-style: italic;
text-align: left;
overflow: hidden;
}
.messageotext
{
width: 100%;
margin-right: 0px;
}
html: 的HTML:
<message><span class="messageotext">prova</span></message>
I want the text to be out the screen so I can translate it by scripting language from right to left. 我希望文本不显示在屏幕上,所以我可以通过脚本语言从右到左进行翻译。
You have given width:100%
and the parent is fixed
so it will not effect If you remove your width:100%
of span
you will see margin-right
您已给定
width:100%
,并且父级是fixed
所以不会起作用。如果您删除width:100%
的span
您将看到margin-right
so you can add text-align:right
to parent which will show the effect of margin-right
or you can also use float:right
因此您可以将
text-align:right
添加到parent,这将显示margin-right
的效果,或者您也可以使用float:right
Removed browser default styles by adding 通过添加删除浏览器的默认样式
*{
margin:0;
padding:0;
}
* { margin: 0; padding: 0; } message { position: fixed; display: block; margin-bottom: 0px; width: 100%; height: 40px; background-color: rgba(26, 119, 212, 100); line-height: 40px; font-style: italic; text-align: left; overflow: hidden; text-align: right; } .messageotext { /* width: 100%;*/ margin-right: 100px; }
<message><span class="messageotext">prova</span> </message>
You can modify your class messageotext with the following code: 您可以使用以下代码修改您的类messageotext:
.messageotext {
width: 100%;
position: absolute;
left: 100%;
}
Then you can decrease the value of left property to translate it from right to left. 然后,您可以减小left属性的值以将其从右向左转换。
Try using float:right
尝试使用
float:right
or you can also use only right:0px
if position
is absolute
或者,如果
position
是absolute
也可以只使用right:0px
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.