3

我有一个浮动h2 a标签,在悬停时应用了 6px border-top。当我将鼠标悬停在文本上时,它会将文本和其下方的元素向下推。如何阻止边框移动文本和其他元素?谢谢!

我的 CSS:

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
  border: 0;
  font-size: 100%;
  font: inherit;
  margin: 0;
  padding: 0
}

article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
  display: block
}

body {
  line-height: 1
}

ol, ul {
  list-style: none
}

blockquote,
q {
  quotes: none
}

blockquote:before,
blockquote:after,
q:before,
q:after {
  content: none
}

table {
  border-collapse: collapse;
  border-spacing: 0
}

.container {
  width: 960px;
  margin: 0px auto;
}

.logo {
  float: left;
  clear: both;
  margin-top: 30px;
}

body {
  background-image: url("../images/bg.jpg");
  border-top: 8px solid black;
}

h2 a {
  font-family: arial;
  text-decoration: none;
  text-transform: uppercase;
  font-size: 94px;
  color: black;
  float: right;
  margin: 0px;
  padding-top: 20px;
}

h2 a:hover {
  border-top: 6px solid orange;
  padding-top: 0px;
}

.clocknotes {
  width: 437px;
  margin: 0px auto;
  clear: both;
}

.brand-three {
  clear: both;
  margin-top: 85px;
}

.brand-three {
  font-size: 200px;
  line-height: 140px;
  float: left;
  letter-spacing: -20px;
}

.quote {
  clear: both;
  width: 417px;
  float: right;
  text-align: right;
  margin-top: -250px;
  font-size: 26px;
}

.social {
  clear: both;
  float: right;
  margin-top: -80px;
}

.footer {
  clear: both;
  top: 50px;
  position: relative;
}
4

3 回答 3

15

CSS:

h2 a:hover {
    border-top: 6px solid orange;
    padding-top:14px;

}

演示:http: //jsfiddle.net/rathoreahsan/VyRZW/

于 2012-06-25T04:11:03.463 回答
2

减少等量的顶部填充,而不是零:

h2 a:hover {
border-top: 6px solid orange;
padding-top: 14px;
}
于 2012-06-25T04:06:56.297 回答
0

给出这个代码:

h2 a {border-top: 6px solid #fff;} /* Should match your background color */
于 2012-06-25T03:54:04.243 回答