html - Is there any CSS to align a box/element? -


i've seen people not use <div align="center">some text</div> , <center>some text</center> because it's outdated can't find css align inside element. closest thing i've found text-align: center; aligns text, not elements. there css allows align elements?

this css. thing want center #editor. it's <textarea></textarea> tag.

@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;  }

to horizontally center box need give explicit width , set margins "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;  }
<div class="container">      <div class="center">          box centereed      </div>  </div>

you can horizontally align box giving it's parent container text-align value of center , making display:inline:

.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;  }
<div class="container">      <div class="center">          box centereed      </div>  </div>

finally, can use flexbox horizontally align block containers within parent:

.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;  }
<div class="container">      <div class="center">          box centereed      </div>  </div>


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -