简体   繁体   English

使用CSS左上对齐单个图像

[英]Top, Left Aligning a Single Image Using CSS

I am trying to upload an image on our webpage ( https://www.palousebicycle.org/team.html ) so that the person's face isn't cut off, while keeping the others the same (it is the last image). 我正在尝试在我们的网页( https://www.palousebicycle.org/team.html )上上传图片,以使人的脸不会被割掉,而其他人则保持不变(这是最后一张图片)。

I tried inline html: 我尝试了内联html:

 #staff2 { border: 10px solid white; width: 45%; min-width: 250px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); } .staff img { border-radius: 50%; width: 228px; height: 228px; object-fit: cover; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); } .staff figure { display: inline-block; padding: 30px 40px; text-align: center; } #nick { position: absolute; top: -30px; left: -30px; align: top, left; } 
 <img "#nick" src="pictures/nick.jpg" alt="Nick" align="left,top"> 

as well as assigning an image #id (#nick) and using the CSS properties "align", "left", and "top". 以及分配图片#id(#nick)并使用CSS属性“ align”,“ left”和“ top”。

I also tried using a frame on the picture to move it top-left, but I couldn't get the image in the right place to not show the frame. 我还尝试在图片上使用框架将其左上移,但是我无法在正确的位置显示图像以不显示框架。

We are a small nonprofit, and it's been awhile since I wrote the webpage, so forgive me for being a bit rusty, and probably not asking the question correctly. 我们是一家小型的非营利性组织,自从我写了网页以来已经有一段时间了,所以请原谅我有些生疏,并且可能未正确提出问题。 Please let me know any other information or files I can post, and thank you so much for any help! 请让我知道我可以发布的任何其他信息或文件,非常感谢您的帮助! I really appreciate your time and assistance! 非常感谢您的宝贵时间和协助!

I would first suggest that you simply crop the image to a 228px by 228px square with the person centered appropriately in the image. 我首先建议您简单地将图像裁剪为228px x 228px的正方形,使人在图像中适当居中。 That would give you the most control in terms of the way the image is cropped. 这样可以在裁剪图像的方式上获得最大的控制权。

If you want to do it with css, you can do something like this: 如果要使用CSS执行此操作,可以执行以下操作:

 #nick { background-image: url(https://www.palousebicycle.org/pictures/nick.jpg); background-size: 300%; border-radius: 50%; width: 228px; height: 228px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); } 
 <div id="nick"></div> 

Displaying the image with the background-image css property instead of with html <img> tag allows you to better control the way it is cropped. 使用background-image css属性而不是html <img>标签显示图像,可以更好地控制其裁剪方式。 In this case, I just added a background-size: 300% which sized the background appropriately to fit the face in the circle. 在这种情况下,我仅添加了一个background-size: 300%来适当调整background-size: 300%以适合圆形中的脸部。

也许您必须在img组件中将(“ #nick”)替换为(id =“ nick”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM