Centrar con Flexbox

Aprende a centrar con Flexbox en tres líneas de CSS: display:flex, justify-content y align-items. Conoce desarrollo a medida e IA de Q2BSTUDIO.

2 sept 2025 • 2 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Cuando por fin le di una oportunidad real a Flexbox, todo encajó. Descubrí que bastan tres líneas de CSS para centrar elementos en un contenedor tanto horizontal como verticalmente.

La fórmula Flexbox para centrar cualquier cosa dentro de un contenedor:

- Añade display: flex al contenedor padre.

- Usa justify-content: center para centrar en horizontal.

- Usa align-items: center para centrar en vertical.

Listo.

Ejemplo HTML

<div class=parent-element> <div class=child-element>Hijo 1</div> <div class=child-element>Hijo 2</div> </div>

Ejemplo CSS

.parent-element { background-color: #999; border: 4px solid #000; display: flex; justify-content: center; align-items: center; height: 200px; } .child-element { font-family: sans-serif; font-size: 18px; text-align: center; color: #fff; background-color: #1a8446; padding: 3em; margin: 7px; }

Lo que aprendí

display: flex convierte el contenedor en un contenedor flex.

justify-content: center alinea los elementos hijos en el eje principal de forma horizontal.

align-items: center los alinea en el eje transversal de forma vertical. Para apreciar el centrado vertical conviene definir una altura en el contenedor padre.

Lo que voy a probar después

- Experimentar con flex-direction para ver cómo cambia el flujo del layout.

- Emplear gap en lugar de márgenes para espaciar elementos de forma más limpia.

- Explorar flex-wrap para entender el comportamiento con múltiples líneas de contenido.

En Q2BSTUDIO ayudamos a equipos y empresas a construir interfaces modernas y eficientes con CSS y JavaScript, además de desarrollar aplicaciones a medida y software a medida de alto rendimiento. Si estás planificando un nuevo producto digital o quieres modernizar tu front end, descubre nuestro desarrollo de software a medida y aplicaciones a medida.

También impulsamos la productividad con ia para empresas, agentes IA e integración con tus sistemas existentes. Conoce nuestras soluciones de inteligencia artificial para clasificación de datos, asistentes cognitivos y automatización inteligente.

Nuestro portafolio incluye ciberseguridad con pentesting, servicios cloud aws y azure, servicios inteligencia de negocio con power bi, además de arquitectura de datos, analítica avanzada y automatización de procesos. Si te interesa llevar tu plataforma al siguiente nivel con rendimiento, seguridad y escalabilidad, hablemos.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat