html - anchor 标记的填充

标签 html css asp.net padding

我有一个 asp.net 页面,代码如下所示。

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

  <!DOCTYPE html>

  <html xmlns="http://www.w3.org/1999/xhtml">

  <head runat="server">
    <title></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
    <style>
      body {
        margin: 0px;
      }
      header,
      footer {
        background-color: black;
        color: white;
        padding: 20px;
        text-align: center;
      }
      header {
        position: fixed;
        top: 0;
        width: 100%;
      }
      header li {
        display: inline-block;
        border: 1px solid rgb(0, 153, 255);
        background-color: dodgerblue;
      }
      header li:hover {
        background-color: white;
      }
      header a {
        text-decoration: none;
        color: white;
        padding: 15px;
      }
      header a:hover {
        color: dodgerblue;
      }
    </style>
  </head>

  <body>

    <form id="form1" runat="server">
      <div>
        <header runat="server">
          <h1>Welcome to SAIC</h1>
          <asp:Menu ID="MainMenu" runat="server" Orientation="Horizontal">
            <Items>
              <asp:MenuItem Value="Home" NavigateUrl="~/Home.aspx"></asp:MenuItem>
              <asp:MenuItem Value="Login" NavigateUrl="~/Login.aspx"></asp:MenuItem>
              <asp:MenuItem Value="Add Products" NavigateUrl="~/Add Products.aspx"></asp:MenuItem>
              <asp:MenuItem Value="View Product Details" NavigateUrl="~/View Product Details.aspx"></asp:MenuItem>
            </Items>
          </asp:Menu>
        </header>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
      </div>
      <footer>
        <p>Copyrights @ 2016</p>
      </footer>
    </form>
  </body>

  </html>

我已经为 anchor 标记应用了填充。但只有padding-toppadding-bottom正在设置。左边和右边的填充没有出现。

我试过设置 padding: 15px 15px 15px 15px;但这也行不通。

这是生成的源代码。 /* <![CDATA[ */正在自动生成。 https://jsfiddle.net/q2Lcrgux/

最佳答案

anchor 标签是一个内联元素。填充不适用于内联元素。您必须将其作为 block 元素。使它们成为 inline-block 必须有效。 http://jsfiddle.net/LinkinTED/4d7q6gwp/

<a href="#" style="display:block;padding:10px">Click here</a>

风格:

a
{
    display:inline-block;
}

关于html - anchor 标记的填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38887042/

相关文章:

javascript - 关闭 JavaScript 中的脚本?

javascript - 如何使用具有相同名称的 jquery 获取每个输入字段的值?

c# - 创建随机颜色 (System.Drawing.Color)

sql - 从表中选择 @variable in(表列)

html - 我该如何修复这个 css 左对齐?

html - 现代浏览器关心 DOCTYPE 吗?

html - 如何删除跨度并在点击时在跨度下播放 youtube 视频?

css - 使用 Ryan Fait 的方法嵌入子页脚

jquery - 使用动态高度 parent 时如何阻止 child 剪裁?

asp.net - foreach block 缺少结束的 "}"字符。确保你有一个匹配的 "}"