/    Sign up×
Community /Pin to ProfileBookmark

id and class…

i have the following code on a page (this is a simplified version):

[code=html]<div id=”rotate_div”><a href=”page.html”><img src=”button_rotate.jpg”></a></div>[/code]

the CSS:

[code]#rotate_div {
position:relative;
float:right;
}

#rotate_div a img {
width:53px;
height:20px;
border:1px solid #333;
}[/code]

but i need to apply this ID to several divs… so i thought that it would be simple enough…

i tried this:

[code=html]<div class=”rotate_div”><a href=”page.html”><img src=”button_rotate.jpg” class=”rotate_image”></a></div>[/code]

CSS:

[code].rotate_div {
position:relative;
float:right;
}

.rotate_image {
width:53px;
height:20px;
border:1px solid #333;
}[/code]

(this is probably wrong for obvious reasons, but i don’t understand why).

anyway, when i change the thing to CLASSES, the image (button_rotate.jpg) is stretched to the size of it’s parent div (305x350px) but i’m not sure why.

i’m sure it’s something to do with position:relative/absolute; though. just a guess.

here a link to the page this is on (using several IDs, which is incorrect syntax) – but it’s really complex and annoying to look at.
[url]http://www.foremostgroups.com/dev/2007corporate/K&B/heritage_bath/delaware.shtml[/url]

and the one with the classes applied:
[url]http://www.foremostgroups.com/dev/2007corporate/K&B/heritage_bath/delaware2.shtml[/url]

thanks in advance for any help/ideas.

to post a comment
CSS

19 Comments(s)

Copy linkTweet thisAlerts:
@KDLANov 01.2007 — Why don't you do it this way, without the classes:
<i>
</i>.rotate_div {
position:relative;
float:right;
}

.rotate_div img {
width:53px;
height:20px;
border:1px solid #333;
}

KDLA
Copy linkTweet thisAlerts:
@dtm32236authorNov 01.2007 — thanks KDLA, but i've tried it that way...

.rotate_div {
position:relative;
float:right;
}

.rotate_div img {
width:53px;
height:20px;
border:1px solid #333;
}


[code=html]<div class="rotate_div"><a href="page.html"><img src="button_rotate.jpg"></a></div>[/code]

and the image still resizes itself to the parent div.

this link now reflects the way you've suggested.

http://www.foremostgroups.com/dev/2007corporate/K&B/heritage_bath/delaware2.shtml
Copy linkTweet thisAlerts:
@KDLANov 01.2007 — Hmmm... maybe I'm missing something, but the buttons look the right size to me (viewing with IE6 and/or FX2). You might clean out your cache, then take another look.
Copy linkTweet thisAlerts:
@dtm32236authorNov 01.2007 — [url=http://www.foremostgroups.com/dev/2007corporate/K&B/heritage_bath/delaware.shtml]this page[/url] looks fine, but this is using invalid code (repeated ids)

[url=http://www.foremostgroups.com/dev/2007corporate/K&B/heritage_bath/delaware2.shtml]this[/url] is the one i've used the classes for, and in FF2 and IE6/7 the button_rotate.jpg is 'stretched'
Copy linkTweet thisAlerts:
@KDLANov 01.2007 — Ah, I see. I wasn't clicking to reveal the hidden stuff linked to the buttons like "vanity" and such.

First, you need to comment out the ID's of "rotate_div." It's not a good idea to have ID's and classes with the same name.

Also, your show/hide js still references the "rotate_div" ID in the CSS, which could be messing with the display.

KDLA
Copy linkTweet thisAlerts:
@dtm32236authorNov 01.2007 — I don't know how you guys have such a good eye for these things - i tend to overlook all these stupid mistakes.

anyway, I've fixed it according to these things you've noticed, and still i'm getting the same result.

PS - as far as the show/hide js goes, i'm using display:none; and display:block; to show and hide certain things when JS is enabled or disabled... and i know that using visibility:hidden/visible is better to use, but i can't seem to get it working like this, so i have to use display.

but that's besides the point...

i don't get why this image wants to expand like this.

throughout this thread, i'll be making changes to [url=http://www.foremostgroups.com/dev/2007corporate/K&B/heritage_bath/delaware2.shtml]delaware2.shtml[/url] .
Copy linkTweet thisAlerts:
@dtm32236authorNov 01.2007 — wow - i've been trying to make this work, and i don't get it.

if anyone has any ideas, please let me know... at this point i don't really care how i get this to work, as long as it works and validates.

thanks for your help KDLA, you definitely pointed out some key issues and put me on the right track.
Copy linkTweet thisAlerts:
@KDLANov 01.2007 — I suggest you take the "rotate image" image out of there and use text, just to test. I'm wondering if it is the usage of an image (along with the other one of larger proportions) that's causing the problem. (Really, it would probably be better if you DID use text, with the little turny arrow as a background.)

KDLA
Copy linkTweet thisAlerts:
@dtm32236authorNov 01.2007 — that's not a bad idea....

i'm going to work on a variation in the mean time - i'll let you know how it works out.

thanks again KDLA... you've been a great help so far.
Copy linkTweet thisAlerts:
@dtm32236authorNov 02.2007 — KDLA - your idea of using a background image is brilliant... I have something going here that's working, but i'm not positive that it's valid code / will work in all browsers (it uses an empty anchor tag). Can you check out this solution, and let me know what you think?

CSS:
.rotate_div {
position:relative;
float:right;
width:60px;
height:23px;
margin:-26px 16px 0 0;
background:#fff url(../images/button_rotate.jpg) no-repeat center;
border:1px solid #333;
}

.rotate_div a {
display:block;
width:60px;
height:23px;
text-decoration:none;
}


[code=html]<div class="rotate_div"><a href="javascript:nextSlide('delaware', 'delaware_cabinet_1drawer', '4');"></a></div>[/code]

thanks again for your help.

edit: i know it's valid code (it validates) but i'm not sure if the syntax is correct.
Copy linkTweet thisAlerts:
@KDLANov 02.2007 — I suggest adding the padding the width of the image, then apply the background to the link, rather than the div.

Also, that negative margin will cause a problem in Fx. Can you style it differently?

KDLA
Copy linkTweet thisAlerts:
@dtm32236authorNov 02.2007 — I suggest adding the padding the width of the image[/quote]

i'm not sure what you mean by this... add the padding to what class?

anyway, you have a good point with the negative margin, but i'm not sure how to fix it... I changed some of my code, and got rid of the negative margin, and [url=http://www.foremostgroups.com/dev/2007corporate/K&B/heritage_bath/delaware.shtml]as you can see[/url], the 'rotate image' falls below the large picture. i'd like it inside (on top of) the large image, but i'm not sure how i can do this without a negative margin.

.rotate_div {
display:none;
width:60px;
height:23px;
border:1px solid #333;
}

.rotate_div a {
display:block;
width:60px;
height:23px;
text-decoration:none;
background:#fff url(../images/button_rotate.jpg) no-repeat center;
}
Copy linkTweet thisAlerts:
@KDLANov 02.2007 — <a href="" style="padding-left: xxxpx; background: url(file.jpg);">link</a>

Apply the padding to the link, where "xxx" is the width of the image (file.jpg) you're using for the background.

Even better....

<a href="" style="padding-left: xxxpx; background: url(file.jpg); line-height: yyypx;">link</a>

where "yyy" is the height of your background image (file.jpg).

Looking at the positioning thing.....

*update -- I don't see the rotate image thing showing up in either Fx2 or IE6.
Copy linkTweet thisAlerts:
@dtm32236authorNov 02.2007 — when i take away display:block; and the width:60px; height:23px; the image disappears in IE6 and 7.

i should be visible now in IE6/7, FF2 and Safari... do you see it?

ps - the layout might be messed up when you look at it... i'm working on making a fluid layout for this page, but I've been trying different things for hours now (you'll probably see a new thread about it if i don't get it within a couple hours)
Copy linkTweet thisAlerts:
@KDLANov 02.2007 — Elements have to be block-level in order to apply width/height. Inline elements' sizes can only be manipulated through padding.

Perhaps you provided the wrong page, but clicking on items either changes the page, or does nothing.
Copy linkTweet thisAlerts:
@dtm32236authorNov 02.2007 — that makes sense, but when i do it with padding, it seems to disappear in IE6/7

.rotate_div {
visibility:hidden;
width:60px;
height:23px;
border:1px solid #333;
}

.rotate_div a {
padding-left:60px;
background:url(../images/button_rotate.jpg) no-repeat center;
line-height:23px;
}


[url=http://www.foremostgroups.com/dev/2007corporate/K&B/heritage_bath/delaware.shtml]this[/url] is the page i'm working on.
Copy linkTweet thisAlerts:
@KDLANov 02.2007 — Well, you're doing it a bit differently than I expected. I was thinking more along the lines of:

<p><a href="">Rotate Image</a></p>

You want the text there so the viewer knows what to do if the background image does not appear. You'll need to crop the image so that the little turny arrow is all that remains.

Once you encase the link into a block element, like <p>, you can manipulate the <p> to have a text-align: center and such.

KDLA
Copy linkTweet thisAlerts:
@dtm32236authorNov 02.2007 — oh, very true. okay, i'm going to try it like that...
Copy linkTweet thisAlerts:
@dtm32236authorNov 02.2007 — i like your idea much better - and i think it should be [url=http://www.foremostgroups.com/dev/2007corporate/K&B/heritage_bath/delaware.shtml]working (?)[/url] in all browsers

CSS:
.rotate_button {
visibility:hidden;
}

.rotate_button a {
font-size:.8em;
color:#666666;
text-align:right;
padding:5px 5px 5px 26px;
background:url(../images/button_rotate2.jpg) no-repeat left;
line-height:23px;
border:1px solid #333;
}


[code=html]<p class="rotate_button"><a onClick="nextSlide('delaware', 'delaware_cabinet_1drawer', '4');">Rotate Image</a></p>[/code]
×

Success!

Help @dtm32236 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...