gpt4 book ai didi

html - 如何在 html/css 中对齐 'a' 元素

转载 作者:太空宇宙 更新时间:2023-11-03 20:18:43 25 4
gpt4 key购买 nike

我需要在中心对齐一个“a”元素

HTML代码:

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link href='http://fonts.googleapis.com/css?family=Cedarville+Cursive' rel='stylesheet' type='text/css'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>

<body>

<h1>Olive</h1>
<a href="page1.html">Enter</a>

</body>
</html>

CSS 代码:

body {
background-color: olive;
}

h1 {
font-family: 'Cedarville Cursive', cursive;
font-size: 230px;
text-align: center;
}

a {
font-family: 'Cedarville Cursive', cursive;
color: white;
font-size: 100px;
text-decoration: none;

我在 CSS 表的“a”元素中使用了“text-align”,但它没有改变。

最佳答案

text-align:center;当您将文本应用于 <a> 时,将文本居中放置在元素内, 您将 <a> 中的文本居中在里面,但是 <a>是一个内联元素,它不会拉伸(stretch),所以你需要把它放在 div 里面.

<div> <a> Ha </a> </div>

div{
text-align:center;
}

关于html - 如何在 html/css 中对齐 'a' 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15423943/

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