Tutorial CSS

CSS INICIO Introducción a CSS Sintaxis CSS Selectores de CSS CSS Cómo Comentarios CSS Colores CSS Fondos CSS Bordes CSS Márgenes CSS Relleno CSS Altura/ancho de CSS Modelo de caja CSS Esquema CSS Texto CSS Fuentes CSS Iconos CSS Enlaces CSS Listas CSS Tablas CSS Pantalla CSS Ancho máximo de CSS Posición de CSS Índice Z de CSS Desbordamiento de CSS CSS flotante Bloque en línea CSS Alinear CSS Combinadores de CSS Pseudo-clase CSS Pseudoelemento CSS Opacidad CSS Barra de navegación CSS Menús desplegables de CSS Galería de imágenes CSS Sprites de imagen CSS Selectores de atributos CSS Formularios CSS Contadores CSS Diseño del sitio web CSS Unidades CSS Especificidad CSS CSS !importante Funciones matemáticas CSS

CSS Avanzado

Esquinas redondeadas CSS Imágenes de borde CSS Fondos CSS Colores CSS Palabras clave de color CSS Gradientes CSS Sombras CSS Efectos de texto CSS Fuentes web CSS Transformaciones CSS 2D Transformaciones CSS 3D Transiciones CSS Animaciones CSS Información sobre herramientas de CSS Imágenes de estilo CSS Reflejo de imagen CSS Ajuste de objeto CSS Posición del objeto CSS Enmascaramiento CSS Botones CSS Paginación CSS Columnas múltiples de CSS Interfaz de usuario de CSS Variables CSS Tamaño del cuadro CSS Consultas de medios CSS Ejemplos de CSS MQ Caja flexible de CSS

Responsivo CSS

Introducción a la tracción trasera Vista de RWD Vista de cuadrícula RWD Consultas de medios RWD Imágenes de RWD Vídeos de RWD Marcos RWD Plantillas RWD

Cuadrícula CSS

Introducción a la cuadrícula Contenedor de rejilla Elemento de cuadrícula

CSS SASS

Tutorial de SASS

Ejemplos de CSS

Plantillas CSS Ejemplos de CSS prueba css Ejercicios CSS Certificado CSS

Referencias CSS

Referencia CSS Selectores de CSS Funciones CSS CSS Referencia Aural Fuentes web seguras CSS CSS Animable Unidades CSS Convertidor CSS PX-EM Colores CSS Valores de color CSS Valores predeterminados de CSS Compatibilidad con navegador CSS

Diseño CSS - Ejemplos flotantes


Esta página contiene ejemplos de flotadores comunes.


Cuadrícula de Cajas / Cajas de Igual Ancho

Caja 1

Caja 2


Caja 1

Caja 2

Caja 3

Con la floatpropiedad, es fácil hacer flotar cuadros de contenido uno al lado del otro:

Ejemplo

* {
  box-sizing: border-box;
}

.box {
  float: left;
  width: 33.33%; /* three boxes (use 25% for four, and 50% for two, etc) */
  padding: 50px; /* if you want space between the images */
}

¿Qué es el tamaño de la caja?

Puede crear fácilmente tres cajas flotantes una al lado de la otra. Sin embargo, cuando agrega algo que aumenta el ancho de cada cuadro (por ejemplo, relleno o bordes), el cuadro se romperá. La box-sizingpropiedad nos permite incluir el relleno y el borde en el ancho (y alto) total de la caja, asegurándonos de que el relleno quede dentro de la caja y que no se rompa.

Puede leer más sobre la propiedad de tamaño de caja en nuestro Capítulo de tamaño de caja CSS .


Imágenes una al lado de la otra

Italia
bosque
Montañas

La cuadrícula de cuadros también se puede usar para mostrar imágenes una al lado de la otra:

Ejemplo

.img-container {
  float: left;
  width: 33.33%; /* three containers (use 25% for four, and 50% for two, etc) */
  padding: 5px; /* if you want space between the images */
}

Cajas de igual altura

In the previous example, you learned how to float boxes side by side with an equal width. However, it is not easy to create floating boxes with equal heights. A quick fix however, is to set a fixed height, like in the example below:

Box 1

Some content, some content, some content

Box 2

Some content, some content, some content

Some content, some content, some content

Some content, some content, some content

Example

.box {
  height: 500px;
}

However, this is not very flexible. It is ok if you can guarantee that the boxes will always have the same amount of content in them. But many times, the content is not the same. If you try the example above on a mobile phone, you will see that the second box's content will be displayed outside of the box. This is where CSS3 Flexbox comes in handy - as it can automatically stretch boxes to be as long as the longest box:

Example

Using Flexbox to create flexible boxes:

Box 1 - This is some text to make sure that the content gets really tall. This is some text to make sure that the content gets really tall. This is some text to make sure that the content gets really tall.
Box 2 - My height will follow Box 1.

Tip:  You can read more about the Flexbox Layout Module in our CSS Flexbox Chapter.


Navigation Menu

You can also use float with a list of hyperlinks to create a horizontal menu:


Web Layout Example

It is also common to do entire web layouts using the float property:

Example

.header, .footer {
  background-color: grey;
  color: white;
  padding: 15px;
}

.column {
  float: left;
  padding: 15px;
}

.clearfix::after {
  content: "";
  clear: both;
  display: table;
}

.menu {
  width: 25%;
}

.content {
  width: 75%;
}

More Examples


Let an image float to the right in a paragraph. Add border and margins to the image.


Let an image with a caption float to the right.


Let the first letter of a paragraph float to the left and style the letter.


Use float to create a homepage with a navbar, header, footer, left content and main content.


All CSS Float Properties

Property Description
box-sizing Defines how the width and height of an element are calculated: should they include padding and borders, or not
clear Specifies what should happen with the element that is next to a floating element
float Specifies whether an element should float to the left, right, or not at all
overflow Specifies what happens if content overflows an element's box
overflow-x Specifies what to do with the left/right edges of the content if it overflows the element's content area
overflow-y Specifies what to do with the top/bottom edges of the content if it overflows the element's content area