Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

div ignores height from style sheet

Tags:

html

css

height

This is driving me crazy. I can't seem to control the height of the div.down_arrow element below -

...
<div id="filters">
    ...
    <span>All</span>
    <div class="down_arrow">
        <img src="images/down_arrow.png" alt=""/>
    </div>
    ...
</div>
...

I've got the following css -

#filters {
    float: right;
    padding: 24px 10px 0 0;
}

#filters div {
    display: inline;
}

#filters div.down_arrow,
#filters div.down_arrow img {
    height: 12px;
    width: 23px;
}

#filters div.down_arrow:hover ing {
        opacity: 0;
}

The safari developer tools tell me that the height and width of my div.down_arrow are still having effect (ie there's no line through the attributes - nothing else is overriding them). But the little popup on the screen shows the dimensions of the div.down_arrow to be 27px x 16px. I can see that the element is larger than the img element it contains.

I don't understand what's going - it looks like the height seems to be taken from the preceding span element (and I've no idea what's effecting the width).

like image 298
Aidan Ewen Avatar asked Jan 15 '13 11:01

Aidan Ewen


People also ask

Why does my div have no height?

The reason why the height or the containers is 0 is because you are floating all the content inside them and floated elements don't expand the height (or width) of their parents. As you are floating all elents in row it has 0 height and therfore so has .

How do I make a div fit the height of my screen?

Syntax: To set a div element height to 100% of the browser window, it can simply use the following property of CSS: height:100vh; Example: HTML.

Why height and width is not working in CSS?

Spans are display: inline; by default. To get them to listen to a height and width, you'll need to add display: block; . Save this answer.


2 Answers

Change display: inline; to display: inline-block;

The issue is you can only manually control the width/height of block elements, not inline elements.

like image 195
AlienHoboken Avatar answered Sep 29 '22 11:09

AlienHoboken


inline elements are not affected by height

like image 40
hank Avatar answered Sep 29 '22 10:09

hank