简体   繁体   English

如何修正我的文字使其显示在一行上?

[英]How do I fix my text to make it appear on one line?

I would like my text to say "Like us on Facebook for the chance to win a prize." 我希望我的文字说“像我们在Facebook上一样有机会赢得大奖”。 I want the word "Facebook" linked but not underlined. 我希望将“ Facebook”一词链接起来但不加下划线。 I also want the text and link to be on one line. 我也希望文本和链接在一行上。 Here is what the output looks like now 这是现在的输出结果

Here is my code. 这是我的代码。

function popupWin() {
text =  "<html>\n<head>\n<title>Pop Window</title>\n<body>\n";
text += "<center>\n<br>";
text += "<h4>Like us on </h4>" + "<a href='myLink' target='_blank'><h4>Facebook</h4></a>" + " <h4>and win a prize</h4>";
text += "</center>\n</body>\n</html>\n";
setTimeout('windowProp(text)', 1000); 
}
function windowProp(text) {
newWindow = window.open('','newWin','width=300,height=200');
newWindow.document.write(text);
}
function popupWin() {
text =  "<html>\n<head>\n<title>Pop Window</title>\n<body>\n";
text += "<center>\n<br>";
text += "<h4>Like us on " + "<a href='myLink' target='_blank' style='text-decoration: none;'>Facebook</a>" + " and win a prize</h4>";
text += "</center>\n</body>\n</html>\n";
setTimeout('windowProp(text)', 1000); 
}
function windowProp(text) {
newWindow = window.open('','newWin','width=300,height=200');
newWindow.document.write(text);
}

popupWin();

One <h4> tag is sufficient to make whole text h4. 一个<h4>标记足以构成整个文本h4。 You don't need to multiplicate it. 您不需要将其相乘。

For not underlining Facebook link is responsible CSS text-decoration: none in an inline html attribute style . 负责CSS text-decoration: none是不强调Facebook链接text-decoration: none内联html属性style

function popupWin() {
      text =  "<html>\n<head>\n<title>Pop Window</title>\n<body>\n";
      text += "<center>\n<br>";
      text += "<h4 style="display:inline">Like us on </h4>" + "<a href='myLink' target='_blank' style="text-decoration:none; display:inline">    <h4 style="display:inline">Facebook</h4></a>" + " <h4 style="display:inline"> and win a prize</h4>";
      text += "</center>\n</body>\n</html>\n";
      setTimeout('windowProp(text)', 1000); 
}

Should work! 应该管用!

display:inline makes the elements come in one line display:inline使元素排成一行

text-decoration:none removes all the extra stuff like the underline. text-decoration:none删除所有多余的东西,例如下划线。

Better styling it with css file. 使用CSS文件更好地设置样式。 In your case, in order to remove the underline, you can set an id for the Facebook div, and style text-decoration to none. 对于您的情况,为了删除下划线,可以为Facebook div设置一个id,并将text-decoration的样式设置为none。 Additionally, to make it appear in one line, you can use either float:left or display:inline. 另外,要使其显示在一行中,可以使用float:left或display:inline。 You can use float:left because it'll turn block element into inline element. 您可以使用float:left,因为它将把block元素转换为inline元素。 Like Below 像下面

JS: JS:

function popupWin() {
text =  "<html>\n<head>\n<title>Pop Window</title>\n<body>\n";
text += "<center>\n<br>";
text += "<h4>Like us on</h4>" + "<h4><a href='myLink' target='_blank' id="facebook" Facebook</a></4>" + "<h4>and win a prize</h4>";
text += "</center>\n</body>\n</html>\n";
setTimeout('windowProp(text)', 1000); 
}
function windowProp(text) {
newWindow = window.open('','newWin','width=300,height=200');
newWindow.document.write(text);
}

CSS: CSS:

#facebook {
   text-decoration: none;
}
h4 {
   float:left // or display:inline
}

P/S: Or you can just remove all unnecessary h4 tag, since each h4 is a block element, so it'll automatically make new like when new h4 tag is made. P / S:或者您可以删除所有不必要的h4标签,因为每个h4都是一个块元素,所以它会像制作新的h4标签一样自动创建新标签。 so if you use only one h4 tag, it'll not make a new line. 因此,如果您仅使用一个h4标签,则不会添加新行。 Just like above answer. 就像上面的答案。

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

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