为什么这个标签不居中?

时间:2012-12-13 11:01:14

标签: asp.net html css webforms

使用ASP.NET代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Requests.aspx.cs" Inherits="Portal.Requests"
    MasterPageFile="Portal.Master" Title="Requests Log" %>

<asp:Content runat="server" ContentPlaceHolderID="MainContentPlaceHolder">
    <div class="block" id="options">
        <h2>
            Requests Log
        </h2>
        <div style="padding: 12px 13px 0px 12px;">
            <asp:Label runat="server" Text="Search :" CssClass="label" />
            <asp:TextBox ID="txtSearch" runat="server" Size="16" CssClass="textbox" />
            <asp:Button ID="btnSearch" CssClass="button" Style="float: right" runat="server"  Text="Search" OnClick="Search" />
        </div>
        <div style="width: 100%; text-align:center; color: #4E1329; font-size: smaller; float:none; display:inline;">
            you can search by acc no and username
        </div>
        <div style="padding-top: 10px; width: 250px; margin-left: auto; margin-right: auto;">
            <asp:GridView ID="requestsGrid" runat="server" AutoGenerateColumns="False" GridLines="Horizontal">
                <Columns>
                    <asp:BoundField DataField="FirstColumn" HeaderText="Who and When" HeaderStyle-Width="120px" />
                    <asp:BoundField DataField="Type" HeaderText="Type" HeaderStyle-Width="40px" />
                    <asp:TemplateField HeaderText="File" HeaderStyle-Width="25px">
                        <ItemTemplate>
                            <asp:LinkButton ID="btnDownload" runat="server" Text=".zip" CommandArgument='<%# Bind("Id") %>'
                                OnClick="Download" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
            </asp:GridView>
        </div>
    </div>
</asp:Content>

呈现:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
    Requests Log
</title><link rel="shortcut icon" type="image/ico" href="favicon.ico" /><link rel="icon" href="favicon.ico" type="image/ico" /><link rel="stylesheet" type="text/css" href="Styles/Stylesheet.css" /><meta name="viewport" content="width = device-width, initial-scale = 1, user-scalable = yes" /><meta name="apple-mobile-web-app-capable" content="yes" /></head>
<body>
    <form method="post" action="Requests.aspx" id="ctl01">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTM3NTI0NjYyOQ9kFgJmD2QWAgIDD2QWAgIDD2QWAgIHDzwrABECAA8WBB4LXyFEYXRhQm91bmRnHgtfIUl0ZW1Db3VudAIWZAEQFgAWABYAFgJmD2QWLgIBD2QWBmYPDxYCHgRUZXh0BRI1IGRheXMgYWdvIGJ5IG1hc2lkZAIBDw8WAh8CBQZHVTk5OTlkZAICD2QWAgIBDw8WAh4PQ29tbWFuZEFyZ3VtZW50BQExZGQCAg9kFgZmDw8WAh8CBRI1IGRheXMgYWdvIGJ5IG1hc2lkZAIBDw8WAh8CBQZHVTk5OTlkZAICD2QWAgIBDw8WAh8DBQE4ZGQCAw9kFgZmDw8WAh8CBRI1IGRheXMgYWdvIGJ5IG1hc2lkZAIBDw8WAh8CBQRDQUFSZGQCAg9kFgICAQ8PFgIfAwUCMTJkZAIED2QWBmYPDxYCHwIFEjUgZGF5cyBhZ28gYnkgbWFzaWRkAgEPDxYCHwIFBENBQVJkZAICD2QWAgIBDw8WAh8DBQIxM2RkAgUPZBYGZg8PFgIfAgUSNSBkYXlzIGFnbyBieSBtYXNpZGQCAQ8PFgIfAgUEQ0FBUmRkAgIPZBYCAgEPDxYCHwMFAjE0ZGQCBg9kFgZmDw8WAh8CBRI1IGRheXMgYWdvIGJ5IG1hc2lkZAIBDw8WAh8CBQRDQUFSZGQCAg9kFgICAQ8PFgIfAwUCMTVkZAIHD2QWBmYPDxYCHwIFEjUgZGF5cyBhZ28gYnkgbWFzaWRkAgEPDxYCHwIFBENBQVJkZAICD2QWAgIBDw8WAh8DBQIxNmRkAggPZBYGZg8P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zFkZAITD2QWBmYPDxYCHwIFEjIgZGF5cyBhZ28gYnkgbWFzaWRkAgEPDxYCHwIFBENBQVJkZAICD2QWAgIBDw8WAh8DBQIzMmRkAhQPZBYGZg8PFgIfAgUSMiBkYXlzIGFnbyBieSBtYXNpZGQCAQ8PFgIfAgUEQ0FBUmRkAgIPZBYCAgEPDxYCHwMFAjMzZGQCFQ9kFgZmDw8WAh8CBRIyIGRheXMgYWdvIGJ5IG1hc2lkZAIBDw8WAh8CBQRDQUFSZGQCAg9kFgICAQ8PFgIfAwUCMzRkZAIWD2QWBmYPDxYCHwIFEXllc3RlcmRheSBieSBtYXNpZGQCAQ8PFgIfAgUGR1U5OTk5ZGQCAg9kFgICAQ8PFgIfAwUCMzVkZAIXDw8WAh4HVmlzaWJsZWhkZBgBBSljdGwwMCRNYWluQ29udGVudFBsYWNlSG9sZGVyJHJlcXVlc3RzR3JpZA88KwAMAQgCAWR+8m8SIKqbNyNbkrQBusmcNv8bCI0kMOXnKhs2eQPoUA==" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['ctl01'];
if (!theForm) {
    theForm = document.ctl01;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<script src="/WebResource.axd?d=QZPkRLZ3fUaN6VLGec8U1eb-7A0RmvYeX7AOUpyZg60IpqTruzWtehyWdkhkl9lfeQb8mEYo0i4n5nosbE2UTMyeu9sobarSJxcUx83SFPs1&amp;t=634768237750540983" type="text/javascript"></script>


<script src="/ScriptResource.axd?d=gH6INTDR0ghdGy8187seiZld9-3hIDEUD4UZXxgbQNevT34BY6bPtKCTN86kvXWivVi5j4Mqk82c9kJeg-HGZ1gkOzd2OkB_H1SFfAw8T0nkn2J_yq_n7Tko8qp8GK6S2sFuEB6V36qw4i4I9UtNBZbY8gEyl8T9hpNAHBP1Ncc0EIlDqB6rGCKHSEZk0IqO0&amp;t=ffffffff940d030f" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
//]]>
</script>

<script src="/ScriptResource.axd?d=SZ7Iu2p7Dx3sirGc0eodEyXdoKWQbBb85Myy8mEmJcXjSVSUbobpetDKV_2kbrQbyRsPhW2vufjIr6XDGEt7v-ukuTFQq2fNuNOHhcfIHAnmuQRWEXvmSJLpONklLNI8hQI7wxVjfx7Qg6EKoJkMvo4NWxeD_ZHIemwcs1W1QwmKgcv6UKwwzLFcarl9GeoC0&amp;t=ffffffff940d030f" type="text/javascript"></script>
<div class="aspNetHidden">

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWGQKutYr8AwLI4arfCwLM08eUAgLIs/LdCwL5l4+IBwKqhYmXBwLjpMWIAgLsw7D4AQKN7v/UCQLu7ta3DALHv6LwCwKV16SoBwLup/DgBgLHs/78AwL4l5unDwKphZW2DwLipNGnCgLrw7yXCgKM7ov0AQLt7uLWBALGv66PBAKT17BRAuyn/AkCxbOKpg0C9pen0AiNJ9hTWsRav+IvckroC8qB9LGJ+gh+z0AvBqjhxR2QQA==" />
</div>
    <script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ctl00$ScriptManager1', 'ctl01', [], [], [], 90, 'ctl00');
//]]>
</script>


    <div id="header" style="text-align:center;padding-top:5px;"> 
        <img id="uaLogo" alt="UA Logo" src="../UALogo.png" />
    </div>


    <div id="wrapper">

    <div class="block" id="options">
        <h2>
            Requests Log
        </h2>
        <div style="padding: 12px 13px 0px 12px;">
            <span class="label">Search :</span>
            <input name="ctl00$MainContentPlaceHolder$txtSearch" type="text" id="MainContentPlaceHolder_txtSearch" class="textbox" Size="16" />
            <input type="submit" name="ctl00$MainContentPlaceHolder$btnSearch" value="Search" id="MainContentPlaceHolder_btnSearch" class="button" style="float: right" />
        </div>
        <div style="width: 100%; text-align:center; color: #4E1329; font-size: smaller; float:none; display:inline;">
            you can search by acc no and username
        </div>
        <div style="padding-top: 10px; width: 250px; margin-left: auto; margin-right: auto;">
            <div>
    <table cellspacing="0" rules="rows" border="1" id="MainContentPlaceHolder_requestsGrid" style="border-collapse:collapse;">
        <tr>
            <th scope="col" style="width:120px;">Who and When</th><th scope="col" style="width:40px;">Type</th><th scope="col" style="width:25px;">File</th>
        </tr><tr align="center" valign="middle">
            <td>5 days ago by masi</td><td>GU9999</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_0" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl02$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>5 days ago by masi</td><td>GU9999</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_1" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl03$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>5 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_2" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl04$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>5 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_3" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl05$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>5 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_4" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl06$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>5 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_5" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl07$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>5 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_6" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl08$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>5 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_7" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl09$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>5 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_8" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl10$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>5 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_9" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl11$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>5 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_10" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl12$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>5 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_11" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl13$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>2 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_12" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl14$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>2 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_13" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl15$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>2 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_14" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl16$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>2 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_15" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl17$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>2 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_16" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl18$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>2 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_17" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl19$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>2 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_18" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl20$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>2 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_19" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl21$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>2 days ago by masi</td><td>CAAR</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_20" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl22$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr><tr align="center" valign="middle">
            <td>yesterday by masi</td><td>GU9999</td><td>
                            <a id="MainContentPlaceHolder_requestsGrid_btnDownload_21" href="javascript:__doPostBack(&#39;ctl00$MainContentPlaceHolder$requestsGrid$ctl23$btnDownload&#39;,&#39;&#39;)">.zip</a>
                        </td>
        </tr>
    </table>
</div>
        </div>
    </div>

    </div>





    </form>
</body>
</html>

css:

.block
{
    margin: 0 auto;
    width: 440px;
    background-color: #FAFAFA;
    border-radius: 6px;
    box-shadow: 3px 3px 3px #888888;
    padding-bottom: 10px;
    border: 1px solid #4e1329;
}

.block > *
{
    position: relative;
}

#options
{
    width: 273px;
    height: auto;
}

我明白了:

enter image description here

为什么label / div(香港专业教育学院试过这两个)不是中心?

4 个答案:

答案 0 :(得分:2)

变化:

<div style="text-align:center; color: #4E1329; font-size: smaller; float:none">
    you can search by acc no and username
</div>

<div style="width: 100%; text-align:center; color: #4E1329; font-size: smaller; display:inline;">
    you can search by acc no and username
</div>

注意:您可能还需要考虑使用CSS类而不是内联样式。

编辑:看到您的修改后,您的班级block需要设置宽度。为了使文本能够居中,它需要100%宽度。为了使100%宽度起作用,您需要具有宽度的父级。如果block有宽度,请为它发布CSS。

编辑 - 最终修订:

display:inline现在让人感到困惑。这个和float:none;需要删除。

<div style="width: 100%; text-align:center; color: #4E1329; font-size: smaller;">
    you can search by acc no and username
</div>

小提琴示例:http://jsfiddle.net/QCvaP/1/

答案 1 :(得分:0)

似乎它与周围的div有关。如果你用固定的方式放一个div,一切看起来都很好。

HTML:

<div style="width: 300px; border: 1px solid red;">
    <div style="padding: 12px 13px 0px 12px;">
        <span class="label">Search :</span>
        <input name="ctl00$MainContentPlaceHolder$txtSearch" type="text" id="MainContentPlaceHolder_txtSearch" class="textbox" Size="16" />
        <input type="submit" name="ctl00$MainContentPlaceHolder$btnSearch" value="Search" id="MainContentPlaceHolder_btnSearch" class="button" style="float: right" />
    </div>
    <div style="text-align:center; color: #4E1329; font-size: smaller; float:none">
        you can search by acc no and username
    </div>
</div>    ​

小提琴:http://jsfiddle.net/2c37L

答案 2 :(得分:0)

两个div都是分开的,div上面有填充。尝试在div下面添加填充,例如

style ="padding: 12px 13px 0px 12px;text-align:center;"

我希望这会奏效。

答案 3 :(得分:0)

你的Div有一个内联CSS,它说你的div是display:inline。这是出于特殊原因吗?因为如果你删除它,你会发现Div成为中心对齐。

http://jsfiddle.net/7gdnH/1/