CSS。更改 li 边框长度
CSS. Change li border length
我有一个导航栏,并在每个列表项上添加了一个 :hover
。
不过我也有一个li:after
破美女
nav {
text-align: center;
}
li {
list-style: none;
padding: 10px;
padding-left: 0;
margin-top: 20px;
display: inline-block;
cursor: pointer;
}
nav li:not(:last-child):after {
content: '|';
margin: 10px;
}
li:hover {
border-bottom: 2px solid black;
}
<nav>
<ul>
<li>Chisinau, MD</li>
<li>Russia, RU</li>
<li>London, UK</li>
</ul>
</nav>
我想删除 li:after
处的 border-bottom
,我试过了,但似乎不起作用:
li:after:hover {
content: '';
border-bottom: none;
}
将 <a>
或 <span>
标签放在 <li>
内,像这样:
<li class='li'><a href="#">Chisinau, MD</a></li>
然后在它悬停时使用border-bottom
,像这样:
li a:hover {
border-bottom: 2px solid black;
}
And remember to style your <a>
for batter look.
Example:
li a{
color: #333;
text-decoration: none;
}
::after
伪元素呈现在元素内部,而不是元素之后。
所以如果你不想要伪元素下方的边框,你应该防止它对li
的大小产生影响。你可以通过绝对定位来实现:
li {
margin: 10px;
}
nav li:not(:last-child):after {
content: '|';
position: absolute; /* Take out-of-flow */
margin-left: 10px;
}
nav {
text-align: center;
}
li {
list-style: none;
padding: 10px 0;
margin-top: 20px;
display: inline-block;
cursor: pointer;
margin: 10px;
}
nav li:not(:last-child):after {
content: '|';
position: absolute;
margin-left: 10px;
}
li:hover {
border-bottom: 2px solid black;
}
<nav>
<ul>
<li>Chisinau, MD</li>
<li>Russia, RU</li>
<li>London, UK</li>
</ul>
</nav>
类似于@Oriol 的回答,但在 li
上使用 position:relative
,因此 ::after
将相对于 li
定位
li {
cursor: pointer;
display: inline-block;
list-style: outside none none;
margin: 10px;
position: relative;
}
nav li:not(:last-child)::after {
content: "|";
position: absolute;
right: -15px;
}
片段
/**
* Do not remove the comment below. It's the markers used by wiredep to inject
* sass dependencies when defined in the bower.json of your dependencies
*/
// bower:scss
// endbower
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
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 {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
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: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/*** */
@import url(http://fonts.googleapis.com/css?family=Roboto+Slab:400,700|Roboto:400,700,700italic,400italic);
@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(../../bower_components/material-design-iconfont/iconfont/MaterialIcons-Regular.eot);
/* For IE6-8 */
src: local('Material Icons'), local('MaterialIcons-Regular'), url(../../bower_components/material-design-iconfont/iconfont/MaterialIcons-Regular.woff2) format('woff2'), url(../../bower_components/material-design-iconfont/iconfont/MaterialIcons-Regular.woff) format('woff'), url(../../bower_components/material-design-iconfont/iconfont/MaterialIcons-Regular.ttf) format('truetype');
}
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
/* Preferred icon size */
display: inline-block;
width: 1em;
height: 1em;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;
/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;
/* Support for IE. */
font-feature-settings: 'liga';
}
html {
font-family: 'Roboto Slab', serif;
}
[layout=row] {
flex-direction: row;
}
.browsehappy {
margin: 0.2em 0;
background: #ccc;
color: #000;
padding: 0.2em 0;
}
md-toolbar.md-default-theme {
background-color: black;
}
section.jumbotron {
margin-bottom: 30px;
padding: 1px 30px;
background-color: #5aadbb;
text-align: center;
color: white;
}
h1 {
font-size: 3em;
}
.techs {
display: flex;
flex-flow: row wrap;
}
md-card {
width: 30%;
}
img.pull-right {
float: right;
width: 100px;
}
//MY-css
h1 {
text-align: center;
font-size: 50px;
// border:1px solid black;
margin: 0;
margin-top: 125px;
margin-bottom: 20px;
}
#head {
/* margin-top: -15.75px; */
// padding-top: 0;
height: 100px;
line-height: 100px;
background-color: rgb(153, 153, 153);
text-align: center;
font-size: 40px;
color: #fff;
}
nav {
// border: 1px solid black;
text-align: center;
}
li {
cursor: pointer;
display: inline-block;
list-style: outside none none;
margin: 10px;
position: relative;
}
nav li:not(:last-child)::after {
content: "|";
position: absolute;
right: -15px;
}
li:hover {
border-bottom: 2px solid black;
}
/**
* Do not remove the comment below. It's the markers used by gulp-inject to inject
* all your sass files automatically
*/
// injector
// endinjector
<div id='head'>Star METEO</div>
<nav>
<ul>
<!-- <li>Chisinau, MD</li> -->
<li class='li'>Chisinau, MD</li>
<li class='li'>Russia, RU</li>
<li class='li'>London, UK</li>
</ul>
</nav>
我有一个导航栏,并在每个列表项上添加了一个 :hover
。
不过我也有一个li:after
破美女
nav {
text-align: center;
}
li {
list-style: none;
padding: 10px;
padding-left: 0;
margin-top: 20px;
display: inline-block;
cursor: pointer;
}
nav li:not(:last-child):after {
content: '|';
margin: 10px;
}
li:hover {
border-bottom: 2px solid black;
}
<nav>
<ul>
<li>Chisinau, MD</li>
<li>Russia, RU</li>
<li>London, UK</li>
</ul>
</nav>
我想删除 li:after
处的 border-bottom
,我试过了,但似乎不起作用:
li:after:hover {
content: '';
border-bottom: none;
}
将 <a>
或 <span>
标签放在 <li>
内,像这样:
<li class='li'><a href="#">Chisinau, MD</a></li>
然后在它悬停时使用border-bottom
,像这样:
li a:hover {
border-bottom: 2px solid black;
}
And remember to style your
<a>
for batter look.Example:
li a{ color: #333; text-decoration: none; }
::after
伪元素呈现在元素内部,而不是元素之后。
所以如果你不想要伪元素下方的边框,你应该防止它对li
的大小产生影响。你可以通过绝对定位来实现:
li {
margin: 10px;
}
nav li:not(:last-child):after {
content: '|';
position: absolute; /* Take out-of-flow */
margin-left: 10px;
}
nav {
text-align: center;
}
li {
list-style: none;
padding: 10px 0;
margin-top: 20px;
display: inline-block;
cursor: pointer;
margin: 10px;
}
nav li:not(:last-child):after {
content: '|';
position: absolute;
margin-left: 10px;
}
li:hover {
border-bottom: 2px solid black;
}
<nav>
<ul>
<li>Chisinau, MD</li>
<li>Russia, RU</li>
<li>London, UK</li>
</ul>
</nav>
类似于@Oriol 的回答,但在 li
上使用 position:relative
,因此 ::after
将相对于 li
li {
cursor: pointer;
display: inline-block;
list-style: outside none none;
margin: 10px;
position: relative;
}
nav li:not(:last-child)::after {
content: "|";
position: absolute;
right: -15px;
}
片段
/**
* Do not remove the comment below. It's the markers used by wiredep to inject
* sass dependencies when defined in the bower.json of your dependencies
*/
// bower:scss
// endbower
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
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 {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
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: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/*** */
@import url(http://fonts.googleapis.com/css?family=Roboto+Slab:400,700|Roboto:400,700,700italic,400italic);
@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(../../bower_components/material-design-iconfont/iconfont/MaterialIcons-Regular.eot);
/* For IE6-8 */
src: local('Material Icons'), local('MaterialIcons-Regular'), url(../../bower_components/material-design-iconfont/iconfont/MaterialIcons-Regular.woff2) format('woff2'), url(../../bower_components/material-design-iconfont/iconfont/MaterialIcons-Regular.woff) format('woff'), url(../../bower_components/material-design-iconfont/iconfont/MaterialIcons-Regular.ttf) format('truetype');
}
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
/* Preferred icon size */
display: inline-block;
width: 1em;
height: 1em;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;
/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;
/* Support for IE. */
font-feature-settings: 'liga';
}
html {
font-family: 'Roboto Slab', serif;
}
[layout=row] {
flex-direction: row;
}
.browsehappy {
margin: 0.2em 0;
background: #ccc;
color: #000;
padding: 0.2em 0;
}
md-toolbar.md-default-theme {
background-color: black;
}
section.jumbotron {
margin-bottom: 30px;
padding: 1px 30px;
background-color: #5aadbb;
text-align: center;
color: white;
}
h1 {
font-size: 3em;
}
.techs {
display: flex;
flex-flow: row wrap;
}
md-card {
width: 30%;
}
img.pull-right {
float: right;
width: 100px;
}
//MY-css
h1 {
text-align: center;
font-size: 50px;
// border:1px solid black;
margin: 0;
margin-top: 125px;
margin-bottom: 20px;
}
#head {
/* margin-top: -15.75px; */
// padding-top: 0;
height: 100px;
line-height: 100px;
background-color: rgb(153, 153, 153);
text-align: center;
font-size: 40px;
color: #fff;
}
nav {
// border: 1px solid black;
text-align: center;
}
li {
cursor: pointer;
display: inline-block;
list-style: outside none none;
margin: 10px;
position: relative;
}
nav li:not(:last-child)::after {
content: "|";
position: absolute;
right: -15px;
}
li:hover {
border-bottom: 2px solid black;
}
/**
* Do not remove the comment below. It's the markers used by gulp-inject to inject
* all your sass files automatically
*/
// injector
// endinjector
<div id='head'>Star METEO</div>
<nav>
<ul>
<!-- <li>Chisinau, MD</li> -->
<li class='li'>Chisinau, MD</li>
<li class='li'>Russia, RU</li>
<li class='li'>London, UK</li>
</ul>
</nav>