How can I make the color of the text turn to black not only when I move the mouse cursor to the text, but also when the cursor enters the whole button area?
.button {
text-align: center;
font-size: 1.5em;
margin: 0 auto;
width: 15%;
padding: 8px;
border: 2px solid;
border-color: #e7dd84;
background-color: rgba(236, 229, 167, 0.2);
transition: 0.35s;
}
.button a, active {
text-decoration: none;
color: #e7dd84;
}
.button a:hover {
text-decoration: none;
color: black;
}
.button:hover {
color: black;
background-color: white;
border-color: white;
transition: 0.35s;
}
<div class="button">
Go to site
</div>
Do you mean like this?
.button
{
text-align: center;
font-size: 1.5em;
margin: 0 auto;
width: 15%;
padding: 8px;
border: 2px solid;
border-color: #e7dd84;
background-color: rgba(236,229,167,0.2);
transition: 0.35s;
}
.button a, active
{
text-decoration: none;
color: #e7dd84;
}
.button:hover a
{
text-decoration: none;
color: black;
}
.button:hover
{
color: black;
background-color: white;
border-color: white;
transition: 0.35s;
}
<div class="button">
Go to site
</div>
Instead of styling the <div>, I suggest to do it on the <a> tag directly.
I would use inline block, so that you don't need to specify the width, as inline block has the ability of shrink-to-fit based on length of the text. And on the container all you need is text-align:center to center that button horizontally.
Hover on the edges of the button you'll see the link also becomes available, because we set padding on it directly. Unless your original demo, you'll have to hover on the text to be able to click. This small improvement makes it more accessible, less confusing.
I also moved the class button onto the <a>, and add container to the <div>.
jsfiddle
.container {
text-align: center;
}
.button {
text-decoration: none;
background-color: rgba(236, 229, 167, 0.2);
border: 2px solid #e7dd84;
color: #e7dd84;
display: inline-block;
font-size: 1.5em;
padding: 8px;
transition: 0.35s;
}
.button:hover {
text-decoration: none;
background-color: white;
border-color: white;
color: black;
}
<div class="container">
<a class="button" href="first.html">Go to site</a>
</div>
You have to give the color change to the link when you hover on the button.
Currently you have given the color to change when hoverd on the link inside the button.
Check updated snippet.
.button
{
text-align: center;
font-size: 1.5em;
margin: 0 auto;
width: 15%;
padding: 8px;
border: 2px solid;
border-color: #e7dd84;
background-color: rgba(236,229,167,0.2);
transition: 0.35s;
}
.button a, active
{
text-decoration: none;
color: #e7dd84;
}
.button:hover a
{
text-decoration: none;
color: black;
}
.button:hover
{
color: black;
background-color: white;
border-color: white;
transition: 0.35s;
}
<div class="button">
Go to site
</div>
Related
HTML:
Get Started
<div id="middle"></div>
CSS
.hero-btn{
display: inline-block;
text-decoration: none;
color: #fff;
border: 1px solid #fff;
padding: 12px 34px;
font-size: 16px;
background: transparent;
position: relative;
cursor: pointer;
}
.hero-btn:hover{
border: 1px solid #f44336;
background: #f44336;
transition: 1s;
}
I was expecting it to scrroll to my div. But it scrolls and then refreshes the page.
The refresh is due to the <a> link default behavior. Give it the attribute href="#" and to prevent automatic default scroll add return false; on the onclick listener like that:
.hero-btn{
display: inline-block;
text-decoration: none;
color: #fff;
border: 1px solid #fff;
padding: 12px 34px;
font-size: 16px;
background: transparent;
position: relative;
cursor: pointer;
}
.hero-btn:hover{
border: 1px solid #f44336;
background: #f44336;
transition: 1s;
}
Get Started
<div id="middle"></div>
I haven't tested it but it should works
When I'm, including a font-awesome icon, there's this unexpected white background that I can't remove. Any ideas on how to remove it?
HTML Code:
<div class="notifications-window" id="close-notifications">
<div class="notifications-header">
<h4>Notifications</h4>
<button type="button" onclick="closenotifs()"><i class="fas fa-window-close"></i></button>
</div>
<div class="notifications-details">
<p>Congratulations! Login Reward: 2 credits</p>
<p>Congratulations! Login Reward: 2 credits</p>
</div>
CSS Code:
.notifications-window {
width: 350px;
border: 3px solid rgb(0, 0, 0);
background-color: rgb(160, 156, 156);
color: #fff;
border-collapse: collapse;
border-radius: 5px;
text-align: center;
list-style-type: none;
display: inline-block;
}
.notifications-window p {
font-size: small;
padding: 5px;
background: rgb(141, 136, 136);
border-radius: 5px;
margin: 5px;
}
.notifications-details {
overflow-y: auto;
max-height: 350px;
}
.fa-window-close {
display: inline-block;
float: right;
justify-content: right;
cursor: pointer;
text-decoration: none;
text-align: center;
color: #000;
background-color: #fff;
border: none;
outline: none;
transition: background 250ms ease-in-out,
transform 150ms ease;
-webkit-appearance: none;
-moz-appearance: none;
}
I'm attaching an image of how the icon looks like after styling
https://i.stack.imgur.com/bfBW6.png
The background of the button is added by User Agent Stylesheet. You can explore more about user agent stylesheet here.
However you can remove the background of the button by writing your own styles.
For this I wrote a .button class for button and also removed background-color: #fff; from your .fa-window-close class. Try this out;
CSS:
.notifications-window {
width: 350px;
border: 3px solid rgb(0, 0, 0);
background-color: rgb(160, 156, 156);
color: #fff;
border-collapse: collapse;
border-radius: 5px;
text-align: center;
list-style-type: none;
display: inline-block;
}
.notifications-window p {
font-size: small;
padding: 5px;
background: rgb(141, 136, 136);
border-radius: 5px;
margin: 5px;
}
.notifications-details {
overflow-y: auto;
max-height: 350px;
}
.fa-window-close {
display: inline-block;
float: right;
justify-content: right;
cursor: pointer;
text-decoration: none;
text-align: center;
color: #000;
/*background-color: #fff;*/
border: none;
outline: none;
transition: background 250ms ease-in-out, transform 150ms ease;
-webkit-appearance: none;
-moz-appearance: none;
}
.button {
background: transparent;
border: none;
}
HTML:
<div class="notifications-window" id="close-notifications">
<div class="notifications-header">
<h4>Notifications</h4>
<button type="button" onclick="closenotifs()" class="button"><i class="fas fa-window-close"></i></button>
</div>
<div class="notifications-details">
<p>Congratulations! Login Reward: 2 credits</p>
<p>Congratulations! Login Reward: 2 credits</p>
</div>
</div>
I am a little confused:
In the picture, the element that says "Navigation einblenden" is span button, while the one with "Suche" is a span a. I have styled them exactly the same:
part of the css, dispOpts is the class-name of the parent span. and the all:none is for testing.
.dispOpts {
all:none;
}
.dispOpts button {
all:none;
background: var(--main-color);
color: white;
border: 1px solid white;
padding: 0.4em;
transition-duration: 0.5s;
margin-left: 0.4em;
margin-bottom:2em;
}
.dispOpts a {
all:none;
background: var(--main-color);
color: white;
border: 1px solid white;
padding: 0.4em;
transition-duration: 0.5s;
margin-left: 0.4em;
}
.dispOpts::before,
.dispOpts::after {
display: none;
}
.dispOpts a:hover,
.dispOpts button:hover{
background: var(--accent-color);
color: white;
}
I cannot find any difference at all...
It is our workbench for a project at work:
http://exist3.ulb.tu-darmstadt.de:8080/exist/apps/edoc/view.html?id=e000001_kuttenberger_religionsfrieden_einleitung
As you can see in your code, you didn't style them the same.
The .dispOpts a is missing margin-bottom:2em; and also to work the same as on button, you have to add also display: inline-block on .dispOpts a, and also to be same, they need to have same line-height and font-size, so result would be like this:
.dispOpts button {
all:none;
background: var(--main-color);
color: white;
border: 1px solid white;
padding: 0.4em;
transition-duration: 0.5s;
margin-left: 0.4em;
margin-bottom:2em;
line-height: 1.4;
font-size: 14px;
}
.dispOpts a {
all:none;
background: var(--main-color);
color: white;
border: 1px solid white;
padding: 0.4em;
transition-duration: 0.5s;
margin-left: 0.4em;
margin-bottom: 2em;
display: inline-block;
line-height: 1.4;
font-size: 14px;
}
And all would be lined correctly with same height.
Also you could use it with all: initial; and the end result would be:
.dispOpts button {
all:initial;
background: var(--main-color);
color: white;
border: 1px solid white;
padding: 0.4em;
transition-duration: 0.5s;
margin-left: 0.4em;
margin-bottom:2em;
}
.dispOpts a {
all:initial;
background: var(--main-color);
color: white;
border: 1px solid white;
padding: 0.4em;
transition-duration: 0.5s;
margin-left: 0.4em;
margin-bottom: 2em;
display: inline-block;
}
With this way, you would need only margin-bottom, and display on a element.
Both link didn't have the same styles :
I want that the size of my button should get fixed for the mobile view but it should be auto for window. how can I do it, please help? Or it should be auto placed in the center. I am using this code. I am using CSS like this.
.button1 {
border: 2px solid rgb(0, 0, 0);
box-sizing: inherit;
background-color: #ffffff;
margin-right: 1.7px;
color: black;
font-size: 18px;
font-weight: 980;
padding: 6px 42px;
text-align: center;
transition: all 0.3s ease-in-out 0s;
width: 96.6px;
text-decoration: none;
line-height: 22px;
font-size: 16px;
font-family: domine;
display: inline-table;
}
.button2 {
border: 2px solid rgb(255, 87, 51);
background-color: #FF5733;
box-sizing: inherit;
margin-right: 1.7px;
color: white;
font-size: 18px;
font-weight: 980;
padding: 6px 42px;
text-align: center;
transition: all 0.3s ease-in-out 0s;
width: 96.6px;
text-decoration: none;
line-height: 22px;
font-size: 16px;
font-family: domine;
display: inline-table;}
.button2 a:link, .button2 a:visited {
background-color: #FF5733;
color: white;
text-decoration: none;
}
.button2 a:hover, .button2 a:active {
background-color: #FF5733;
color:#000000;
}
#media screen and (max-width: 680px) and (min-width:0px){
.button2 { padding: 6px 32px;width: 85px;display: inline-table;max-height:80px;
}
.button1 { padding: 6px 32px;width: 85px;max-height:88px;}
}}
<button style="margin:auto"class="button button1">BUY NOW</button><button style="margin:auto;" class="button button2">DETALS</button>
Could the issue be that you have the button style set to auto in your inline CSS in your html page? That would override the margins you are setting in your CSS page. Maybe that is effecting the way the buttons are being displayed, because the media query looks good. I really hope this helps. Good luck!
I am using a CSS button code, but I found some problem in doing it. I want that the width of my button should get fixed for the mobile view but it should be auto for the window. how can I do it, please help? Or it should be auto placed in the center. I am using this code. I am using CSS like this.
CSS code :
.button1
{
border: 2px solid rgb(0, 0, 0);
box-sizing: inherit;
background-color: #ffffff;
margin-right: 1.7px;
color: black;
font-size: 18px;
font-weight: 980;
padding: 6px 42px;
text-align: center;
transition: all 0.3s ease-in-out 0s;
width: 96.6px;
text-decoration: none;
line-height: 22px;
font-size: 16px;
font-family: domine;
display: inline-table;
}
.button2
{
border: 2px solid rgb(255, 87, 51);
background-color: #FF5733;
box-sizing: inherit;
margin-right: 1.7px;
color: white;
font-size: 18px;
font-weight: 980;
padding: 6px 42px;
text-align: center;
transition: all 0.3s ease-in-out 0s;
width: 96.6px;
text-decoration: none;
line-height: 22px;
font-size: 16px;
font-family: domine;
display: inline-table;
}
.button2 a:link, .button2 a:visited
{
background-color: #FF5733;
color: white;
text-decoration: none;
}
.button2 a:hover, .button2 a:active
{
background-color: #FF5733;
color:#000000;
}
#media screen and (max-width: 680px) and (min-width:0px)
{
.button2 { padding: 6px 32px;width: 85px;display: inline-table;max-height:80px;}
.button1 { padding: 6px 32px;width: 85px;max-height:88px;}
}
HTML code:
<button class="button button1">
BUY NOW
</button>
<button class="button button2">
DETALS
</button>
For a start, change the button display from inline-table to inline-block