When I hover over my Login and Register buttons, they do not turn yellow. When I hover over my click-to-email-admin button, it turns yellow. The code is the same for both links. As far as I can tell, nothing is stopping the two buttons from changing colors.
I'm aware that a:hover has to come AFTER a, a:visited. I've got it set up that way.
What is wrong with my CSS?
CSS
html {
min-height: 100%;
width: 2000px;
max-width: 100%;
}
body {
background: #292E37;
font-size: 13px;
width: 2000px;
max-width: 100%;
}
header {
z-index: 1;
top: 0;
max-width: 100%;
position: fixed;
background: cornflowerblue;
width: 100%;
height: 10%;
-moz-box-shadow: 0px 1px 5px 1px #000;
-webkit-box-shadow: 0px 1px 5px 1px #000;
box-shadow: 0px 1px 5px 1px #000;
border-bottom: 1px solid yellow;
font-family: fantasy;
/*This shadowbox is perfect to simulate floating on the bottom of a box */
}
these links do not work with hover
#loginButton {
bottom: 1%;
left: .5%;
position: absolute;
float: right;
text-decoration: none;
font-size: 12px;
max-width: 100%;
max-height: 100%;
}
#loginButton a {
color: green;
}
#loginButton a:visited {
color:black;
}
#loginButton a:hover {
color: yellow;
}
#registerButton {
bottom: 1%;
left: 3%;
position: absolute;
float: left;
text-decoration: none;
color: white;
font-size: 12px;
}
#registerButton a, a:visited {
color: white;
}
#registerButton a:hover {
color: yellow;
}
this link does work with hover
#centerIntro {
margin: inherit;
margin-top: 3%;
text-align: center;
-moz-box-shadow: 0px 1px 5px 1px #000;
-webkit-box-shadow: 0px 1px 5px 1px #000;
box-shadow: 0px 1px 5px 1px #000;
border: 1px solid yellow;
font-family: fantasy;
font-size: 20px;
color: white;
text-decoration: none;
text-shadow: 2px 0px 7px rgba(0, 0, 0, 1);
background-color: cornflowerblue;
border-radius: 1%;
width: 1000px;
max-width: 50%;
}
#centerIntro a, a:visited {
color: white;
}
#centerIntro a:hover {
color: yellow;
}
HTML
<header>
<img id="headerTitle" src="images/headerTSC.png" alt="The Stream Crate title">
<div>Login</div>
<div>Register</div>
</header>
Any ideas?
There's a few thing wrong here.
First, your selectors are wrong:
You have this markup:
<a id="loginButton" ...
And you're attempting to apply styles to it using this selector:
#loginButton a { ... }
That selector doesn't match that link. It would match an <a> tag nested inside any other element that had a id="loginButton", but it will not match an <a> tag whose id is loginButton.
You need to simply apply the styles to #loginButton and #loginButton:hover.
Also, you say...
I'm aware that a:hover has to come AFTER a, a:visited. I've got it set up that way.
That's wrong. That isn't how CSS selector precedence works. Order is important, but later selectors don't necessarily win just because they come later. In this case, a:hover is more specific, and it can come before or after a and it will still win.
Instead of
#loginButton a:hover {
color: yellow;
}
and
#registerButton a:hover {
color: yellow;
}
Try this, these buttons are already anchor elements so there is no need to add the "a" in the css
#loginButton:hover {
color: yellow;
}
and
#registerButton:hover {
color: yellow;
}
Here is an example of the buttons without the "a" references in the css
https://jsfiddle.net/41dha1p7/
Change your css
#loginButton a {
color: green;
}
to
#loginButton a:link {
color: green;
}
The same to #registrationButton.
The order also matters. It should be :link, :visited, :hover, and :active.
Related
This question already has answers here:
Circle with two borders
(4 answers)
Closed 3 months ago.
I have a CSS style for a button. I don’t know how to do it. I think it’s a bit too complicated and it’s not easy to make responsive adjustments. I would like to ask everyone how to write a button like this in CSS? thanks
.save_coin {
display: inline-block;
position: relative;
z-index: 3;
}
.save_coin::after {
content: "";
display: inline-block;
position: absolute;
background: #222;
border-radius: 32px;
padding: 26px 101px;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
#media (max-width: 768px) {
.save_coin::after {
border-radius: 38px;
padding: 38px 102px;
}
}
.save_coin span {
display: inline-block;
font-weight: 500;
text-align: center;
background: #222;
color: #fff;
padding: 12px;
border-radius: 32px;
position: relative;
z-index: 2;
border: 1px solid #fff;
width: 192px;
}
#media (max-width: 768px) {
.save_coin span {
width: auto;
font-size: 24px;
font-weight: 700;
padding: 15px 46px;
}
}
.save_coin:hover span {
color: #222;
background-color: #fff;
}
<span>save</span>
I think you can use outline attribute, work pretty good imo.
button {
padding: 10px 30px;
border-radius: 50px;
border: 2px solid white;
background-color: black;
color: white;
outline: 2px solid black;
}
button:hover {
background-color: white;
color: black;
}
<button>save</button>
You could try the box-shadow CSS property:
button {
cursor: pointer;
outline: none;
font-size: 30px;
/* 👇 outer line */
border: 5px solid black;
/* some very large number, to get a pill effect */
border-radius: 1024px;
padding: 30px 60px 30px 60px;
background: black;
color: white;
/* 👇 inner white line */
box-shadow: inset 0 0 0 3px white;
/* custom transition */
transition: 0.3s ease;
}
/* ignore this if you just want button design */
button:hover {
background: white;
color: black;
}
<button type="button">立即儲值</button>
How to add border bottom on hover effect as in this image
Add :hover for your button like this:
button {
width: 300px;
height: 60px;
border-radius: 10px;
background-color: #d94346;
border: none;
color: white;
font-weight: bold;
font-size: 1.3rem;
}
/* Add hover effect */
button:hover {
border-bottom: #bb262a 6px solid;
}
<button>Hover</button>
Is this result what you were expecting for ?
A box-shadowwould be more appropriate in my opinion.
EDIT: Comparing to the other answers I see, this way the button text won't move. 2 options.
button {
font-size: 30px;
padding: 30px 250px;
color: white;
background-color: #d84446;
border: none;
border-radius: 15px;
}
button:hover {
box-shadow: 0px 7px 0px #bb262a;
cursor: pointer;
}
<button>Hover</button>
you should do it in the other order
button:hover {
border-bottom: 4px solid #bb262a;
}
I'm trying to make a better looking label for a button when you hover over it, i was wondering how can i style the aria-label element to look like this screenshot i added below.
.
You can use the CSS attribute selector for this.
[aria-label] {
position: relative;
}
[aria-label="Search by voice"]:after {
content: attr(aria-label);
/* Your CSS here, this is just a random one for demonstration */
display: none;
position: absolute;
top: 110%;
left: 10px;
z-index: 5000;
pointer-events: none;
padding: 8px 10px;
line-height: 15px;
white-space: nowrap;
text-decoration: none;
text-indent: 0;
overflow: visible;
font-size: .9em;
font-weight: normal;
color: #fff;
text-shadow: 1px 0 1px #888;
background-color: #412917;
border-left: 6px solid #d37092;
border-radius: 2px;
box-shadow: 1px 2px 6px rgba(0,0,0,0.3);
}
a:focus {
outline:1px dashed #E92C6C;
}
[aria-label]:hover:after, [aria-label]:focus:after {
display: block;
}
I am making a modal view, using bootstrap framework, as shown in the figure , these are two buttons , I want hover effect when , mouse points on, using CSS but it isn't working,
#yesbut,#nobut {
width: auto;
height: auto;
display: inline-block;
padding: 10px 35px;
text-align: center;
background: #2e6c96;
color: #fff;
font-size: 16px;
text-decoration: none;
border: 1px solid #2e6c96;
outline: none;
text-transform: uppercase;
}
#yesbut :hover{
background: #fff;
border: 1px solid #fff;
}
#nobut :hover{
background: #fff;
color: #2e6c96;
border: 1px solid #fff;
}
<div id="yesbut" >YES</div>
<div id="nobut">NO</div>
enter image description here
#yesbut :hover{ /*Remove the space*/
background: #fff;
border: 1px solid #fff;
}
You got error in selectors corrected is:
#yesbut:hover{
background: #fff;
border: 1px solid #fff;
}
without space between #yesbut/#yesno and :hover.
Space mean you are targeting elements inside that particular element e.g. children of #yesbut.
You need to remove the spaces. If you put a space before the pseudo-class it means that you want to select a child of e.g. #yesbut instead of the element itself.
#yesbut,#nobut {
width: auto;
height: auto;
display: inline-block;
padding: 10px 35px;
text-align: center;
background: #2e6c96;
color: #fff;
font-size: 16px;
text-decoration: none;
border: 1px solid #2e6c96;
outline: none;
text-transform: uppercase;
}
#yesbut:hover{
background: #fff;
border: 1px solid #fff;
}
#nobut:hover{
background: #fff;
color: #2e6c96;
border: 1px solid #fff;
}
<div id="yesbut" >YES</div>
<div id="nobut">NO</div>
I have a header photo, and usually they are fairly easy to set up. However, for some reason which I cannot find, the header image floats over the elements of the HTML page.
Any help would be appreciated. I have tried looking for any margins/padding I forgot to delete, but there are none.
Picture of problem...
HTML pertaining to header image:
<div id="gallery">
<div id="imgContain">
<img src="pictures/clubhouse.jpg">
</div>
</div>
My CSS File: (not sure where the problem is, so I posted all of it...)
html, body
{
margin: 0;
padding: 0;
background-attachment: fixed;
background-image: url('.././pictures/04.jpg');
background-color: rgb(56,32,32);
}
#font-face
{
font-family: fancyFont;
src: url('fonts/fancy.otf');
}
#wrapper
{
min-width: 1000px;
margin: auto;
}
#content
{
background-color: white;
display: table;
border-radius: 5px;
bottom: 0px;
left: 0;
margin: auto;
right: 0;
top: 0;
width: 915px;
height: 100%;
box-shadow: 5px 5px 22px black;
}
#content p
{
padding: 25px;
font-family: Arial;
text-indent: 30px;
font-size: 1em;
word-wrap: break-word;
}
center
{
border-bottom: 1px solid black;
}
table
{
border: 1px solid black;
float: left;
}
.main-table /*Main table is the navigation table to the left...*/
{
background-color: white;
margin-bottom: 25px;
border: 4px double white;
width: 245px;
box-shadow: 0px 0px 10px black;
}
.main-table td
{
padding: 10px;
padding-left: 15px;
}
.main-table td a
{
text-decoration: none;
color: black;
font-family: Arial;
transition: .2s;
font-size: .9em;
padding-left: 20px;
}
.main-table td a:hover
{
border-bottom: 1px solid black;
color: black;
padding-left: 50px;
transition: .2s;
}
.main-table h1
{
font-family: fancyFont;
padding:10px;
color: black;
text-shadow: 2px 2px 1px white;
}
.division /*Division(s) are the small info boxes in the center.*/
{
margin-top: px;
margin-left: 40px;
border: none;
margin-bottom: 0px;
}
.division th
{
width: 250px;
background-color: white;
border-bottom: 3px double black;
padding: 10px;
font-family: fancyFont;
}
.division tr td
{
display: inline-block;
width: 250px;
height: 100px;
max-width: 250px;
}
#gallery
{
width: 100%;
height: 100px;
}
#gallery h1
{
font-family: fancyFont;
text-shadow: 2px 2px 1px #acacac;
}
#gallery img
{
width: 100%;
height: 450px;
border-bottom: 1px solid black;
}
table ul li
{
list-style: square;
font-family: Arial;
}
#imgContain
{
background-color: white;
width: 100%;
margin: 0;
padding: 0;
}
#table-container
{
width: 900px;
margin: 0;
}
take out the
#gallery{height:100px;}
css because your gallery img height is 450px and the two conflict.
An element will "float" over another element when the floating element's position is set to absolute. I don't see position: absolute; in your CSS, but I do see positioning styles (bottom: 0px; left: 0; etc.) so maybe another style sheet is applying position: absolute. Best way would be to inspect the elements using a browser inspector like Firefox has and see what CSS styles are being applied. You can send me the URL and I will look at it. If you just want to throw a dart at the board you could try setting this style:
#gallery {
position: static !important;
}
Floating generally happens when position: absolute is set in CSS, but strangely, it's not your case.
So, you can try to add a CSS property to this image, called z-index with the value of -1. It'll possibly work.
This property is a kind of "layers". By default, every element is set in z-index: 0.
So, basically, it'll be:
img {
z-index: -1;
}
or, in this case:
#gallery {
z-index: -1;
}
Sorry if my english is bad.