如何将<asp:panel>宽度设置为内容大小的25%</asp:panel>

时间:2012-05-24 12:09:24

标签: c# asp.net

您好,有人可以告诉我如何给panel.width一个25%的内容大小?

4 个答案:

答案 0 :(得分:4)

像这样定义Panel:

<asp:Panel CssClass="CustomWidth" ID="MyPanel" runat="server"> </asp:Panel> 

然后链接到设置以下内容的外部css样式表:

.CustomWidth{     width: 25%; }

答案 1 :(得分:3)

您可以使用jQuery

假设Panel1是您的面板的ID,并且您希望根据的相应内容容器是Container1

var dWidth = $('#Container1').width();
$('#Panel1').width(dWidth * 0.25);

Panel1的宽度设置为您使用的容器的25%。

只需决定您要使用哪个容器(可能是div或类似的东西,您没有向我们展示您的代码)

答案 2 :(得分:0)

如果您不使用JavaScript,则可以在CodeBehind文件中编写C#代码:

Panel1.Style.Add("width", "25%");

答案 3 :(得分:-1)

我真的不明白你的问题,但它看起来像JavaScript Jobe, 例如:

var Element_Id = document.getElementById("Elem_Id"); // Element Id
var curr_Element_Width = parseInt(Element_Id.clientWidth); // parseInt is taking down our "px" string at the width.... look:
var curr_Element_Id_Width = 100px we need INT only!
we only need the number 100 so after parseInt its now 100 and not 100px we can't work with string's and that is the reson we doing that,

然后你可以使用像这样的功能......

function addWidth() {
    Element_Id.style.width = (curr_Element_Width + 100) + 'px'; // after we change the width we add the "px" string again
} 

在这里我们与Px合作,但你也可以这样做,希望它会帮助你,祝你有个美好的一天。

相关问题