html - 带有包装器和 float 元素的 CSS 布局

标签 html css

我想要一个包装器,我需要在其中的左侧有一个 img,中间有一个按钮,右侧有一个文本,所有这些都在同一行中。为了居中我试过了

       {margin:0 auto;}

但它不起作用。同样使用单独的标签将元素移动一个行距。

CSS:

.wrapper
{
  width:70%;
  margin:0 auto; /* THIS IS WORKING FINE */
}

.custom_image
{
  float:left;
}
.custom_button
{
  background-color:#ff6600;
  border:2px; /* THIS IS NOT WORKING */
  border-color:#ccc; /* THIS IS NOT WORKING */
  padding:5px;
  margin:0 auto; /*THIS IS NOT WORKING */
}
.custom_text
{
  float:right;
}

HTML:

<div class="wrapper">
  <div class="custom_image"><img src="LOCATION"/></div>
  <div class="custom_button"><input type="submit" value="Submit"></div>
  <div class="custom_text">TEXTS</div>
</div>

最佳答案

更新

您已经非常接近了,您只需要将按钮从内部 div 中取出并将文本置于包装器的中心。像这样尝试:

HTML

<div class="wrapper">
  <input type="submit" value="Submit">
  <div class="custom_image"><img src="http://www.petside.com/sites/default/files/imagecache/thumbnail_50x50/grumpy_cat_photo.jpg"/></div>
  <div class="custom_text">TEXTS</div>
</div>

CSS

.wrapper {
    text-align:center;
    width:70%;
    margin:0 auto;
}
.custom_image {
  float:left;
}
.custom_text {
  float:right;
}

Demo

关于html - 带有包装器和 float 元素的 CSS 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16255512/

相关文章:

javascript - Bootstrap 3 滚动 spy

html - 换行会切断内联元素边框

javascript - 为什么滚动行为 :smooth not working but javascript window. 滚动平滑?

javascript - 在 Marionette 布局中维护一堆 Marionette ItemView

html - Angular 4 MaterializeCSS ngfor 和标签

javascript - 如何在 $(variable).click, jquery 中获取变量 id

javascript - 创建长度为 <tr> 的 .row.cells 行

html - 如何仅使用 CSS 在 HTML 中垂直居中文本

javascript - 使用javascript通过鼠标悬停更改div的类名

html - IE11 盒子阴影扩散和边框半径