gpt4 book ai didi

html - 在 Bootstrap 中居中一个 4 列的 Div

转载 作者:行者123 更新时间:2023-11-28 03:59:17 25 4
gpt4 key购买 nike

我是 Bootstrap 的新手,遇到了麻烦。我已经搜索了一个小时,试图弄清楚如何让我制作的 div(旨在作为链接)显示在页面中央,但没有成功。下面是我的 HTML 和 CSS 代码,如果你能帮助我找出我做错了什么,我将不胜感激。

HTML

<!DOCTYPE html>

<html>
<head>
<link rel="stylesheet" type="text/css" href="categories.css">
<!-- 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">
<title>Categories</title>
</head>


<body>
<div class="container">

<div class="row">
<div class="category col-md-4 col-centered">
<a class="link" href="http://google.com">TEST</a>
</div>
</div>
</div>

<!-- 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>
</html>

CSS

.col-centered{
float: none;
margin-left: auto;
margin-right: auto;
}

.category {
text-align: center;
font-size: 5em;
background: #09719B;
border-style: solid;
border-color: black;
}

.category:hover {
background-color: #064661;
}

.category a{
color: white;
display: block;
}

.category:hover a{
color:white;
text-decoration: none;
}

最佳答案

将您的 categories.css 包含在 Bootstrap css 之后。像下面。这会覆盖 Bootstrap 样式。

<!-- 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">
<link rel="stylesheet" type="text/css" href="categories.css">

引用这个https://www.w3.org/TR/html401/present/styles.html#h-14.3.2

另一种使用 Bootstrap 类 .col-md-offset-4

关于html - 在 Bootstrap 中居中一个 4 列的 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43298825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com