最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

HTML: How do I display an icon in the correct place when an icon to the left is optionally omitted: - Stack Overflow

programmeradmin127浏览0评论

I have an online page with a number of icons displayed, in pre-determined columns. Some of the icons are omitted based on the authority level of the admin person accessing the page. Even if an icon is omitted, I want following icons in the same line to be displayed in the correct columns. An example of what I am trying is (in C): The code in the else path being intended to cause a blank field to be output to take up the space taken by the "Member History" icon, so that the following icon will be in the same place irrespective of whether the "Member History" icon has been displayed.

fprintf(ouFile, "\<td align=center>");
If (Authority > 5)
{
    fprintf(ouFile, "<button class=\"button1\" type=submit name=u049>");
    fprintf(ouFile, "Member History");
    fprintf(ouFile, "\</button\>\</td>");
else
{
    fprintf(ouFile, "\<\"\&nbsp;\&nbsp;\&nbsp;\&nbsp;\");
    fprintf(ouFile, "\</td\>");
}
fprintf(ouFile, "\<td align=center>");

However, the result is as if I had not inserted the else path. The next icon in the row is shown in the column of the "Member History" icon if it had been included.

What am I doing wrong? How do I achieve what I wanted?

I have an online page with a number of icons displayed, in pre-determined columns. Some of the icons are omitted based on the authority level of the admin person accessing the page. Even if an icon is omitted, I want following icons in the same line to be displayed in the correct columns. An example of what I am trying is (in C): The code in the else path being intended to cause a blank field to be output to take up the space taken by the "Member History" icon, so that the following icon will be in the same place irrespective of whether the "Member History" icon has been displayed.

fprintf(ouFile, "\<td align=center>");
If (Authority > 5)
{
    fprintf(ouFile, "<button class=\"button1\" type=submit name=u049>");
    fprintf(ouFile, "Member History");
    fprintf(ouFile, "\</button\>\</td>");
else
{
    fprintf(ouFile, "\<\"\&nbsp;\&nbsp;\&nbsp;\&nbsp;\");
    fprintf(ouFile, "\</td\>");
}
fprintf(ouFile, "\<td align=center>");

However, the result is as if I had not inserted the else path. The next icon in the row is shown in the column of the "Member History" icon if it had been included.

What am I doing wrong? How do I achieve what I wanted?

Share Improve this question edited Jan 8 at 0:50 WarwickW 455 bronze badges asked Jan 6 at 9:51 WarwickWrWarwickWr 6
  • 1 The first fprintf() in the Else path has three double quotes (") on it, making the quotes unterminated. Was that just a typo in your post, or is that error in the original too? And when posting scripts or program code, please use the editing tools to apply code formatting (the {} button in the question/answer editing toolbar) to it, so the site won't re-wrap the lines and indentation works as appropriate for code. – telcoM Commented Jan 6 at 10:43
  • Why do you have the < in the else clause, as you are not supplying a tag? Also remove the superfluous quote adjacent to it – Vercingatorix Commented Jan 6 at 15:38
  • What is <fprintf supposed to be? – Barmar Commented Jan 6 at 23:30
  • Why do you escape characters that have no special meaning, like < and &? Were those added automatically by the Stacks Editor? – Barmar Commented Jan 6 at 23:31
  • The first tag you're printing in the else block makes no sense. You have < with no matching >. There's no tag name, just a bunch of &nbsp;. – Barmar Commented Jan 6 at 23:35
 |  Show 1 more comment

2 Answers 2

Reset to default 0
fprintf(ouFile, "<td align=center>");
if (Authority > 5)
{
    fprintf(ouFile, "<button class=\"button1\" type=\"submit\" name=\"u049\">");
    fprintf(ouFile, "Member History");
    fprintf(ouFile, "</button></td>");
}
else
{
    fprintf(ouFile, "&nbsp;</td>");
}

You need to ensure a <td> cell is always rendered, even if it's empty or contains a placeholder.

I have a whole series of these buttons, each representing a call to an application and called if particular conditions are true. When a button is not needed some of them leave a blank field and others do not. I have solved the problem empirically by putting in an extra <td></td> where necessary, to leave a blank spot for the omitted buttons, so that following buttons in the row end up in the correct column. That worked, but I do not understand why it is sometimes necessary to put in one set and other times to put in two sets. It does not seem to be caused by the cell width.

发布评论

评论列表(0)

  1. 暂无评论