CSS - Listas a lo ancho
La tendencia actual al desarrollar páginas HTML es utilizar CSS.
Con CSS, se debe crear el contenido de la página demarcado adecuadamente con etiquetas HTML, y el diseño de la página se obtiene dandole el estilo por medio de un archivo aparte.
La manera más utilizada actualmente de crear menués es con una lista de enlaces y hacerla ver como un menu con CSS, pero una lista tiene sus limitaciones. Yo quise hacer que un menú generado por software por medio de listas utilizara todo el ancho de la página. Una lista no distribuye sus elementos a lo ancho de la lista, tal como lo hace una tabla, sino que los va agregando a la lista hasta llenar su ancho. La única manera de hacerlo era poner medidas estáticas a los elementos de la lista, pero al agregar otro elemento se corrín y quedaba desordenado. Así que tuve que encontrar una solución dinámica a mi problema.
Esta es una tabla con dos elementos:
| A | B |
Esta es una lista con dos elementos:
- A
- B
Nótese que para evitar confusiones, el borde de la tabla es rojo mientras que el de la lista es negro.
Al quitar los marcadores a la lista y desplegarla en una línea, se ve similar a nuestra tabla:
- A
- B
Mi problema era que los elementos no son distribuidos a lo ancho de la lista, sino que esta agrupados al inicio, mientras que en la tabla, al darle un ancho fijo, los elementos se distribuyen dentro de la tabla para utilizar todo el ancho:
| A | B |
Mi primera solución fue dar un ancho fijo a la lista, y utilizar medidas estáticas para distribuir los elementos a lo ancho:
- A
- B
Pero esta solución resultó ser ineficaz tan pronto se agregó otro elemento más por medio del software:
- A
- B
- C
Esto es lo que pasaría si el software generara una tabla en lugar de una lista, y de hecho, este es el efecto esperado:
| A | B | C |
Se me ocurrió modificar el software para que generara una tabla en lugar de una lista, pero hubiera resultado más complicado. Especialmente al actualizar el software, ya que la nueva versión posiblemente volverá a generar este menú como listas, y tendría que volverlo a modificar. También esta la posibilidad de un cambio en el diseño de la página, y ahora el menú perdería todas las ventajas de ser creado como una lista. Así que preferí dejar esta opción como última.
Entonces decidí replantear mi problema. En lugar de pensar que mi problema es que la lista no distribuye sus elementos a lo ancho, empezar a pensarlo como la necesidad de que una lista se comporte como una tabla.
La tabla se comporta como lo hace, porque el navegador crea unas definiciones de estilo por defecto, en el caso de una tabla sencilla, serían las siguientes:
table { display: table }
tr { display: table-row }
td { display: table-cell }
… y el estilo lo que me permite es modificar las definiciones por defecto de los diferentes elementos HTML utilizados en nuestras páginas, tal y como ya lo hice con la lista para que despliegue sus elementos en una sola línea un lugar de hacerlo en líneas aparte. Así que se me ocurrió quitar las medidas estáticas y probar lo siguiente:
ul { display: table }
li { display: table-cell }
… y este fue el resultado:
Con 2 elementos
- A
- B
Con tres elementos
- A
- B
- C
Así que esta es la manera sencilla de hacer que una lista horizontal despliegue sus elementos a lo ancho de la misma.
January 29th, 2012 at 18:28:41
This design is steller! You definitely know how to keep a reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Excellent job. I really loved what you had to say, and more than that, how you presented it. Too cool!
January 29th, 2012 at 18:32:56
Wow that was odd. I just wrote an extremely long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyways, just wanted to say superb blog!
January 29th, 2012 at 18:48:55
Wonderful post however , I was wondering if you could write a litte more on this topic? I’d be very thankful if you could elaborate a little bit more. Bless you!
January 30th, 2012 at 4:59:18
Exactly where might I get a hold of this Blog platform?
January 30th, 2012 at 7:50:56
I’m not sure exactly why but this web site is loading extremely slow for me. Is anyone else having this problem or is it a issue on my end? I’ll check back later on and see if the problem still exists.
January 30th, 2012 at 8:14:23
I am curious to find out what blog system you are utilizing? I’m having some small security problems with my latest blog and I’d like to find something more safe. Do you have any recommendations?
January 31st, 2012 at 14:48:30
Really impressed with the website, sincerely, Dr. Smith,
Sanford Dental Excellence
4942 W. SR 46 Suite 1038, Sanford, FL
(407) 513-4950
January 31st, 2012 at 17:05:45
Hmm it seems like your website ate my first comment (it was extremely long) so I guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying your blog. I too am an aspiring blog blogger but I’m still new to the whole thing. Do you have any tips and hints for first-time blog writers? I’d genuinely appreciate it.
February 1st, 2012 at 2:56:56
Does your blog have a contact page? I’m having trouble locating it but, I’d like to shoot you an email. I’ve got some suggestions for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it develop over time.
February 1st, 2012 at 9:12:45
Hey! I know this is kinda off topic however I’d figured I’d ask. Would you be interested in exchanging links or maybe guest writing a blog post or vice-versa? My blog goes over a lot of the same subjects as yours and I believe we could greatly benefit from each other. If you are interested feel free to send me an email. I look forward to hearing from you! Fantastic blog by the way!
February 1st, 2012 at 13:59:22
Audio began playing any time I opened up this webpage, so frustrating!
February 1st, 2012 at 17:12:05
learn how to hack a facebook = hack-facebook-password.org
February 2nd, 2012 at 13:38:40
The crux of your writing while sounding reasonable initially, did not settle properly with me after some time. Somewhere throughout the sentences you actually were able to make me a believer but just for a while. I however have a problem with your leaps in assumptions and one would do well to help fill in those gaps. When you actually can accomplish that, I could definitely end up being amazed.
February 3rd, 2012 at 19:10:42
It’s a shame you don’t have a donate button! I’d without a doubt donate to this fantastic blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to brand new updates and will share this website with my Facebook group. Talk soon!
February 3rd, 2012 at 19:52:24
It’s a pity you don’t have a donate button! I’d definitely donate to this fantastic blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will share this blog with my Facebook group. Talk soon!
February 3rd, 2012 at 20:38:08
Wow! This blog looks exactly like my old one! It’s on a totally different topic but it has pretty much the same page layout and design. Excellent choice of colors!
February 3rd, 2012 at 22:22:01
When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Appreciate it!
February 4th, 2012 at 7:59:44
Internet can now put your phone calls on cable and you can make free pc to phone calls. This free calling service lets you make free calls to India, free calls to China, and free calls to all other countries using internet telephone. Internet telephony is the thing of the future according to a recent research. Free phone calls will be a reality in very soon and wireless service carriers will have a hard time justifying their costs.
February 4th, 2012 at 9:35:51
Fancy dress for boys will always be popular and there are so many different choices out there these days from animals to TV star themed costumes, film stars to traditional costumes such as angels and fairies.
February 4th, 2012 at 9:53:17
Do you have a spam problem on this site; I also am a blogger, and I was curious about your situation; many of us have created some nice methods and we are looking to swap techniques with other folks, be sure to shoot me an e-mail if interested.
February 4th, 2012 at 13:59:38
great post!!
February 4th, 2012 at 16:23:35
I’m not sure exactly why but this weblog is loading very slow for me. Is anyone else having this problem or is it a problem on my end? I’ll check back later and see if the problem still exists.
February 5th, 2012 at 9:26:26
Woah! I’m really loving the template/theme of this site. It’s simple, yet effective. A lot of times it’s difficult to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a awesome job with this. Additionally, the blog loads super fast for me on Firefox. Excellent Blog!
February 6th, 2012 at 1:06:38
I know this if off topic but I’m looking into starting my own blog and was curious what all is required to get setup? I’m assuming having a blog like yours would cost a pretty penny? I’m not very web savvy so I’m not 100% certain. Any suggestions or advice would be greatly appreciated. Thanks
February 6th, 2012 at 11:53:11
Wow that was strange. I just wrote an extremely long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyway, just wanted to say excellent blog!
February 6th, 2012 at 14:25:50
Thanks for ones marvelous posting! I genuinely enjoyed reading it, you’re a great author.I will always bookmark your blog and definitely will come back at some point. I want to encourage you to definitely continue your great job, have a nice evening!
February 6th, 2012 at 20:21:56
This design is steller! You definitely know how to keep a reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Great job. I really loved what you had to say, and more than that, how you presented it. Too cool!
February 7th, 2012 at 0:09:36
Do you mind if I quote a few of your posts as long as I provide credit and sources back to your weblog? My blog is in the exact same area of interest as yours and my visitors would certainly benefit from a lot of the information you present here. Please let me know if this ok with you. Thanks!
February 7th, 2012 at 1:26:26
Hmm it seems like your blog ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I too am an aspiring blog blogger but I’m still new to the whole thing. Do you have any recommendations for rookie blog writers? I’d really appreciate it.
February 7th, 2012 at 6:13:43
Don’t count the chickens before they are hatched.