- This topic is empty.
-
AuthorPosts
-
April 29, 2015 at 12:54 pm #201331
rlnl
ParticipantHi, I have a
<div>
with fixed height and padding. The border-box property is applied on the whole page. Inside the<div>
I have an<img>
withmax-width:100%
, andmax-height:100%
properties.<code class="css">*, *:before, *:after { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; } #responsive-image { height:150px; border:1px solid red; display:inline-block; float:left; padding:15px; } img { max-width:100%; max-height:100%; }
The div should be same as the width. (+15px padding on left and right)
I have a CodePen link: http://codepen.io/anon/pen/dooGorI would like to get rid of the whitespace on the right.
Thank you!
April 29, 2015 at 1:40 pm #201332Paulie_D
MemberFloat & Inline-block are incompatible…pick one or the other.
Images should be max-width or max-height..not both.
I’m not really clear on what you are trying to do..the Codepen doesn’t seem to have any whitespace on the right.
April 30, 2015 at 1:01 am #201339rlnl
ParticipantI forgot to mention that the problem appears in Firefox: http://note.io/1Iq3RgJ
I used max-width and max-height because I would like to reduce the height and the width too.
What is the best solution?
April 30, 2015 at 2:27 am #201342Paulie_D
MemberYeah…it’s a combination of the padding, box-sizing and the max-whatever you’re applying to the image.
As I said, you can’t have max-height and max-width as 100% at the same time…you have to pick one or the other (at least AFAIK).
That said, max-height is pretty unusual, normally I would expect to see max-width for responsiveness
Something is borked in FF somewhere..or it could be that they are doing it right and everyone else is doing it wrong. :)
April 30, 2015 at 2:32 am #201344rlnl
ParticipantI changed max-width to auto, and it’s same :/
http://codepen.io/anon/pen/dooGor
I’m working on a header, where the height is not always the same. On some pages it’s 100px, on other it’s only 60px. That’s why I want responsive height for the logo. Do you know solution for this?
April 30, 2015 at 2:42 am #201347Paulie_D
MemberI’m working on a header, where the height is not always the same. On some pages it’s 100px, on other it’s only 60px.
So something like this?
April 30, 2015 at 3:57 am #201348rlnl
ParticipantYes, something like this, but what happens if the width of the div is smaller than the image? Is it possible to use responsive styles for width and height together?
April 30, 2015 at 4:39 am #201350Paulie_D
MemberYes, something like this, but what happens if the width of the div is smaller than the image?
Why would it be? This is a header right?
Perhaps you need to be thinking about background images instead.
April 30, 2015 at 5:37 am #201355rlnl
ParticipantYes it’s a header, and the image is a logo. So it’s not possible to use an image with responsive with and height, right?
April 30, 2015 at 6:00 am #201361Paulie_D
MemberSo it’s not possible to use an image with responsive with and height, right?
Not really…one or the other.
Things don’t usually get “taller” when we’re talking about responsiveness, just wider and narrower.
I’m not really sure why the “logo” would be wider than the header though.
April 30, 2015 at 7:31 am #201385rlnl
ParticipantYou are right. I accepted the answer.
By the way for a full screen image the viewports height/width can be smaller so in that case it’s useful.
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.