html - 如何在列表中的 Font Awesome 图标后放置换行符?

标签 html css responsive-design

我正在尝试创建一个类似 LinkedIn 的菜单,其中的按钮由文本顶部的图标组成,但我找不到在 FontAwesome 图标后以 CSS 形式插入换行符的方法。对于其余部分,我的脚本看起来很符合我的喜好。

尽管有display:block#sidebar nav ul li由于某种原因,它没有提供想要的结果,最近我也尝试输入 <br>作为content在图标之后。

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;
}
 html {
     box-sizing: border-box;
}
 *, *:before, *:after {
     box-sizing: inherit;
}
 body, input, select, textarea {
     color: rgba(0, 0, 0, 0.55);
     font-family: Arial, Helvetica, sans-serif;
     font-size: 16.5pt;
     font-weight: normal;
     line-height: 1.5;
}
 .icon {
     text-decoration: none;
     border-bottom: none;
     margin-right: 5px;
     position: relative;
     color: rgba(0, 0, 0, 0.55);
}
 .icon:before {
     font-size: 1.75em;
     font-style: normal;
     text-transform: none !important;
}
 ul.icons {
     cursor: default;
     list-style: none;
     padding-left: 0;
}
 ul.icons li {
     display: inline-block;
     padding: 0 0.75em 0 0;
}
 ul.icons li:last-child {
     padding-right: 0;
}
 ul.icons li > a, ul.icons li > span {
     border: 0;
     text-decoration: none;
}
 ul.icons li > a:before, ul.icons li > span:before {
     font-family: FontAwesome;
     font-style: normal;
     font-weight: normal;
     text-transform: none !important;
}
 ul.icons li > a .label, ul.icons li > span .label {
     display: none;
}
 ul.menu {
     list-style: none;
     padding: 0;
}
 ul.menu > li {
     border-left: solid 1px rgba(0, 0, 0, 0.5);
     display: inline-block;
     line-height: 1;
     margin-left: 1.5em;
     padding: 0 0 0 1.5em;
}
 ul.menu > li:first-child {
     border-left: 0;
     margin: 0;
     padding-left: 0;
}
 @media screen and (max-width: 480px) {
     ul.menu > li {
         border-left: 0;
         display: block;
         line-height: inherit;
         margin: 0.5em 0 0 0;
         padding-left: 0;
    }
}
 #sidebar {
     padding: 2.5em 2.5em 0.5em 2.5em ;
     background: #ffffff;
     border-right: 1px solid black;
     cursor: default;
     height: 100vh;
     left: 0;
     overflow-x: hidden;
     overflow-y: auto;
     position: fixed;
     text-align: right;
     top: 0;
     width: 18em;
     z-index: 10000;
}
 #sidebar > .inner {
     display: flex;
     flex-direction: column;
     justify-content: center;
     min-height: 100%;
     opacity: 1;
     width: 100%;
}
 body.is-ie #sidebar > .inner {
     height: 100%;
}
 #sidebar nav > ul {
     list-style: none;
     padding: 0;
     white-space: pre: 
}
 #sidebar nav > ul > li {
     margin: 1.5em 0 0 0;
     opacity: 1;
     padding: 0;
     position: relative;
}
 #sidebar nav a {
     border: 0;
     color: rgba(0, 0, 0, 0.35);
     display: block;
     font-size: 0.6em;
     font-weight: bold;
     letter-spacing: 0.25em;
     line-height: 1.75;
     outline: 0;
     padding: 1.35em 0;
     position: relative;
     text-decoration: none;
     text-transform: uppercase;
}
 #sidebar nav a:before, #sidebar nav a:after {
     border-radius: 0.2em;
     bottom: 0;
     content: '';
     height: 0.3em;
     position: absolute;
     right: 0;
     width: 100%;
}
 #sidebar nav a:before {
     background: rgb(0, 0, 0, 0.5);
}
 #sidebar nav a:after {
     background-image: -moz-linear-gradient(to right, #003085, #029bde);
     background-image: -webkit-linear-gradient(to right, #003085, #029bde);
     background-image: -ms-linear-gradient(to right, #003085, #029bde);
     background-image: linear-gradient(to right, #003085, #029bde);
     max-width: 0;
}
 #sidebar nav a:hover {
     color: rgba(0, 0, 0, 0.55);
}
 #sidebar nav a.active {
     color: #4267b2;
}
 #sidebar nav a.active:after {
     max-width: 100%;
}
 #sidebar nav a.active span {
     color: #4267b2;
}
 @media screen and (max-width: 1280px) {
     #sidebar {
         border-right: 0px;
         border-bottom: 1px solid black;
         height: 3.5em;
         left: 0;
         line-height: 3.5em;
         overflow: hidden;
         padding: 0;
         text-align: center;
         top: 0;
         width: 100%;
    }
     #sidebar > .inner {
         flex-direction: row;
         align-items: stretch;
         height: inherit;
         line-height: inherit;
    }
     #sidebar nav {
         height: inherit;
         line-height: inherit;
    }
     #sidebar nav ul {
         display: -moz-flex;
         display: -webkit-flex;
         display: -ms-flex;
         display: flex;
         height: inherit;
         line-height: inherit;
         margin: 0;
    }
     #sidebar nav ul li {
         display: block;
         height: inherit;
         line-height: inherit;
         margin: 0 0 0 2em;
         padding: 0;
    }
     #sidebar nav a {
         height: inherit;
         line-height: 2em;
    }
     #sidebar nav a:after {
         background-image: none;
         background-color: #4267b2;
    }
     #sidebar nav span:after {
         content: "</br>";
    }
}
<!DOCTYPE HTML>
<html>
	<head>
		<title>LinkedIn like menu</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
		<link rel="stylesheet" href="assets/css/main2.css" />
		<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" />
	</head>
	<body>

		<section id="sidebar">
			<div class="inner">
				<nav>
					<ul>
						<li><a href="#home"><span class="icon fas fa-user"></span>Home</a></li>
						<li><a href="#about"><span class="icon fas fa-search"></span>About</a></li>
						<li><a href="#contact"><span class="icon fas fa-phone"></span>Contact</a></li>
					</ul>
				</nav>
			</div>
		</section>

		<script src="assets/js/main.js"></script>		
	</body>
</html>

最佳答案

这应该是你想要实现的。

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;
}

html {
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body,
input,
select,
textarea {
  color: rgba(0, 0, 0, 0.55);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16.5pt;
  font-weight: normal;
  line-height: 1.5;
}

.icon {
  text-decoration: none;
  border-bottom: none;
  margin-right: 5px;
  position: relative;
  color: rgba(0, 0, 0, 0.55);
}

.icon:before {
  font-size: 1.75em;
  font-style: normal;
  text-transform: none !important;
}

ul.icons {
  cursor: default;
  list-style: none;
  padding-left: 0;
}

ul.icons li {
  display: inline-block;
  padding: 0 0.75em 0 0;
}

ul.icons li:last-child {
  padding-right: 0;
}

ul.icons li>a,
ul.icons li>span {
  border: 0;
  text-decoration: none;
}

ul.icons li>a:before,
ul.icons li>span:before {
  font-family: FontAwesome;
  font-style: normal;
  font-weight: normal;
  text-transform: none !important;
}

ul.icons li>a .label,
ul.icons li>span .label {
  display: none;
}

ul.menu {
  list-style: none;
  padding: 0;
}

ul.menu>li {
  border-left: solid 1px rgba(0, 0, 0, 0.5);
  display: inline-block;
  line-height: 1;
  margin-left: 1.5em;
  padding: 0 0 0 1.5em;
}

ul.menu>li:first-child {
  border-left: 0;
  margin: 0;
  padding-left: 0;
}

@media screen and (max-width: 480px) {
  ul.menu>li {
    border-left: 0;
    display: block;
    line-height: inherit;
    margin: 0.5em 0 0 0;
    padding-left: 0;
  }
}

#sidebar {
  padding: 2.5em 2.5em 0.5em 2.5em;
  background: #ffffff;
  border-right: 1px solid black;
  cursor: default;
  height: 100vh;
  left: 0;
  overflow-x: hidden;
  overflow-y: auto;
  position: fixed;
  text-align: right;
  top: 0;
  width: 18em;
  z-index: 10000;
}

#sidebar>.inner {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100%;
  opacity: 1;
  width: 100%;
}

body.is-ie #sidebar>.inner {
  height: 100%;
}

#sidebar nav>ul {
  list-style: none;
  padding: 0;
  white-space: pre:
}

#sidebar nav>ul>li {
  margin: 1.5em 0 0 0;
  opacity: 1;
  padding: 0;
  position: relative;
}

#sidebar nav a {
  border: 0;
  color: rgba(0, 0, 0, 0.35);
  display: block;
  font-size: 0.6em;
  font-weight: bold;
  letter-spacing: 0.25em;
  line-height: 1.75;
  outline: 0;
  padding: 1.35em 0;
  position: relative;
  text-decoration: none;
  text-transform: uppercase;
}

#sidebar nav a:before,
#sidebar nav a:after {
  border-radius: 0.2em;
  bottom: 0;
  content: '';
  height: 0.3em;
  position: absolute;
  right: 0;
  width: 100%;
}

#sidebar nav a:before {
  background: rgb(0, 0, 0, 0.5);
}

#sidebar nav a:after {
  background-image: -moz-linear-gradient(to right, #003085, #029bde);
  background-image: -webkit-linear-gradient(to right, #003085, #029bde);
  background-image: -ms-linear-gradient(to right, #003085, #029bde);
  background-image: linear-gradient(to right, #003085, #029bde);
  max-width: 0;
}

#sidebar nav a:hover {
  color: rgba(0, 0, 0, 0.55);
}

#sidebar nav a.active {
  color: #4267b2;
}

#sidebar nav a.active:after {
  max-width: 100%;
}

#sidebar nav a.active span {
  color: #4267b2;
}

span.icon {
  display: block;
}

@media screen and (max-width: 1280px) {
  #sidebar {
    border-right: 0px;
    border-bottom: 1px solid black;
    height: 3.5em;
    left: 0;
    line-height: 3.5em;
    overflow: hidden;
    padding: 0;
    text-align: center;
    top: 0;
    width: 100%;
  }
  #sidebar>.inner {
    flex-direction: row;
    align-items: stretch;
    height: inherit;
    line-height: inherit;
  }
  #sidebar nav {
    height: inherit;
    line-height: inherit;
  }
  #sidebar nav ul {
    display: -moz-flex;
    display: -webkit-flex;
    display: -ms-flex;
    display: flex;
    height: inherit;
    line-height: inherit;
    margin: 0;
  }
  #sidebar nav ul li {
    display: block;
    height: inherit;
    line-height: inherit;
    margin: 0 0 0 2em;
    padding: 0;
  }
  #sidebar nav a {
    height: inherit;
    line-height: 2em;
  }
  #sidebar nav a:after {
    background-image: none;
    background-color: #4267b2;
  }
}
<!DOCTYPE HTML>
<html>

<head>
  <title>LinkedIn like menu</title>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
  <link rel="stylesheet" href="assets/css/main2.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" />
</head>

<body>

  <section id="sidebar">
    <div class="inner">
      <nav>
        <ul>
          <li><a href="#home"><span class="icon fas fa-user"></span>Home</a></li>
          <li><a href="#about"><span class="icon fas fa-search"></span>About</a></li>
          <li><a href="#contact"><span class="icon fas fa-phone"></span>Contact</a></li>
        </ul>
      </nav>
    </div>
  </section>

  <script src="assets/js/main.js"></script>
</body>

</html>

关于html - 如何在列表中的 Font Awesome 图标后放置换行符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53897215/

相关文章:

C# html 电子邮件 - Div/文本覆盖图像

html - Windows 7手机Web开发问题

html - 如何在知道容器和箱子的大小的情况下找到容器内每个箱子的百分比(6)

html - 无法让 CSS 划分相互匹配,即使它们是相同的

jquery - 使用ajax加载时div不调整高度

css - slider 中的响应图像

html - Bootstrap 3/CSS : How to properly vertically align in panel heading

javascript - 在浏览器中自动完成 ="off"强制

javascript - 如何使用 Chart.js 删除不必要的重叠网格线?

android - -webkit-transform 在 Android webview 中不起作用