简体   繁体   English

如何将CSS span应用于没有换行符的串联字符串?

[英]How can I apply CSS span to a concatenated string with NO line breaks?

I have the following code (in a Rocket Themed Joomla site) and I can't seem to get the Javascript to remove the newline when I add the last tag. 我有以下代码(位于Rocket主题的Joomla网站中),添加最后一个标记时,似乎无法获取Java脚本来删除换行符。 Here is the script: 这是脚本:

<head>

<script type="text/javascript">
var d = new Date();
var date = d.getDate();
var day = d.getDay();

function schoolDay5(){
//weekNo = Math.ceil(date/7); //See bottom of the page to see how it works
if (date%2 == 0)
return 2;
else
return 1;
}
window.onload=function(){
var str= "<span class='promo1 ribbon'>" + "Welcome to Stephen Leacock it is day " + schoolDay5()+ "<span>";
document.getElementById('notice').innerHTML=str;
}
</script>
</head>

<body>
<div id="notice"></div>
</body>

When I run this I get a new line on the last tag. 当我运行它时,我在最后一个标签上换了一行。 How can I just have this script spit out a single line? 我怎样才能让这个脚本吐出一行?

Here is the page showing the result: How it looks now 这是显示结果的页面: 现在的外观

In your CSS you've got that span element set to display: block; 在CSS中,您已将span元素设置为display: block; . And it contains a span also set to display: block; 它包含一个也设置为display: block;

You're getting a line break because the empty <span></span> that shows the graphic (to the right of the title) (.ribbon span) has a CSS style of display:block . 您正在换行,因为显示图形(标题右侧)(。ribbon span)的空白<span></span>具有CSS: display:block样式。 This causes it to show on it's own line. 这导致它显示在自己的行上。

To fix this, remove display:block and add float:right . 要解决此问题,请删除display:block并添加float:right

.ribbon span {background-repeat:no-repeat; padding-right:100px; background-position:100% -205px; min-height:45px; float:right;}

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

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