HTML   发布时间:2022-04-15  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了html – 是否有任何CSS来对齐框/元素?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我见过有人说不要使用< div align =“center”> Some Text< / div>和< center>一些文字< / center>因为它已经过时但我找不到任何CSS来对齐元素中的所有内容.我发现它最接近的是text-align:center;但这只是对齐文本,而不是元素.有没有允许你对齐元素的CSS?

这是CSs.我想要集中的是#editor.这是< textarea>< / textarea>标签.

@font-face {
	font-family: Bandits;
	src: url("Bandits.ttf");
	font-weight: bold;
}

#editor {
	position: absolute;
	bottom: 35px;
	left: 35px;
	width: 800px;
	height: 600px;
	resize: none;
}

#see-result {
	position: absolute;
	top: 276px;
	left: 425px;
	width: 125px;
	letter-spacing: 2.7px;
	font-weight: bold;
	BACkground-color: #888;
	text-align: center;
	padding-top: 6.5px;
	padding-bottom: 6.5px;
	cursor: pointer;
	font-family: Calibri;
} #see-result:hover {
	BACkground-color: #ABABAB;
}

header {
	text-align: center;
	font-size: 65px;
	font-family: Bandits;
	letter-spacing: 2px;
}
最佳答案
要将框水平居中,您需要为其指定显式宽度,然后将其边距设置为“0 auto”:

.container{
    border:solid 2px lightblue;
    width:600px;
    height:400px;
}

.center{
    border:solid 2px red;
    height:200px;

    /*centering CSS*/
    width:200px;
    margin:0 auto;
}

您还可以通过为其父容器提供中心的文本对齐值并使其显示来水平对齐框:内联:

.container{
    border:solid 2px lightblue;
    width:600px;
    height:400px;
    text-align:center;
}

.center{
    border:solid 2px red;
    width:200px;
    height:200px;
  
    /*Centering CSS*/
    display:inline;
    text-align:center;
}

最后,您可以使用flexbox在其父级中水平对齐块容器:

.container{
    border:solid 2px lightblue;
    width:600px;
    height:400px;
	
    /*Centering CSS*/
    display:flex;
    justify-content:center;
}

.center{
    border:solid 2px red;
    width:200px;
    height:200px;
}

大佬总结

以上是大佬教程为你收集整理的html – 是否有任何CSS来对齐框/元素?全部内容,希望文章能够帮你解决html – 是否有任何CSS来对齐框/元素?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。