- This topic is empty.
-
AuthorPosts
-
March 25, 2011 at 5:03 pm #32138balsamParticipant
Please bear with me if this is a dopey question, but I’m learning! Also, if I use incorrect terms, please feel free to point it out as it’ll help me learn.
I want to have boxes of text of various sizes scattered around the page. I did a style called “mission” like so:
the width: has been commented out for my experimenting. What I wanted to do is for each individual paragraph or box, specify a width that is appropriate and not have to make endless styles with the only difference between them being the width.
Down in the body of the html, I just have a div class of mission applied to a paragraph, like this
a bunch of text
even more text
you guessed it, yet more text
but I can’t quite figure out how to make say this grouping of text be 500px wide, while another grouping would maybe be 300px wide, etc. I thought I could add something to that div class that would make it 500px wide, while in the next div class make it another width. I guess I could make styles for each width and combine the div’s but perhaps there’s a better way.
Thanks in advance for any guidance.
Brian
p.s. I know the background/text colours are hideous – they’re just random while I assemble this thing
March 25, 2011 at 5:43 pm #53608soapParticipantA div is a block-level element by default, meaning its width will be as wide as its containing element. If you want the width to be a certain number, I’m im afraid you will have declare it. The thing is, how would it know by itself how wide to be based on text inside of it. Now if you wanted random widths, that can done easily with javascript. Let know if me that is your goal.
March 25, 2011 at 9:51 pm #53576soapParticipantI think the point is that he didn’t want to have a bunch of different classes. Lazy boy :)
March 26, 2011 at 9:11 pm #53483soapParticipantmaybe
March 28, 2011 at 11:04 am #53465balsamParticipantThanks for all the help guys. I was hoping to be able to specify the width at the text location of the html. Sort of something like this:
a bunch of text
even more text
you guessed it, yet more text
but it appears that simply adding “width=” doesn’t work. So the next best way is to keep .mission class defining everything but the width and then separate classes for the various widths I’m wanting.
March 28, 2011 at 11:15 am #53466guiniveretooMemberYou would have to declare different classes for different widths I’m afraid; but it’s not as terrible as you might think. You could declare classes like this:
.mission { /* the code you want for each div */ }
.skinny { width: 300px; }
.medium { width: 500px; }
.wide { width: 700px; }
Then declare it in the html like so:
some text here
I’m not sure what a pro would say, but thinking about it I’d keep the class names to something generic but understandable (as in not “.width500” but “.medium”) so that if you need to change the widths of the divs then the class names would still make sense.
March 28, 2011 at 12:53 pm #53406balsamParticipantThanks guiniveretoo!
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.