all. Very new to HTML and CSS, and I'm having trouble applying CSS to some buttons. Here's the code:
HTML:
<div class="top-buttons">
<button id="first-button">One</button>
<button id="second-button">Two</button>
<button id="third-button">Three</button>
<button id="fourth-button">Four</button>
<div>
CSS
.button {
display: inline-block;
border: none;
/* padding */
text-align: center;
text-decoration: none;
/* font-size */
margin: 15px 30px;
cursor: pointer;
color: #564946;
}
#first-button{
border-radius: 20%;
}
I was toying around and was able to get only the border-radius to work; none of the other properties worked, even when I switched it from .button to .top-buttons. Any ideas? Only other thought I have at this point is it may be the text editor I'm using? I just stuck with Atom because I had previously installed it. Thank you so much in advance!
Your buttons are wrapped within <button></button> tags, whereas you are applying your styling to .button class, so if you want to apply global styling to those buttons, you should use following to apply styling to button tag:
button {
display: inline-block;
border: none;
/* padding */
text-align: center;
text-decoration: none;
/* font-size */
margin: 15px 30px;
cursor: pointer;
color: #564946;
}
you only need to specify the element that you what to affect.
For example, there are two ways to solve that
Styles only for the buttons inside .top-buttons:
.top-buttons > button {
display: inline-block;
border: none;
text-align: center;
text-decoration: none;
margin: 15px 30px;
cursor: pointer;
color: #564946;
}
Styles for all buttons
button {
display: inline-block;
border: none;
text-align: center;
text-decoration: none;
margin: 15px 30px;
cursor: pointer;
color: #564946;
}
Related
i want 2 of my buttons to be stacked (on top of each other). however, after using display: block, the buttons are still side by side. here are my html & css code!
does anyone know why? i had done my research and display:block is the way to code my buttons to make them on top of each other. would appreciate any help!
thank you in advance for everyone that have helped me! i'm really grateful. :)
.homepage_viewcurrentproject
{
font-family : Times New Roman;
font-size : 28px;
color : #FFFFFF;
color : rgb(255, 255, 255);
}
nav#button
{
float: left;
padding: 15px;
width: 150px;
height:350px;
margin-top: 15px;
margin-left: 65px;
text-align: center;
}
nav#button ul li
{
margin: 0; /*Setting margins and padding to 0 to remove browser default settings*/
padding: 0;
list-style-type: none; /*remove the bullets*/
color: white;
}
nav#button li a
{
display: block; /*to allow changes of- width,height, padding and margin around the link*/
width: 350px; /* length of button */
padding: 5px 10px; /*top and bottom:5px left and right:10px*/
background-color: #25374C;
text-decoration: none; /* remove the underline of hyperlink */
margin:10px;
padding: 30px 40px;
background: #25374C;
border-radius: 18px;
}
nav#button a:link{
color: white;
text-decoration: none;
}
nav#button a:visited{
color: white;
}
nav#button li a:hover, /*add a style to an element when you mouse over it*/
button li a:focus /*add a style to an element that has keyboard input focus*/
{
background-color: #2c425c;
color: #CCFFC5;
}
nav#button li a:active /*add a style to an element that is activated*/
{
background-color: #25374C;
}
<nav id="button" class="homepage_viewcurrentproject">
<ul>
<li>
Check out my Python Study
</li>
<li>
View latest project
</li>
</ul>
</nav>
enter image description here
You can use this method:
nav ul {
display: flex;
flex-direction: column;
}
I have declared a CSS attribute for the main-container of a HTML page. Now I want an ahref-button to have another color, but it is not applied without !important. Therefore I want ask you how I can do that.
Thank you!
See also: Codepen
main a:link, main a:visited {
color: black;
text-decoration: none;
}
.test {
background-color: green;
padding: 5px 5px;
text-align: center;
text-decoration: none;
font-size: 20px;
width: 190px;
display: block;
color: white; /*is not applied*/
}
/*Another try*/
a.test {
color: white; /*is not applied, however it is with !important. But this shouldn't be the right solution?*/
}
<main>
Button
</main>
Remove :link in main.a:link or style more specific main a.test with your color. I try to remove it and working as well
A link on a "navbar" on my website can't be clicked for some reason and I can't seem to find the reason why. It is in the viewport(Here is the link to the website:https://codetheworld.000webhostapp.com/. The link on the website is supposed to be the "Learn to code" button). One interesting thing is that, once I open an inspect element window, it works. Here is the code snippet for just the navbar:
#first {
margin-top: 500px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
position: relative;
top: -1150px;
left: 100px;
z-index: 4;
}
li a {
width: 200px;
height: 50px;
font-size: 2em;
text-decoration: none;
color: white;
font-family: Georgia, serif;
padding: 10px;
border: 2px solid white;
border-radius: 7px;
text-align: center;
line-height: 30px;
}
li a:hover {
background-color: grey;
color: white;
text-decoration: none;
}
<ul id="first">
<li>Learn to code</li>
</ul>
You positioned your element outside of the viewport, so it can't be clicked.
Remove the margin-top & top positioning and everything will work:
#first {
background: black;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
position: relative;
left: 100px;
z-index: 4;
}
li a {
width: 200px;
height: 50px;
font-size: 2em;
text-decoration: none;
color: white;
font-family: Georgia, serif;
padding: 10px;
border: 2px solid white;
border-radius: 7px;
text-align: center;
line-height: 30px;
}
li a:hover {
background-color: grey;
color: white;
text-decoration: none;
}
<ul id="first">
<li>Learn to code</li>
</ul>
Well, you have a <div id="up2"> and it's right over your button. That's the reason why you can't click that button.
You could increase the top value of your div#up2 and edit/decrease the top values of the elements in the div#up2.
#Alessi 42 commented the correct solution, however Dekel was the one who posted it.
I did a fiddle and verified certainty: https: // jsfiddle.net / drpeck / tgeyfpd8 /
So learning from the experience I would say:
First test with and without CSS, and once you have determined that without CSS the element appears.
Start introducing CSS selectors and add/removing the different attributes
Once you find the attribute that is affected proceed to play with the values.
For my own sake, although not required, having the absolute path always helps me personally to avoid any unexpected misunderstanding (in other words to have clarity), even if the file is under the root directory. i.e:
Insted of this: href="tutorial.html" I would do href="./tutorial.html"
HTML code:
<div id="but_2" class="button">
Portfolio
</div>
<div id="but_1" class="button">Home</div>
CSS code:
.button {
background-color: #ff0000;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
#but_1 {
position: absolute;
right: 50px;
top:20px;
}
My css button isn't working, it brings me to where I need to be, but it is blue and is underlined(the text in the button) I have text-decor none, but it still isnt going away.
Target the a element to remove the underline and change the color. You can target it with .button a {}
.button {
background-color: #ff0000;
border: none;
padding: 15px 32px;
text-align: center;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
#but_1 {
position: absolute;
right: 50px;
top: 20px;
}
.button a {
text-decoration: none;
color: white;
}
<div id="but_2" class="button">Portfolio
</div>
<div id="but_1" class="button">Home</div>
You need to be more specific and target the a href attribute.
For example:
.button a {
text-decoration: none;
color: #000;
}
https://jsfiddle.net/xojev64e/
a {text-decoration: none; color:#FF0000;} shows unvisited link
a:visited {color:#FF0000;} shows visited link
a:hover {color:#FF0000;} shows mouse over link
a:active {color:#FF0000;} show selected link
use all property to define you color
I think you have not clear your browsing history of your browser. First clear you history, session, or cookie and then perform following steps.
Add following to your css file
.button a {
text-decoration: none;
color: white;
}
And add this for more attraction on mouseover
.button a:hover {
text-decoration: none;
color: black;
}
Hope this will help you.. :)
I would like to know what is the 'correct' way to change my current menu, that looks like this:
to this:
The problem I have is making the buttons into these blocks that would change background on hover, and the vertical alignment, do I use padding? blocks? table? Help :S
(The color doesn't matter)
CSS:
.menu{
clear: both;
background-image:url(meniuBG.jpg);
height:55px;
line-height: 10px;
}
.menu a{
text-align: center;
text-decoration: none;
font-style:italic;
color:rgb(193,193,193);
margin-right: 25px;
margin-left: 25px;
}
HTML (for no apparent reason):
<div class="meniu">
NAUJIENOS
KREPSINIO VADOVAS
TRENIRUOTES
IDOMYBES
GALERIJA
APIE MUS
</div>
.menu {
...
height:55px;
/* line-height: 10px; delete this */
}
.menu a {
...
line-height: 55px; /* add this */
}
Because you want to center vertically your <a> , there is many way to do this you can search on google there's many tuto.
the solution i give you is to make line-height equal to the heigh (55px). this solution work when your text is just on one line.
and for the hover just make <a> display: inline-block; and replace margin with padding
.menu a{
text-align: center;
text-decoration: none;
font-style: italic;
color: rgb(193,193,193);
/* margin-right: 25px; */
/* margin-left: 25px; */
padding: 0 25px;
line-height: 55px;
display: inline-block;
}
here's a FIDDLE
try to add this
.menu a{
text-align: center;
text-decoration: none;
font-style:italic;
color:rgb(193,193,193);
margin-right: 25px;
margin-left: 25px;
line-height:55px;
display: inline-block;
}
.menu a:hover{
background-color: #E7550C;
}