简体   繁体   English

在div中对齐文本

[英]Aligning text inside a div

In the below code 在下面的代码中

 var panel=<div name="panel" id="panel" style="display:inline;position: absolute; margin-left: auto;margin-right:auto;left: 0;right: 0;width:350px;height: 100px;filter:alpha(opacity=50);">testfield1</div>' ;
  panel = panel + '&nbsp&nbsp<div id ="name" style="display:inline;position: absolute; margin-left: auto;margin-right:auto;left: 350px;right: 0;width:750px;height: 100%;border-color:black;">
        panel = panel + 'This is a test</div>

The text "This is a test" appears at the bottom of the div, whereas "testfield1" appears at the center. 文本“ This is a test”出现在div的底部,而“ testfield1”出现在div的底部。 How to make both pieces of text inline with each other? 如何使两段文字彼此内联?

Thanks. 谢谢。

This is WAY too un-readable. 这太不可读了。

A few pointers though from what I CAN see 虽然我可以看到一些提示

Use the StringBuilder class instead of concatenating all of those strings 使用StringBuilder类,而不是串联所有这些字符串

System.Text.StringBuilder sb = new System.Text.StringBuilder()

sb.Append(@"<div id=""panel"">");

...

string panel = sb.ToString();

I don't think you need to add the name attribute to your divs, id normally suffices 我认为您不需要在div中添加name属性,id通常就足够了

Seperate out the styles into a seperate style sheet (css) and get rid of all the un-necessary non breaking spaces 将样式分离到单独的样式表(css)中,并消除所有不必要的不​​间断空格

In your css you want something like 在您的CSS中,您想要类似

div#panel
{
    display: inline;
    position: absolute;
    ...
}

    div#panel #name
    {
        display: inline;
        position: absolute;
    }

Also combine styles where you can, for example the above could be re-written as 还要在可能的地方结合样式,例如上面的内容可以重写为

div#panel, div#panel #name
{
    display: inline;
    position: absolute;
    ...
}

Then poeple will able to help you debug your css 然后,poeple将能够帮助您调试CSS

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

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