您会从这个问题中看出来,我对Flexbox和SASS还是陌生的。我有一个MVC应用程序,在其中我尝试根据标题是否经过身份验证来对齐标题登录信息。
我要完成的工作是,如果您未通过身份验证或其用户名和注销/帐户信息堆积在一行中,则标题的左侧带有徽标,而某些登录/注册按钮则排在底部,一行如果已通过身份验证,则彼此优先。
我正在尝试使用flexbox完成这些任务。我的想法是,我将有一个整体的父容器"header_account-info"
,在"header__logo"
子容器中有徽标,在"header_account-user"
或"header-account-login"
中有其他登录部分。为了进行测试,我使用了“ header-account-login”容器。
使用下面的代码,我无法使"header-account-login"
容器具有背景色(用于测试),也无法使其与底部对齐。
我将其放在Code Pen中,并看到相同的结果。 https://codepen.io/anon/pen/WgGxQL
为什么我在"header-account-login"
容器中看不到背景色,并且我认为我已经进行了正确的设置,以使按钮移至容器的末端(底部)?
HTML
<div class="header">
<div class="header__logo">
<img src="~/images/logo.png" class="header-logo" />
</div>
<div class="header_account-info">
<div class="header-account-login">
<a href="@Url.Action("Register", "Account")" id="registerLink" class="btn btn-outline-secondary">
<i class="far fa-user-plus"></i> Register
</a>
<a href="@Url.Action("Login", "Account")" id="loginLink" class="btn btn-outline-secondary">
<i class="fas fa-sign-in-alt"></i> Log In
</a>
</div>
</div>
</div>
SASS
.header {
display: flex;
padding: 3px;
&__logo {
/*flex: 1;*/
margin-right: auto;
background-color: aqua;
height: 100px; /*TESTING*/
}
&__account-info {
display: flex;
background-color: aquamarine;
}
&__account-user {
background-color: blanchedalmond;
}
&__acount-login {
align-items: flex-end;
background-color: aquamarine;
}
}
答案 0 :(得分:1)
为什么我在“标头帐户登录”容器中看不到背景色,并且我认为我已经进行了正确的设置,以使按钮移至容器的末尾(底部)?
因为您的HTML / CSS中有错别字-在某些情况下,您使用的是单个下划线,在其他情况下,则使用两个下划线。另外,“帐户”在某些地方拼写错误。
至于劳特,我认为就足够了:
.header {
display: flex;
padding: 3px;
justify-content: space-between;
}
.header__logo {
/*flex: 1;*/
margin-right: auto;
background-color: aqua;
height: 100px;
}
.header__account-info {
display: flex;
align-items: flex-end;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="header">
<div class="header__logo">
<img src="http://www.fillmurray.com/g/140/100" class="header-logo" />
</div>
<div class="header__account-info">
<div class="header__account-login">
<a href="@Url.Action(" Register ", "Account ")" id="registerLink" class="btn btn-outline-secondary">
<i class="far fa-user-plus"></i> Register
</a>
<a href="@Url.Action(" Login ", "Account ")" id="loginLink" class="btn btn-outline-secondary">
<i class="fas fa-sign-in-alt"></i> Log In
</a>
</div>
</div>
</div>
答案 1 :(得分:-2)
这是使其工作的一种方法:
.header-account-info {
position: relative;
}
.header-account-login {
background-color: red;
position: absolute;
bottom: 0px;
right: 0px;
width: 158px;
}
您尝试调用班级的方式(即“&__ acount登录”)是错误的-只需给自己一个完整的班级名称即可,例如我的示例。