简体   繁体   English

如何让文本自动居中?

[英]How do I center a text automatically?

I'm developing a project, and I have a bar at the top, with two logos and a text centered in the middle written "Autenticação", but this text is centered by eye, as I do to centralize this text in the center of the bar automatically?我正在开发一个项目,顶部有一个栏,中间有两个徽标和一个文本,中间写着“Autenticação”,但是此文本以眼睛为中心,就像我将文本集中在酒吧自动? I've tried in many ways and I can't, if anyone knows, please help me!我已经尝试了很多方法,我不能,如果有人知道,请帮助我! 例子

Code:代码:

 *{ margin: 0; padding: 0; } .logos-container{ border-bottom: solid 1px #cdd1d3; box-shadow: 0px 3px 5px -1px rgba(50, 50, 50, 0.35); margin-top: 10px; } .logomin{ width: 245px; } .logoaetr{ width: 145px; display: inline; } .logos-container ul{ margin-left: 10%; list-style: none; } .logos-container ul li{ display: inline-block; } .logos-container ul li:nth-child(3){ vertical-align: top; margin: 15px 300px; text-transform: uppercase; font-family: 'Roboto', sans-serif; font-weight: 700; font-size: 18px; text-align: center; color: #001C44; } .loginContainer{ background: url("https://i.ibb.co/NnfNFJ1/fatura.png") no-repeat; background-size: 24%; height: 43vw; background-position-y: 20px; width: 100%; } .footer ul li{ display: inline-block; } .footer ul li a{ padding: 0px 10px; text-decoration: underline; color: #9B9B9B; } .footer ul li ap{ font-family: 'Roboto', sans-serif; font-size: 14px; line-height: 24px; font-weight: 300; margin-left: 50px; } .footer{ background: #f5f5f5; } .footer ul{ list-style: none; }
 <div class="page"> <div class="logos-container"> <ul> <li><img src="https://i.ibb.co/njPs6xJ/min.png" class="logomin" alt="Ministerio da Educação" /></li> <li><img src="https://i.ibb.co/mcKb85g/aetr.png" class="logoaetr" alt="Agrupamento de Escolas Tomaz Ribeiro" /></li> <li><h2>Autenticação</h2></li> </ul> </div> <div class="loginContainer"> <p>&nbsp;</p> </div> <footer class="footer"> <ul> <li><a href="https://google.pt/"><p>Esqueceu a sua senha?</p></a></li> <li><p>Versão: 1.0</p></li> </ul> </footer> </div>

It sounds like you're wanting (since it's unclear between the picture and description) something more like this.听起来您想要(因为图片和描述之间不清楚)更像这样的东西。 Also cleaned up your syntax errors and semantic structure issues.还清理了您的语法错误和语义结构问题。 Cheers!干杯!

 *{ margin: 0; padding: 0; box-sizing: border-box; } .logos-container { display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: left; padding: 0 2rem; text-transform: uppercase; font-family: 'Roboto', sans-serif; font-weight: 700; font-size: 1rem; text-align: center; color: #001C44; border-bottom: solid 1px #cdd1d3; box-shadow: 0px 3px 5px -1px rgba(50, 50, 50, 0.35); margin-top: 10px; } .logos-container img { height: 3rem; } .logos-container h2 { flex: 1; } .loginContainer{ background: url("https://i.ibb.co/NnfNFJ1/fatura.png") no-repeat left 20px; background-size: 24%; height: calc(100vh - 5.25rem); } .footer { font-family: 'Roboto', sans-serif; font-size: 14px; font-weight: 300; padding: 0 2rem; background: #f5f5f5; } .footer a { text-decoration: underline; color: #9B9B9B; }
 <div class="page"> <div class="logos-container"> <img src="https://i.ibb.co/njPs6xJ/min.png" class="logomin" alt="Ministerio da Educação"> <img src="https://i.ibb.co/mcKb85g/aetr.png" class="logoaetr" alt="Agrupamento de Escolas Tomaz Ribeiro"> <h2>Autenticação</h2> </div> <div class="loginContainer"> <p>&nbsp;</p> </div> <div class="footer"> <a href="https://google.pt/">Esqueceu a sua senha?</a> <span>Versão: 1.0</span> </div> </div>

Try this (HTML the same):试试这个(HTML相同):

https://jsfiddle.net/cLdpmhbv/ https://jsfiddle.net/cLdpmhbv/

*{
  margin: 0;
  padding: 0;
}
.logos-container{
  border-bottom: solid 1px #cdd1d3;
  box-shadow: 0px 3px 5px -1px rgba(50, 50, 50, 0.35);
  margin-top: 10px;
}
.logomin{
  width: 245px;
}
.logoaetr{
  width: 145px;
  display: inline;
}
.logos-container ul{
  list-style: none;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}
.logos-container ul li{
  display: inline-block;
}
.logos-container ul li:nth-child(1),
.logos-container ul li:nth-child(2){
    flex-basis: 10%;
}

.logos-container ul li:nth-child(3){
  flex-basis: 80%;
  transform: translateX(-20%);
  text-transform: uppercase;
  font-family: 'Roboto', sans-serif;
  font-weight: 700;
  font-size: 18px;
  text-align: center;
  color: #001C44;
}
.loginContainer{
  background: url("https://i.ibb.co/NnfNFJ1/fatura.png") no-repeat;
  background-size: 24%;
  height: 43vw;
  background-position-y: 20px;
  width: 100%;
}
.footer ul li{
  display: inline-block;  
}
.footer ul li a{
  padding: 0px 10px;
  text-decoration: underline;
  color: #9B9B9B;
}
.footer ul li a p{
  font-family: 'Roboto', sans-serif;
  font-size: 14px;
  line-height: 24px;
  font-weight: 300;
  margin-left: 50px;
}
.footer{
  background: #f5f5f5;
}
.footer ul{
  list-style: none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM