[英]Align components in web page header
我想將此html代碼對齊為網頁標題:
<div>
<h1>Web_site_title</h1>
<h:form>
<h:commandLink action="#{logoutController.logout}" value="Preferences"></h:commandLink>
</h:form>
<h:selectOneMenu value="#{language.language}" onchange="submit()">
<f:selectItem itemValue="en" itemLabel="English" />
<f:selectItem itemValue="bg" itemLabel="Български" />
</h:selectOneMenu>
<h:form>
<h:commandLink action="#{logoutController.logout}" value="Logout"></h:commandLink>
</h:form>
</div>
我想得到這個視覺效果:
如何對齊補碼?
使用display: flex
和justify-content: flex-end
將元素向右推, align-items: center
以垂直對齊它們。 然后使用margin-right: auto
在h1
上margin-right: auto
將其向左推。
.flex { display: flex; justify-content: flex-end; align-items: center; } h1 { margin-right: auto; }
<div class="flex"> <h1>Web_site_title</h1> <h:form> <h:commandLink action="#{logoutController.logout}" value="Preferences"></h:commandLink>form </h:form> <h:selectOneMenu value="#{language.language}" onchange="submit()"> <f:selectItem itemValue="en" itemLabel="English" /> <f:selectItem itemValue="bg" itemLabel="Български" />select </h:selectOneMenu> <h:form> <h:commandLink action="#{logoutController.logout}" value="Logout"></h:commandLink>form </h:form> </div>
最簡單的方法是將flex與如下所示的設置一起使用。 h1
上的auto
margin-right進行左/右分布, align-items: center
可用於所有項目的垂直居中。
.x { display: flex; align-items: center; } .x h1 { margin-right: auto; }
<div class="x"> <h1>Web_site_title</h1> <h:form>A <h:commandLink action="#{logoutController.logout}" value="Preferences"></h:commandLink> </h:form> <h:selectOneMenu value="#{language.language}" onchange="submit()">B <f:selectItem itemValue="en" itemLabel="English" /> <f:selectItem itemValue="bg" itemLabel="Български" /> </h:selectOneMenu> <h:form>C <h:commandLink action="#{logoutController.logout}" value="Logout"></h:commandLink> </h:form> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.