簡體   English   中英

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

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

我希望我的文字說“像我們在Facebook上一樣有機會贏得大獎”。 我希望將“ Facebook”一詞鏈接起來但不加下划線。 我也希望文本和鏈接在一行上。 這是現在的輸出結果

這是我的代碼。

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();

一個<h4>標記足以構成整個文本h4。 您不需要將其相乘。

負責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); 
}

應該管用!

display:inline使元素排成一行

text-decoration:none刪除所有多余的東西,例如下划線。

使用CSS文件更好地設置樣式。 對於您的情況,為了刪除下划線,可以為Facebook div設置一個id,並將text-decoration的樣式設置為none。 另外,要使其顯示在一行中,可以使用float:left或display:inline。 您可以使用float:left,因為它將把block元素轉換為inline元素。 像下面

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:

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

P / S:或者您可以刪除所有不必要的h4標簽,因為每個h4都是一個塊元素,所以它會像制作新的h4標簽一樣自動創建新標簽。 因此,如果您僅使用一個h4標簽,則不會添加新行。 就像上面的答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM