Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 内联元素的水平对齐改进_Css_Html - Fatal编程技术网

Css 内联元素的水平对齐改进

Css 内联元素的水平对齐改进,css,html,Css,Html,在我的页面上,标题区域中有两个元素。我希望第一个元素集中在标题区域的中间,第二个元素一直被推到标题区域的右侧。我使用以下代码达到了预期效果: <div id="header-area" style="text-align:center;width:100%;"> <div id="partition1" style="display:inline-block;width:33%;"></div> <div id="partition2" styl

在我的页面上,标题区域中有两个元素。我希望第一个元素集中在标题区域的中间,第二个元素一直被推到标题区域的右侧。我使用以下代码达到了预期效果:

<div id="header-area" style="text-align:center;width:100%;">
  <div id="partition1" style="display:inline-block;width:33%;"></div>
  <div id="partition2" style="display:inline-block;width:33%;">
    <div id="element1" style="display:inline;width:400px;height:100px;">
      <h3 style="display:inline;width:400px;">Main title Goes Here</h3><br/><br/>
      <p style="display:inline;width:400px;">Subtitle goes here</p>
    </div>
  </div>
  <div id="partition3" style="display:inline-block;width:33%;text-align:right;">
    <div id="Element2" style="display:inline;width:150px;vertical-align:middle;">
      <button onclick="history.back();" style="height:45px;width:100px;">
      Back</button>
    </div>
  </div>
</div>

主标题在这里

字幕显示在这里

返回

您会注意到我将
标题区域划分为三个空格,并将
元素1
元素2
在各自的分区内对齐。如何在不划分
标题区域的情况下实现相同的布局?

有几种方法可以做到这一点。这里有两个:

选项#1:浮动

HTML:

<div id="header">
    <div class="right">Element on right end</div>
    <div class="center">Center-Aligned Element</div>
</div>
<div id="header">
    <div>Center-Aligned Element</div>
    <div class="right">Element on right end</div>
</div>
<div id="header">
    <h3>Main Title Goes Here</h3>
    <p>Subtitle Goes Here</h3>
    <button>Element on right end</button>
</div>
选项#2:绝对位置

HTML:

<div id="header">
    <div class="right">Element on right end</div>
    <div class="center">Center-Aligned Element</div>
</div>
<div id="header">
    <div>Center-Aligned Element</div>
    <div class="right">Element on right end</div>
</div>
<div id="header">
    <h3>Main Title Goes Here</h3>
    <p>Subtitle Goes Here</h3>
    <button>Element on right end</button>
</div>
使用元素的示例:

HTML:

<div id="header">
    <div class="right">Element on right end</div>
    <div class="center">Center-Aligned Element</div>
</div>
<div id="header">
    <div>Center-Aligned Element</div>
    <div class="right">Element on right end</div>
</div>
<div id="header">
    <h3>Main Title Goes Here</h3>
    <p>Subtitle Goes Here</h3>
    <button>Element on right end</button>
</div>