【问题标题】:Image inside of div not centeringdiv内的图像未居中
【发布时间】:2013-12-17 09:34:21
【问题描述】:

我似乎无法在 div 中将图像居中。 未居中的图像是“quotimg”,它位于 div 内部的 div quotejd 内部。

目前正在学习一些css和html(不应该使用html5元素)

HTML

<div class="head">

   <div class="quotejd">

      <img id="quoteimg" src="pictures/quotes/jd.png">

      <p id="quote">“The only creatures that are evolved enough to convey pure love<br> are dogs and infants.”</p>

</div>

</div>

CSS

.Head {
background-image: url('pictures/dogwallpaper1.png');
background-repeat: no-repeat;
background-size: cover;
height: 550;
text-align: center;
margin: 0 auto;
}

.quotejd {
margin: 0 auto;
text-align: center;

}

 #quoteimg {
width: 5em;
margin: 0 auto;
text-align: center;
display: block;
float: none;
}

#quote {
font-size: 1.8em;
line-height: 1em;
margin: 0 auto;
text-shadow: 0px 0px 5px rgba(57,57,57,1);
font-family: 'Nixie One', cursive;
text-align: center;
color: #ffffff;
}

【问题讨论】:

标签: css html centering


【解决方案1】:

当我也在学习 CSS 时,这让我很困惑。尝试将图像周围的 div(使用 .quotejd 类)设置为设定的宽度(即宽度:960px)。 margin 的 auto 值不知道如何居中。

【讨论】:

  • 我尝试将 div -“quotedj”和“head”的宽度设置为 79em,但效果不佳。这是同时起作用的:将“quotejd” div 填充到 30px,但它并没有真正居中
  • 是的,填充不会成为居中的方法。你想让你的头部部分填满整个页面吗?我可能会将 .head 宽度设置为 100%,然后将内部 div“.quotejd”设置为 75%。每次使用 margin:0 auto 时,都需要指定宽度(我倾向于使用百分比来测试它)。也许就像 Ankit 上面所说的那样,您正在尝试做的事情的屏幕截图会有所帮助。
  • i.imgur.com/fKH158t.png ,我希望它保持在 79em 左右。
  • 好的,我明白了。您是否尝试将 .head 设置为该部分的全宽以及将 .quotejd 设置为 79em 的宽度?还是不行吗?
  • 好的,看看这段代码:jsfiddle.net/shudson4/Ag4Dy 确保你的 CSS 中的类是小写的,并且你必须在 .head 和 .quotejd div 中使用 width:79em。跨度>
猜你喜欢
  • 2013-12-24
  • 1970-01-01
  • 2012-06-14
  • 1970-01-01
  • 2016-07-13
  • 1970-01-01
  • 1970-01-01
  • 2013-12-03
  • 2016-11-27
相关资源
最近更新 更多