css - HTML <div> 水平对齐

标签 css

我试图水平对齐两个 div。尝试了大约 15 种不同的方法后,我仍然无法让它发挥作用。

This is how my divs are aligned now

$html .= '<div class="fotoLinks">';
$html .= '  <img src="'.$image->getWebPath().'"/>';
$html .= '</div>';
$html .= '<div class="tekst">';
$html .=    $this->text;
$html .= '</div>';

使用相应的 CSS(div.alinea 是一个包装 div):

div.alinea
{
    float: left;
    width: 100%;
    margin-bottom: 15px;
}

div.tekst
{
    float: left;
}

div.fotoLinks
{
    float: left;
    margin-right: 15px;
    height: 100%;
}

我希望能从新方法中获得一些灵感。

最佳答案

尝试

display: inline-block;

代替 float: left;

编辑:

一种您可以尝试但不太受支持的方法,用于包装器 div,设置:

display: table;

对于你的内部 div:

display: table-cell;

关于css - HTML <div> 水平对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12768253/

相关文章:

带有内联 SVG 的 CSS 生长动画

css - 创建一个可能包含两个或三个元素的相同高度的按钮

html - 段落内的行高问题

css - 覆盖 index.html css react 元素

jquery - 使图像适合其父元素

html - 悬停效果链接

jquery - 平滑 jQuery 幻灯片

jquery - 单击另一行时取消突出显示行背景

php - Wordpress 的高级自定义字段文本溢出 DIV

html - Bootstrap CDN 未加载