我错过了我应该隐藏:before元素,只有当它在按钮div里面时才能显示,以便在悬停按钮上创建填充效果。
a.button {
font-size: 20px;
color: #000;
border: 2px solid #000;
padding: 8px 12px;
position: relative;
margin: 0;
}
a.button:before {
transition: 0.5s all ease-in-out;
content: '';
position: absolute;
background-color: red;
top: 100%;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
a.button:hover {
transition: 0.6s all ease-in-out;
color: #fff;
}
a.button:hover:before {
transition: 0.5s all ease-in-out;
top: 0;
}
<a href="#" class="button">buttt</a>
答案 0 :(得分:3)
将:before
元素高度设置为0
,然后将其:hover:before
更改为100%
该摘录
a.button {
font-size: 20px;
color: #000;
border: 2px solid #000;
padding: 8px 12px;
position: relative;
margin: 0;
}
a.button:before {
transition: 0.5s all ease-in-out;
content: '';
position: absolute;
background-color: red;
top: 100%;
left: 0;
width: 100%;
height: 0;
z-index: -1;
}
a.button:hover {
transition: 0.6s all ease-in-out;
color: #fff;
}
a.button:hover:before {
transition: 0.5s all ease-in-out;
top: 0;
height:100%;
}
<a href="#" class="button">buttt</a>
答案 1 :(得分:1)
你可以将你的链接包装在div中并将溢出设置为隐藏,如下所示:
a.button {
font-size: 20px;
color: #000;
border: 2px solid #000;
padding: 8px 12px;
position: relative;
margin: 0;
}
a.button:before {
transition: 0.5s all ease-in-out;
content: '';
position: absolute;
background-color: red;
top: 100%;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.wrap {
float: left;
width: 65px;
height: 32px;
overflow: hidden;
}
a.button:hover {
transition: 0.6s all ease-in-out;
color: #fff;
}
a.button:hover:before {
transition: 0.5s all ease-in-out;
top: 0;
}
&#13;
<div class="wrap"><a href="#" class="button">buttt</a></div>
&#13;
答案 2 :(得分:1)
将public function login()
{
$header = array("title" => "Welcome - ");
$this->load->view('includes/header', $header);
$this->load->view('accounts/login');
$this->load->view('includes/footer');
}
public function login_submit()
{
$data = array(
'username' => $this->input->post('username'),
'password' => sha1($this->input->post('password'))
);
$this->form_validation->set_rules('username', 'Username', 'required|is_unique[accounts.username]|min_length[6]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[6]');
$accountDetails = $this->accounts_model->fetch('accounts', $data);
if (!$accountDetails) {
echo "<script>alert('Account does not exist!'); window.location.href = '".base_url()."accounts/login';</script>";
} else {
$accountDetails = $accountDetails[0];
if ($accountDetails->status == 1) {
$header = array("title" => "Account - ");
$this->load->view('includes/header', $header);
$this->load->view('admin/home', $accountDetails);
$this->load->view('includes/footer');
} else {
echo "<script>alert('You account is blocked!'); window.location.href = '".base_url()."accounts/login';</script>";
}
}
}
和display:inline-block
添加到overflow:hidden
样式,因为代码的默认显示为a.button
。
inline
&#13;
a.button {
font-size: 20px;
color: #000;
border: 2px solid #000;
padding: 8px 12px;
position: relative;
margin: 0;
overflow:hidden;
display:inline-block; /* Add this */
overflow:hidden; /* Add this */
}
a.button:before {
transition: 0.5s all ease-in-out;
content: '';
position: absolute;
background-color: red;
top: 100%;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
a.button:hover {
transition: 0.6s all ease-in-out;
color: #fff;
}
a.button:hover:before {
transition: 0.5s all ease-in-out;
top: 0;
}
&#13;
答案 3 :(得分:1)
仅插入此:
a.button {
display: inline-block;
overflow: hidden;
//Other Codes...
}
a.button {
font-size: 20px;
color: #000;
border: 2px solid #000;
padding: 8px 12px;
position: relative;
margin: 0;
display: inline-block;
overflow: hidden;
}
a.button:before {
transition: 0.5s all ease-in-out;
content: '';
position: absolute;
background-color: red;
top: 100%;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
a.button:hover {
transition: 0.6s all ease-in-out;
color: #fff;
}
a.button:hover:before {
transition: 0.5s all ease-in-out;
top: 0;
}
<a href="#" class="button">buttt</a>