Thanks for your replies. My issue isn’t with displaying each item next to each other or on top of each other, it’s the fact that in the first instance I need the first 3 letters of the month, and in the second instance, I want the whole word for the month.
Ahhh, I see what you’re saying now. That’s an interesting question.
Would you be opposed to using JavaScript? If not, you could sniff out the screen size to see if you have a small screen and then change the text of the span in question.
I haven’t tested this yet so I have no idea if I should put a display:none there or use another trick to hide “SEP”. Also I’m not sure I need :after, but you get the idea.
So, when you want it all in one line, do nothing. When you want the date stacked, just say in the CSS
span {display: block;}
span.mon {display: none;}
With no styles on the spans, nothing will happen: the line will just be one normal line. But with display: block on the spans, they’ll stack. And with display: none on the end of the month, it will disappear.
Hm, yeah, that’s a game changer. Is some kind of CMS generating this? Or is it just PHP you write?
This isn’t my area, but I wonder if you can insert different bits of PHP between the various spans. For example, on big screens set span.abbr to display block and span.full to display: none, and vice versa on small screens.
An idea - you could output both formats in your php and position them as floated boxes so you can use the fact that on a smaller screen size (=smaller width) one box with date will float to the next line. Actually, I used another empty box to act as an element pushing the other boxes because I found it difficult to use the date boxes alone:
In this example as you make the browser window very small (narrow) the date will change from one format to the other. So the displayed format is dependent only on the browser width or the wrapper element width. This code is a bit convoluted considering the simple effect you are trying to achieve but maybe you would be able to simplify the implementation.
Thanks, Ralph, I also think it’s a clever idea but I’m not sure if it’s practical here since it’s supposed to work on “smaller devices”. I don’t know what the OP meant by that but usually mobile phones have much less css capable browsers and may choke on this. This works in all major desktop browsers but would need testing on the other “smaller devices” it’s supposed to work on.
That’s a neat little trick Lemon Juice! You must have scratched your head a little to come up with this
However I wouldn’t have the date twice in the HTML… it feels wrong. Accessibility and all that…
Plus you don’t need to bother with positioning tricks like that, I’m going to use media queries anyway so what I’ll do is in one case I’ll position the month absolutely within a container that has position: relative, and in the other case you let each element position itself next to the other naturally, as inline elements do.
My concern was purely about generating the date in the format that I want.
I think the best solution I’ve heard so far is to use the TITLE attribute for the month. In the actual element I’d have the full word, and in the TITLE the 3 letter version. Then I’d use some css to display either the content of the TITLE or of the tag.
I’ve had a play with this and it works very well, although I’m not totally happy about the way I’m hiding the month when I’m displaying the TITLE attribute instead.
Yes, your solution is really nice and that’s the way to go! I didn’t think you could do it this way…
I was just curious if I can do it with positioning of floats but it feels too complicated to me and, as you say, having the date twice in html is not good.
I’ve never used media queries - do they work in IE9?
I agree, you can either display the large version of your layout on IE, or if you really want your media-queries to be picked up EVEN by IE6, you can use a tool such as 320 and up, by Andy Clarke.
I’ve used it before, it’s great combined with Paul Irish’s HTML5 boilerplate (they’ve released version 2 yesterday, exciting!).
Someone made a very useful comment : instead of using the TITLE attribute I should be using the HTML5 data- custom attributes !! I love this idea
I think it’s the best way to do it, although I don’t know how it degrades in old browser. It might work just fine with a trick or two. I haven’t tried yet.