Vitalij Kornijenko
Vitalij Kornijenko

Reputation: 559

Set height of an image same as a neighboring element CSS

I was wondering how could you set height of an image to the neighboring elements height. So, essentially I want to have it like this:

[div] [img]

Other than javascript I can't see a way how can I do this. So, instead of using js can I just use CSS?

Thank you

Code so far(nothing special):

<div style="text-align:right;">
                        <label for="file-upload">Choose file</label>
                        <img><!-- Updates dynamically using js-->
                        <input id="file-upload" type="file" name="photo"/>
                    <input type="submit" value="Upload Image" name="submit" />
                </div>

Upvotes: 0

Views: 86

Answers (1)

Nima Parsi
Nima Parsi

Reputation: 2110

In order to style neighboring elements in CSS you can use adjacent selector(plus sign). As in following:

label + img{height:300px}

That will target img in your code "after" any label.

JSFiddle

Upvotes: 1

Related Questions