0

In CSS, is there a way to refer to property value like width of a container div tag from one of its contained elements to create a dynamic relationship between the two. Here is some code to illustrate my intent:

<div id="settingz" style="position:absolute; width: 350px; height: 300px;">
<span style="position:absolute;  left:inherit parent width; margin-left:-30px; top:6px;" >
        <img id="exportRedX" src="/static/RedX2.png" />
    </span>
(/div>

Notice the silly attempt left:inherit parent width; That is the best way for me to convey what I'm trying to do. I want to tie the image to a position relative to the div's width. I know about the align="right" but that does not really do what margin-left can contribute to the left: ... inheritance.

Any help is appreciated...

DK

5
  • 1
    No, you cannot do that. Commented Jun 27, 2013 at 15:37
  • What you should be able to do is just let them float next to each other, in a common container. Commented Jun 27, 2013 at 15:42
  • @Bergi That complicates things a bit, but I see your point, using position:relative. Good idea, though it complicates things a bit. I found an interesting solution. I will publish it after I get more inputs. Commented Jun 27, 2013 at 15:49
  • I think a simple float:left is faaaaaar less complicated than trying to create dynamic inheritance in CSS. Commented Jun 27, 2013 at 15:51
  • @zessx Both float:left and float:right make the image to go far to the left, but I thought that you were right. I don't understand why float:right does not do it? Thank you for the suggestion, however... Commented Jun 27, 2013 at 15:59

2 Answers 2

1

This isn't possible with pure CSS, however you can use CSS preprocessors such as SASS or LESS to achieve similar things by using variables and mix-ins.

Sign up to request clarification or add additional context in comments.

6 Comments

very interesting reply. I never heard of these... Must investigate... Thank you for your input...
Wow! SASS and LESS are very impressive @rink.attendant.6 . Thank you for the light...
@DKean: Yes, but don't forget they're not dynamic and serverside only.
@Bergi I think that LESS is client side too!
@DKean: Oh, right. But only in modern browsers, i.e. not where you would really need it in lack of CSS3 features.
|
0

Thank you all so much for the help. SASS and LESS seem to be impressive and I will dabble with them later. For now the solution I found, which answers my need is as follows:

<span style="position:absolute;  left: 100% ; margin-left:-30px;" >
    <img id="exportRedX" src="/static/RedX2.png" />
</span>

This hugs the right side and allows me to adjust the relative distance from the right as well.

The solution lies in left: 100% ; margin-left:-30px;. That makes the hugging dynamic.

Your time lent to help me is very appreciated, guys!

Thank you all,

DKean

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.