我尝试了大部分方法,但我无法将导航栏中的链接居中对齐。
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import mglearn
from pandas.plotting import scatter_matrix
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
iris_dataset = load_iris()
X_train,X_test,Y_train,Y_test = train_test_split(iris_dataset['data'],iris_dataset['target'],random_state=0)
iris_dataframe = pd.DataFrame(X_train,columns=iris_dataset.feature_names)
grr = scatter_matrix(iris_dataframe,c = Y_train,figsize = (15,15),marker = 'o',
hist_kwds={'bins':20},s=60,alpha=.8,cmap = mglearn.cm3)
plt.show()

.navbar-nav {
margin: 30px 20px !important;
}
a {
/* color: #fff !important;*/
font-family: 'Caesar Dressing';
font-size: 18px;
padding: 10px 30px !important;
}
a:hover {
border: 2px solid #fff !important;
background-color: transparent !important;
}
.active {
border: 2px solid #fff !important;
background-color: transparent !important;
}

但我希望所有4个链接都在屏幕上垂直居中
答案 0 :(得分:2)
您可以使用text-align
li
这样的navbar
属性来实现此目的
.navbar-nav > li
{
text-align :center;
}
.navbar-nav {
margin: 30px 20px !important;
}
a {
/* color: #fff !important;*/
font-family: 'Caesar Dressing';
font-size: 18px;
padding: 10px 30px !important;
}
a:hover {
border: 2px solid #fff !important;
background-color: transparent !important;
}
.active {
border: 2px solid #fff !important;
background-color: transparent !important;
}
.navbar-nav > li
{
text-align :center;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<body>
<div class="container-fluid bg">
<nav class="navbar">
<div class="container-fluid">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Education</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</nav>
</div>
</body>
&#13;
答案 1 :(得分:1)
.navbar-nav > li > a
{
text-align :center;
}
为你的css添加瘦身。
答案 2 :(得分:0)
使用此CSS,
.navbar-nav{
position: relative;
left: 50%;
transform: translateX(-50%);
}
.navbar-nav > li{
margin: 0 5px;
display: inline-block;
vertical-align: top;
}
.navbar-nav > li > a {
margin: 5px 0;
background-color: #ccc;
}
答案 3 :(得分:0)
请尝试以下代码:
.navbar-nav {
width: 100%;
text-align: center;
> li {
float: none;
display: inline-block;
}
}
用于居中对齐整个内部链接
答案 4 :(得分:0)
只需添加带有容器流体的文本中心类
<body>
<div class="container-fluid bg">
<nav class="navbar">
<div class="container-fluid text-center">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Education</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</nav>
</div>
</body>