Html 使用css将文本居中对齐
我将以下代码用于简单图像库(在中可以找到实际代码,它可以完美地工作)。编辑css后,文本的对齐方式已更改。我想把文字对齐在中间。任何人都知道答案,请帮助我 我的HTML代码:Html 使用css将文本居中对齐,html,css,image,web,Html,Css,Image,Web,我将以下代码用于简单图像库(在中可以找到实际代码,它可以完美地工作)。编辑css后,文本的对齐方式已更改。我想把文字对齐在中间。任何人都知道答案,请帮助我 我的HTML代码: <html> <body> <div id="d"> <div class="img"> <a target="_blank" href="klematis_big.htm"> <img src="a.jpg"> </a> <div
<html>
<body>
<div id="d">
<div class="img">
<a target="_blank" href="klematis_big.htm">
<img src="a.jpg">
</a>
<div class="desc">
Add a description of the image here </div>
</div>
<div class="img">
<a target="_blank" href="klematis2_big.htm">
<img src="a.jpg">
</a>
<div class="desc">
<p>
Add a description of the image here</p>
</div>
</div>
<div class="img">
<a target="_blank" href="klematis3_big.htm">
<img src="a.jpg">
</a>
<div class="desc">
Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis4_big.htm">
<img src="a.jpg">
</a>
<div class="desc">
<p>
Add a description of the image here</P>
</div>
</div>
<div class="img">
<a target="_blank" href="klematis_big.htm">
<img src="a.jpg">
</a>
<div class="desc">
Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis2_big.htm">
<img src="a.jpg">
</a>
<div class="desc">
Add a description of the image here</div>
</div>
</div>
</body>
</html>
截图:
将css更改为
.desc
{
text-align:center;
font-weight:normal;
width:120px;
margin:2px;
}
更改对齐:居中代码>到文本对齐:居中代码>尝试以下操作:
.desc{
margin: 0 auto;
}
删除div的宽度
.desc {
text-align: center;
font-weight: normal;
margin: 2px;
}
并将其更改为。属性align不存在。您必须修改margin属性的值:
.desc
{
text-align:center;
font-weight:normal;
width:120px;
margin:2px auto;
}
此外,此部分中缺少哈希符号:
<style>
d
{
width : 660;
border:1px;
}
D
{
宽度:660;
边界:1px;
}
必须进行如下修改:
<style>
#d {
width : 660;
border:1px;
}
#d{
宽度:660;
边界:1px;
}
.detail
{
文本对齐:居中;
字体大小:正常;
页边距:0自动;
}请检查css,在.img中的高度和宽度中添加'px'值,例如img{height:200px;width:200px;}
<style>
#d {
width : 660;
border:1px;
}