How to Show a Hidden Label When Hovering Over a Button?

We all know you can change the colour of a button when you hover over it in CSS alone.

But, what would I do to make a label within it show up when I hover over it?

Effectively, my button just has an icon/image in it when it is in normal mode. But, when the user hovers over the button it will show a text label as well.

I realise you can put a title into the button with gives a text description of what the button does, but can you put a label into a button when you hover over it?

Is that a good idea, or should I just stick to using title?

Ie, here is my button in normal state:

<button>
    <img src="./images/iconok.png" alt="Submit" />
    <label style="display: none"> Submit</label>
</button>

and in my hovered state

<button>
    <img src="./images/iconok.png" alt="Submit" />
    <label style="display: inline-block"> Submit</label>
</button>

How do I implement this?

Note: When the button is not being hovered over, I do not want any space being allocated to the label at all, as if it was not even there.

EDIT: I have made a mistake in my original question that affected the answer. I had display: block; on my label, which caused the label to appear below the image, but should have been display: inline-block; to make it appear at the side.

3

Your question is little bit confusing, but is this what you wanted?:

HTML:

<button>
    <img src="./images/iconok.png" alt="Submit" />
    <label class="btn-label"> Submit</label>
</button>

CSS:

.btn-label {
  display: none;
}

button:hover .btn-label {
  display: inline-block;
}

3

  • Use visibility: hidden to prevent the label from taking up any
    space when hidden.
  • And visibility: visible with :hover pseudo-selector to display it on hover of button inside button.

This is how you can show a hidden label when the user is hovering around the button.
There are 2 sumbit buttons because there is one for the image alt (you can’t display the image here, and one for label after you hover on the button.

function ShowSubmitButton() {
  document.getElementById("submit").style.display = "block"
}
#submit {
  display: none;
}
<button>
<img src="./images/iconok.png" alt="Submit" onmouseover="ShowSubmitButton()">
<!--There are two submits because the top one is from the alt of the img-->
    <label id="submit"> Submit</label>
</button>

But I wouldn’t suggest you to use that. Instead, I would like to give you a better code here:

function ShowSubmitButton() {
  document.getElementById("submit").style.display = "block"
}
#submit {
  display: none;
}
<img src="./images/iconok.png" alt="Submit" onmouseover="ShowSubmitButton()"><!--This "submit" is from alt-->
<button id="submit">
    <label> Submit</label>
</button>

Explaination

I am using JavaScript to modify the button’s style> property through an addEventListener method. However, in this instance, I didn’t use addEventListener because you can also set it directly within the HTML element’s attributes.

As an alternative approach, you could reverse the logic by applying display: none when the button is not being hovered over. This will hide the submit button when it’s not active. If you choose to implement this, you’ll need to add a container around the button because when you are hovering on that image, you will not be able to click the submit button at the same time. Just please let me know if you need help with this setup.

0

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật