CSS 问题,无法在分区内居中图像

标签 css html css-float

寻找id为shelf的分区和类为inner_div的嵌套分区,现在的问题是inner_div中的图像在使用css后没有居中下面提供的类。

CSS 类

.inner_div{
  display:inline_block;
  width:20%;
  float:left;
  font-size:10px;
  text-align: center;
}
.inner_div p{
  text-align:center;
  margin-left:2px;
  margin-right:2px;
  /*font-weight:bold;*/
  padding:2px;
  height:35px;
  border-radius:5px;
  color:rgb(255,255,255);
  background-color:rgb(51,51,51);   
 }

我的目录结构简单

<div id='shelf'>
  <div class='inner-div'>
  <p>BOOK TITLE<p>
  <img src=''></img> //book cover
  <img src=''></img // available or not
  </div>
  <div class='inner-div'>
  <p>BOOK TITLE<p>
  <img src=''></img> //book cover
  <img src=''></img // available or not
  </div>
  <div class='inner-div'>
  <p>BOOK TITLE<p>
  <img src=''></img> //book cover   // not able to center this two images 
  <img src=''></img // available or not // not able to center this two images 
  </div>
    .......continues till data available in database


</div>

最佳答案

试试这个:

.inner_div img {
    display:block;
    margin:auto;
}

关于CSS 问题,无法在分区内居中图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22905357/

相关文章:

javascript - CSS 媒体查询横向 android 软键盘

javascript - jQuery - 隐藏一个特定的 div 直到另一个被点击,当 div 悬停时再次隐藏那个 div

css - 相当于向左浮动和 overflow hidden

css - 如何修复 HTML 样式覆盖 CSS?

javascript - 在单输入中进行 Markdown 更新

javascript - 如何增加信息覆盖的高度

javascript - 如何使用一个输入链接表单并使用两个链接提交

html - 包含图像的 float <li> 元素下方有 4px 间隙

html - 解决 IE 怪癖模式下的渲染错误

html - 使图像在其他图像下方对齐