简体   繁体   English

图片在我的DIV中未对齐

[英]Picture not aligning in my DIV

Not sure what's going on here. 不知道这是怎么回事。 I re-seized the image to match the width of the div but somehow it still doesn't align with it. 我重新抓住了图像以匹配div的宽度,但是不知何故它仍然与它不对齐。 I uploaded the issue to codepen here. 我在这里将问题上传到了Codepen。 Tried to play around with the margins but its still doesn't change the behavior. 试图玩边际,但它仍然不会改变行为。

.propertyOverview.mapView {
  height: 430px;
  width: 600px;
  background-color: white;
  display: inline-block;
  border: solid 1px #E8E8E8;
  border-radius: 5px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  vertical-align: top;
  margin-left: 50px;
}

.propertyImage.mapViewPic {
  height: 260px;
  width: 600px;
  border-radius: 5px 5px 0 0;
}

.quickDetails {
  margin-top: 10px;
}

.propertyOverview p {
  margin: 0px 20px;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: .7px;
  font-family: 'Lato', sans-serif;
  line-height: 30px;
  color: #272635;
}

.propertyOverview .priceDetail {
  font-weight: 900;
  font-family: 'Lato', sans-serif;
  font-size: 20px;
  color: #272635;
}

.quickFacts {
  border-top: solid 1px #E8E8E8;
  padding-top: 5px;
  margin-top: 12px;
  color: #272635;
  font-size: 15px;
}

https://codepen.io/insivika/pen/PEzxPK https://codepen.io/insivika/pen/PEzxPK

Issue is @ 问题是@

.propertyOverview.mapView {
    height: 430px;
    width: 600px;
}

Where width is 600px and the image width is 360px. 其中width为600px,图像宽度为360px。 Thats why the extra space. 那就是为什么有多余的空间。

 .propertyOverview.mapView { height: 430px; width: 360px; background-color: white; display: inline-block; border: solid 1px #E8E8E8; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; vertical-align: top; margin-left: 50px; } .propertyImage.mapViewPic { height: 260px; width: 100%; border-radius: 5px 5px 0 0; } .quickDetails { margin-top: 10px; } .propertyOverview p { margin: 0px 20px; font-size: 16px; font-weight: 400; letter-spacing: .7px; font-family: 'Lato', sans-serif; line-height: 30px; color: #272635; } .propertyOverview .priceDetail { font-weight: 900; font-family: 'Lato', sans-serif; font-size: 20px; color: #272635; } .quickFacts { border-top: solid 1px #E8E8E8; padding-top: 5px; margin-top: 12px; color: #272635; font-size: 15px; } .quickFact1, .quickFact2, .quickFact3, .like { display: inline-block; margin-left: 20px; font-family: 'Lato', sans-serif; } .like { margin-left: 110px; font-size: 23px; color: #cccccc; } .like:hover, .like:active { color: #FF3366; } 
  <div class="propertyOverview mapView"> <div class="propertyImage mapViewPic"> <img src="https://image.ibb.co/ivV9vR/sample_Property_Map1.png" alt="sample_Property_Map1" alt=""> </div> <div class="quickDetails"> <p>5689 Main Ave</p> <p>Los Angeles, CA 90019</p> <p class="priceDetail">$556,000</p> </div> <div class="quickFacts"> <div class="quickFact1">2 br</div> <div class="quickFact2">2 bth</div> <div class="quickFact3">4,000 SF</div> <div class="like"><i class="fa fa-thumbs-up"></i></div> </div> </div> 

As I understand it, I guess you are trying to stretch the image to take up whole width of container. 据我了解,我猜您正在尝试拉伸图像以占据整个容器宽度。 Here is the problem: 这是问题所在:

<div class="propertyImage mapViewPic">
    <img src="https://image.ibb.co/ivV9vR/sample_Property_Map1.png" 
     alt="sample_Property_Map1" alt="">
</div>

.propertyImage.mapViewPic {
    height: 260px;
    width: 600px;
    border-radius: 5px 5px 0 0;
}

You have given a class to parent container of the image and targeting it in CSS. 您已为图像的父容器提供了一个类,并在CSS中将其定位。

Instead do this. 而是这样做。 Remove the extra container div 删除多余的容器div

<div class="propertyOverview mapView">
    <img src="https://image.ibb.co/ivV9vR/sample_Property_Map1.png" 
     alt="sample_Property_Map1" alt="" class="propertyImage">
</div>

Update your CSS like this. 像这样更新您的CSS。

.propertyOverview .mapViewPic {
    width: 600px;
    border-radius: 5px 5px 0 0;
}

Aligning an image is same as aligning a text.... If you want your image to be centrally aligned with any div tag as you mentioned then their may be two possibilities that either align it relative to the div tag or you align both div and image together 对齐图像与对齐文本相同。...如果您希望图像与您提到的任何div标签集中对齐,则可能有两种可能,即它们相对于div标签对齐,或者同时对齐div和一起成像

If you want both div and image to be centrally aligned use 如果要同时将div和图像集中对齐,请使用

.propertyImage.mapViewPic {
text-align : center;
height: 260px;
width: 600px;
border-radius: 5px 5px 0 0;
}
div{
text-align: center;
}

This will align both of your div and image centrally taking into note that the image is not a child element of the div tag you mentioned, otherwise the image will be aligned with relative to the the div tag 这将使div和图像都集中对齐,并注意该图像不是您提到的div标签的子元素,否则图像将相对于div标签对齐

You can check this link 您可以检查此链接

.propertyImage.mapViewPic {  
   display: flex;
   align-items: center;
   justify-content: center; 
}

You can also set text-align: center; 您还可以设置text-align:center; for img tag 对于img标签

**if you want full image of div ** **如果您想要div的完整图像**

.propertyImage.mapViewPic {
  overflow:hidden;
}

.propertyImage.mapViewPic img {
  width:100%;
}

you can use this code 您可以使用此代码

<!DOCTYPE html>
<html>
<head>
<title>Login page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
    .mm {
        display: flex;
        display: -webkit-flex;
        align-items: center;
        -webkit-align-items: center;
        justify-content: center;
        -webkit-justify-content: center;
        width: 100%;
        height: 100vh;
        text-align: center;
    }
</style>
</head>
<body>
    <div class="mm"> <img src="https://i.kinja-img.com/gawker-media/image/upload/t_original/1250833953592952166.png"/> </div>
</body>
</html>

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

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