I have two buttons at the centre of my page with this css design.
button{
outline: none;
text-align: center;
border-radius:15px 50px 30px;
}
.button:hover {background-color: #3e8e41}
.button:active{
background-color: #3e8e41;
box-shadow:0 5px #666;
transform:translateY(4px);
}
#javaBtn{
color: #fff;
box-shadow:0 9px #999;
background-color:#2ECC71;
border: none;
padding: 15px 30px;
cursor: pointer;
font-size: 12px;
}
#layoutBtn{
color: #fff;
box-shadow:0 9px #999;
background-color:#2ECC71;
border: none;
font-size: 12px;
padding: 15px 20px;
cursor: pointer;
}
My html:
<div align="center">
<img src="yalda.jpg" class= "mainPic">
</div>
<div align="center">
<button class="button" id="layoutBtn">Layouts</button>
<button class="button" id="javaBtn">Java</button>
</div>
<div align="left">
<img src="me.jpg" class= "myPic">
<p><font color="white"> <i>some text</i></font></p>
<a href="&" target="_blank" class="fa fa-linkedin" ></a>
<button class="googleBtn">some text</button>
</div>
I am trying to create another button with a different css design but my third button inherits the css design from the first two and looks kinda like them. What can I do about it?
The third button looks like your first two buttons because you did not create a style that is specific to it. Your first rule applies to all of the buttons on the page:
button {
outline: none;
text-align: center;
border-radius:15px 50px 30px;
}
Unlike your second two rules, here you wrote button and not .button. This means that it will select all elements of type button, not all elements that have class="button".
Additionally, if you want your third button (I am assuming that this is the one with class="googleBtn") to look very different, then you must create a style rule that selects it, like so:
.googleBtn {
color: red;
/* replace this with your style rules */
}
Side note: the HTML align attribute, and the <font> element have been deprecated for years. Please do not use this to format your page.
First, you have to declare a CSS rule for .googleBtn with different styles in the rule. Also I noticed that the two rules in your CSS, #layoutBtn and #javaBtn, styles are exactly the same. Instead, you can define one rule for both #layoutBtn and #javaBtn with that style of button and another for .googleBtn.
Related
I have a dynamic tab system and because of the design every time a tab is active it changes to blue both the text and a line under it.
The problem is that I need the line to occupy the entire width of the screen in grey and the blue line appears indicating the active tab just over that same grey line.
this is my html
<div class="tabs d-flex flex-row">
<div *ngFor='let category of this.market; let i = index'>
<h2 (click)="selectedTab = i" [ngStyle]="selectedTab === i && {'border-bottom':'4px solid #0E5FA4', 'color':'#0E5FA4'}">{{category.name}}</h2>
</div>
</div>
and here's my css where I create the gray line
.tabs {
border-bottom: 4px solid #DCE0E6;
margin-bottom: 20px;
}
As I have it now there is a grey line below the blue line indicating the active text.
What I need to create is the effect of the grey line that has a blue stretch just below the active tab text.
Here is an stackblitz link https://angular-ivy-er17vx.stackblitz.io.
Any idea how to achieve this?
Please try this css:
p {
font-family: Lato;
}
.tabs {
display: flex;
height: 80px;
border-bottom: 4px solid #DCE0E6;
margin-bottom: 20px;
}
.tabs > div > h2 {
margin:0;
padding: 20px 4px 10px 4px;
height: 50px;
}
stachblitz
A more robust solution would be to use angular material tabs
In general for tabs with default bottom border and default selected border:
HTML
<span [ngClass]="{ 'active-tab': selectedIndex === i }"
*ngFor="let item of items; let i = index"
(click)="onHeaderTab(i)">
<span> {{ slide.header }} </span>
</span>
TS
selectedIndex = 0;
onHeaderTab(i){
this.selectedIndex = i;
}
CSS
.active-tab {
border-bottom: 2px solid #2f353d;
padding-bottom: 4px;
}
I tried using the solutions found on stackoverflow to do this but it does not seem to work in newer versions of firefox. I want the red background to take up the entire button but this only works in the chrome, not firefox. I added the button::-moz-focus-inner css rules that should resolve this. Does anyone know how to do this in newer versions of firefox?
<style>
button {
padding: 0px;
}
label {
display: block;
padding: 1px 6px;
background-color: red;
}
button::-moz-focus-inner {
padding: 0;
border: 0;
}
</style>
<button>
<label for="myId">My Button</label>
</button>
<br />
<button>My Button</button>
<input id="myId" type="checkbox" />
You've put a label into a button, and are applying the red background to the label, not the button. You'd be better off not using a label tag, but if you need to, put the button in the label tag.
<style>
button {
/* Padding is pretty important for buttons */
padding: 3px 5px;
border: 0;
background-color: red;
cursor: pointer;
margin: 0px;
}
</style>
<button>My Button</button>
<!-- It is good practice to put labels right before what they are labeling -->
<label for="myId"><button>My Button</button></label>
<input id="myId" type="checkbox" />
I may be wrong, and by all means im not trying to be rude. But it looks like you're pretty new to web dev. Look up any css property or tag you're having trouble with on W3Schools. It's a great website.
Cheers, Isaac.
I need to add custom styling to the checked/active radio button behind the label.
I can get the border and width of the buttons fine, just can't set a background color to the checked/active button only. As the input-label is outside the div I can't seem to manage it.
I can't mess with the code below, can only change CSS.
Can anyone help me please?
<label class="radio-inline display-block col-sm-3" for="concern" style="color: rgb(102, 102, 102);">
<span class="has-pretty-child">
<div class="clearfix prettyradio labelright blue has-pretty-child">
<input class="radio the_input_element" name="runway_surface" id="concern" value="Concern" style="display: block !important; color: rgb(50, 55, 60);" autocomplete="off" type="radio">
<a class="checked fa fa-check ui-state-active" style="color: rgb(0, 163, 201);"></a>
</div>
<span class="input-label radio-label" style="color: rgb(102, 102, 102);">Concern</span>
</span>
Something like this:
The idea here is the label element which can create amazing things.
Playing with it can generate you a bunch of great effects.
You just need to hide the radios or checkboxes and work with its labels, and you need to know three important css selectors for this effect:
The general next sibling: element ~ sibling{ style } which select all the sibling found after the element
The direct next sibling: element + sibling{ style } which select only the first sibling after the element
The checked input selector: input:checked{ style } which selects the input if it's checked only.
And this effect can be done with these steps:
Create an input and a label for every choice you need
Connect every input with its label using the for and id
Hide the input using something like display: none or others
Set a style for your label which will be the default mode
Set a new style for the label that placed after a checked input input:checked + lebel{ style }
Now we can apply it:
nav{
width: fit-content;
border: 1px solid #666;
border-radius: 4px;
overflow: hidden;
display: flex;
flex-direction: row;
flex-wrap: no-wrap;
}
nav input{ display: none; }
nav label{
font-family: sans-serif;
padding: 10px 16px;
border-right: 1px solid #ccc;
cursor: pointer;
transition: all 0.3s;
}
nav label:last-of-type{ border-right: 0; }
nav label:hover{
background: #eee;
}
nav input:checked + label{
background: #becbff;
}
<nav>
<input type="radio" id="x1" name="x"/>
<label for="x1">Choice 1</label>
<input type="radio" id="x2" name="x"/>
<label for="x2">Choice 2</label>
<input type="radio" id="x3" name="x"/>
<label for="x3">Choice 3</label>
<input type="radio" id="x4" name="x"/>
<label for="x4">Choice 4</label>
<!-- as many choices as you like -->
</nav>
And it's done now.
You can search for many many ideas on codepen and you can see this great navigation bar using only css and navigates throw the different pages:
Nav Bar Using Only CSS
Or See this collapsed nav bar that can be opened or closed using only css too:
Open & Close Nav Bar Using CSS
To style a checkbox or a radio button you need to hide the real input and style another element to look like the one you need. Please refer to this w3schools page for a tutorial on how to do this: https://www.w3schools.com/howto/howto_css_custom_checkbox.asp
you need to hide the real input and style another element to look like the one you need. Please refer to this
<input type='checkbox' name='checkbox-btns' id='checkbox-btn-2'/> <label htmlFor='checkbox-btn-2' class='btn'> Unsafe</label>
input[type=checkbox]{display:none;}
input[type=checkbox] + label.btn{
width:300px;
padding: 5px 5px;
text-align: center;
margin: 5px 5px;
display: inline-block;
text-transform: capitalize;
font-size: 10px;
font-weight: 600;
outline: none;
position: relative;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
border: 1px solid #0088cc;
color: #0088cc;
-webkit-transition: none;
-moz-transition: none;
transition: none;
border-radius: 10px;
cursor: pointer;
}
input[type=checkbox]:checked + label.btn{
background: #0088cc;
color:white;
}
Sometimes I see two entries for the CSS 'color' attribute active on a single element, even when one has !important. The one without !important is taking precedence though, as it should (I am trying to force the element to color: white). See screenshot:
Thanks!
UPDATE: added html markup
<div class="x-button x-button-back x-layout-box-item x-stretched" id="quit-button" style="width: auto !important;">
<span class="x-badge" style="display: none;"></span>
<span class="x-button-icon x-hidden" id="ext-element-1109"></span>
<span class="x-button-label" style="" id="ext-element-1110">Quit</span>
</div>
.peacekeepers-edition is set on the first element inside the body, #playview is a distant descendent.
Regardless of the specificity of the rule all proprieties from the CSSOM will appear in the inspector rule view. The fact that the "color:#ccffff" is not crossed/underline is just an inspector bug.
BTW, you overqualified your selectors: .preacekeepers-edition #playview will have a specificity of 1|1|0|, that is way more that you should have. Adding !important will make things hard to manage later.
I'm making some assumptions about your markup (because you haven't provided any), but I think it's fairly safe to say that this is your issue.
Assuming your markup is something like this...
<div class="peace-keepers-edition">
<div id="playview">
<button class="x-button-back">
<i class="x-button-icon">icon</i>
</button>
</div>
</div>
Your first selector targets the button element...
.peace-keepers-edition #playview .x-button-back {
color: #FFF !important;
}
but your second selector targets an element that is a descendant of your button...
.peace-keepers-edition #playview .x-button-back .x-button-icon {
color: #ccccff;
}
Your !important rule is irrelevant because your selectors are targeting different elements.
Easy fix; add this line after line 769...
.peace-keepers-edition #playview .x-button-back .x-button-icon {
color: #fff;
}
Broken example...
body {
background: #1a1a1a;
}
button {
padding: 15px;
font-size: 30px;
background: green;
}
.peace-keepers-edition #playview .x-button-back {
color: #FFF !important;
}
.peace-keepers-edition #playview .x-button-back .x-button-icon {
color: #ccccff;
}
<div class="peace-keepers-edition">
<div id="playview">
<button class="x-button-back">
<i class="x-button-icon">icon</i>
</button>
</div>
</div>
Working example...
body {
background: #1a1a1a;
}
button {
padding: 15px;
font-size: 30px;
background: green;
}
.peace-keepers-edition #playview .x-button-back {
color: #FFF !important;
}
.peace-keepers-edition #playview .x-button-back .x-button-icon {
color: #fff;
}
<div class="peace-keepers-edition">
<div id="playview">
<button class="x-button-back">
<i class="x-button-icon">icon</i>
</button>
</div>
</div>
I am making a set of buttons for my site, and I am in need of some professional insight.
In order to reduce CSS bloat, I want to subclass my buttons for different colors, ex .button.blue .
Will the following incur issues in the future? (assuming I don't make a class of just .blue)
Do I have to use something like .button.button-blue instead?
.button {
display:inline-block;
padding: 9px 18px;
margin: 20px;
text-decoration: none;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
text-align: center;
background: #FFE150;
}
.button.blue {
background: #49b8e7;
border:1px solid #54abcf;
border-bottom:1px solid #398fb4;
color:#FFF
text-shadow: 0 1px 0 rgba(255,255,255, 0.5);
}
.header{
height: 50px;
}
.header.blue {
background: blue;
color: #fff;
}
What you have there with the multi-classes will work fine assuming you want them to work like so:
<div class="button blue">
Will use .button and .button.blue
</div>
<div class="button">
Will only use .button
</div>
<div class="header blue">
Will use .header and .header.blue
</div>
<div class="header">
Will only use .header
</div>
<div class="blue">
Will use neither of the .blue declarations because it doesn't contain header or button.
</div>
A selector like .button.blue actually selects for an element with that has both "blue" and "button" as classes, not a class called .button.blue. See http://www.w3.org/TR/CSS21/selector.html#class-html.
You can use the .button.blue style rule you have listed, but you'll need to rearrange your HTML so that you have something like <button type="button" class="button blue"/>. However, you don't really need to have a button class since it being a button (or <input type="submit">, etc.) is enough to use in your selector. You could write a CSS rule that is simply button.blue, input[type=submit].blue{}
Seems like button.blue is enough.
The only difference between the two is if you use <button class="button blue">, or <button class="button button-blue">.
You even don't need to duplicate the painting in blue... You can just do something like this:
.button
{
// button style
}
.header
{
// header style
}
.blue
{
background: blue;
color: #fff;
}
Of course if you add the blue class to each of them. (<div class="header blue">and<button class="button blue">)
Combine the classes applying the color you want to theme.
HTML:
<input type="text" class="text-field-required default" .../>
<select class="autocomplete-drop-down blue">...</select>
<a href="#" class="button-link green" .../>
CSS:
.text-field-required {
//component css theme without colors
}
.default {
//default color css theme for any component
}
.blue {
//blue css theme for any component
}
.green {
//green css theme for any component
}