View Single Post
Old 02-23-2021, 02:16 PM   #114
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,361
Karma: 20212223
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
Quote:
Originally Posted by knightrider247 View Post
Hi there,

somehow I am incapable to get the pictures centered. Here is my CSS-code. Isn't display block the correct code?

.landscape img {
width: 100%;
display: block;
}


Another thing: Why couldnt I say: width: 100 % for both landscape and portrait pictures? I know you guys said that it would result in a result I didnt want, but with the tools I have I cant get it to display it the "wrong" way (cut off or whatever). I tested with kindl previewer, phone, paperwhite.

Thank you for your help!
knightrider

display:block does not automatically center the image, it simply means to treat the tagged section as a "block element"...typically it will result in putting it on a new line. If you have your image embedded inside of a block level element (such as a <div>) then display:block is unnecessary.

Also, with a width=100%, the image is already taking up the full width of the parent element, so centering is moot; you would need to provide CSS for the parent element instead.

You need to give it some CSS such as:


Code:
.landscape {margin: 1em 0}

.landscape img {margin:0 auto; width: 75%}

<div class="landscape"><img alt="" src="sample.jpg" /></div>
or:
Code:
.landscape {margin: 1em auto; width: 75%}

.landscape img {width:100%}

<div class="landscape"><img alt="" src="sample.jpg" /></div>
Attached is a graphic that illustrates some of the different issues that arise with images. The graphic/images assume you preserve the aspect ratio (otherwise they get stretched or squashed) and that you somehow center the image vertically (which is not covered in this question/answer).
Attached Thumbnails
Click image for larger version

Name:	Capture.PNG
Views:	497
Size:	397.8 KB
ID:	185573  
Turtle91 is offline   Reply With Quote