Html <div 类 ="row"> 不居中

标签 html css

首先我想说我对编码知之甚少。

在这个网站我做了http://academiadae.com ,我在每一侧添加了两个小 div,所以我可以让一个 div class="6u"居中。

<div class="row">
    <div class="3u"></div>
    <div class="6u"><img src="images/logo.png" /></div>
    <div class="3u"></div>
</div>

你能帮我让它居中而不需要其他 div 吗? 我尝试在 CSS 中制作不同的元素 =center,但没有成功。

谢谢。

最佳答案

首先,您使用的类 6u 不会被选中。 CSS 名称必须以下划线 (_)、连字符 (-) 或字母 (a–z) 开头才能用作 CSS 选择器。你可以查看这个page供引用。

其次,如果你想让单个 div 居中,你可以应用这个:

<div class="row">
  <div class="item6u">
  test
  </div>
</div>

其中只有一个类名以字母开头的 div。 对于您的 CSS,您需要设置 div 的宽度,就像@Sprazer 告诉您需要设置边距一样:

.row{
   background-color:yellow;
}
.item6u{
   background-color:red; 
   width:50%; //changed to 50% percentage as wawa suggested
   margin:0 auto; 
   text-align:center;
}

请在此处查看代码:JSFIDDLE .

关于Html <div 类 ="row"> 不居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35457089/

相关文章:

html - 不显示支持的字母

html - 空白 : nowrap; css style not allowing for table to be responsive

html - Material 设计精简版 : How to display Table on Mobile?

html - 对齐标签、跨度和按钮

css - 为什么有些网页在移动设备上显示在平板电脑 View 中?

html - 在表格中调整 TD 的大小

html - 由于 MIME 类型而未加载样式表

javascript - 通过javascript添加图像改变位置

html - 如何让这些 id 标签的样式正确?

css - 边框半径 Nativescript