Skipping value in CSS box model value definitions - css

TLDR;
I have a CSS input form which consists of 4 number inputs for each direction and it sets margins. When I submit auto, auto margins make element positioned in center horizontally. When I give 0px, It sets it to 0px which is really a value of "0px", and it doesn't provide an auto like untouched property. Is this possible?
I wondered if there is something like this: For example I have a CSS definition like this:
border-width: 4px;
and on some case I want to change the width of only left and right borders:
border-left-width: 2px;
border-right-width: 2px;
Instead of writing this, I can't write these:
border-width: initial 2px;
border-width: inherit 2px;
border-width: unset 2px;
because they seem to be invalid values in chrome developer tools.
Is there anything else I can use to do this?
function toggleClasses(){
document.querySelectorAll(".div").forEach(function(elem){
elem.classList.toggle("toggled");
});
}
.div {
width: 100px;
height: 100px;
margin: 20px;
display: inline-block;
background: #eee;
border-color: #333;
border-width: 4px;
border-style: solid;
}
.div.div-1.toggled {
border-width: initial 2px;
margin: initial 10px;
}
.div.div-2.toggled {
border-width: inherit 2px;
margin: inherit 10px;
}
.div.div-3.toggled {
border-width: unset 2px;
margin: unset 10px;
}
<div class="div div-1"></div>
<div class="div div-2"></div>
<div class="div div-3"></div>
<input type="button" onclick="toggleClasses();" value="Togggle" />

Related

CSS Borders and border-radius for text

I came across this trick when I wanted to feature some headline text. I love the look of it as was wondering if there was a way to have the ends point up.
.pagebreaker {
padding: 10px;
margin-bottom: -5px;
border-top: 4px solid #f6d241;
border-radius: 35px;
}
ref Image:
I've tried negative border-radius and negative padding. Is there something I am missing here? Or is this something that can't be done?
Thanks.
Use border-bottom
.pagebreaker {
padding: 10px;
margin-bottom: -5px;
border-bottom: 4px solid #f6d241;
border-radius: 35px;
width: 300px;
height: 10px;
}
<div class="pagebreaker"></div>

How to prevent input from cutting tails of the letters without changing the height?

I'm trying to achieve an input field with an underline. As it is visually more appealing to me, I'm trying to make underline as close as possible to the font. I did achieve the closeness, but now, input field cuts tail parts of the letters with tails. Is there a possible workaround for this? Can I cancel input's this behaviour with something like "overflow: visible"? Or may I draw a fake line over the input field, instead of using border-bottom? Thanks in advance.
In short, I'm trying to make text get through the bottom line.
Here is a screenshoot about the problem.
Here is my current class:
.kk_input {
border: 0;
border-bottom: 1px solid #000;
outline: none;
font-size: 20px;
height: 20px;
margin-top: 5px;
}
Without seeing the rest of your markup, this should give you an idea enough to go off of.
.kk_input {
border: 0;
outline: none;
font-size: 20px;
}
div {
position: relative;
}
div:after {
position: absolute;
content: "";
bottom: 4px;
left: 0;
height: 1px;
width: 100%;
background-color: black;
}
<div>
<input class="kk_input" type="text">
</div>
You can use more than one box-shadow to create this effect.
.so49204829_input{
line-height: 20px;
font-size: 20px;
padding: 8px 4px;
box-shadow: inset 0 -11px 0 #fff, inset 0 -12px 0 #000;
}
<input type="text" class="so49204829_input">
& here's another approach using a second element. Unfortunately, you can't add an :after pseudo-element to input elements (at the time of posting).
.so49204829_input {
line-height: 20px;
font-size: 20px;
padding: 8px 4px;
width: 200px;
display:block;
}
.so49204829_input_accent {
margin-top: -14px;
height: 1px;
width: 208px;
background-color: #000;
pointer-events: none; /* this makes sure click events aren't intercepted by the accent-line element */
}
<input type="text" class="so49204829_input"><div class="so49204829_input_accent"></div>

CSS border abbreviation

I want to trim my CSS border statement. I know there is a possibility, but I found always that one in the internet e.g. :
You would better do it through classes like this:
.box{
width: 100px;
height: 100px;
margin: 20px;
float: left;
}
.border{
border-width: 5px;
border-style: solid;
border-color: #98bf21;
}
.b1{ border-width: 5px 10px 15px 2px; }
.b2{ border-width: 5px 7px 10px 7px; }
.b3{ border-width: 15px 2px 10px 5px; }
<div class="box border b1"></div>
<div class="box border b2"></div>
<div class="box border b3"></div>
For for instance padding, you can write: padding: 5px 10px to set a five pixel top and bottom padding and a 10 pixel left and right padding.
But for border, that is not the case. You have to set the same value to all sides, or set the property for one side at a time.
You can however set just the width using border-left-width, so you could set a default border and override just the width for specific sides:
border: 5px solid #666;
border-left-width: 10px;
border-right-width: 10px;
Or use border-width, which lets you set multiple values for the width alone, in the same way as you can set padding.

Set Border color of round corner div in IE?

I am having problem to set the div border , which using the border-radius.htc.
It works in all browsers except IE.
I referred this site to make a div as rounded corners http://dimox.net/cross-browser-border-radius-rounded-corners/
My HTML will be,
<div id="div1">
<input type="text" id="txtBox" />
</div>
CSS will be,
#div1 {
width: 200px;
height: 30px;
background-color: #D1C9CC;
border-style: solid;
border-width: thin;
border-color: red;
-webkit-border-radius : 10px;
-moz-border-radius: 10px;
border-radius: 10px;
behavior: url(jquery/border-radius.htc);
-webkit-border-radius: 10px;
}
#txtBox {
width: 180px;
height: 20px;
background-color: transparent;
position: relative;
top: 5px;
left: 10px;
border-style: none;
}
My need to set the textbox rounded corner with border of red color in the IE. How can I modify this ?
Good answers are definitely appreciated.
You may need to select F12 on your keyboard while inside of IE and check which document mode you are in. Anything below IE 9 will not work.

CSS line-height style to button in Firefox (decrease)

How to decrease offset between text and top border in button. I'm trying to set line-height, but it's not working in Firefox: Fiddle
CSS:
input[type="button"]
{
border-color: #D2D2D3 #79797A #4D4D4E #C0C0C1;
border-style: solid;
border-width: 1px;
height: 16px;
line-height: 7px;
padding: 1px;
width: 16px;
background: #d8dadb;
}
HTML:
<input type="button" value="+" />
Your setting a hard width and height. Take those out or set them to auto and your button will respond to padding adjustments.
input[type="button"]
{
border-color: #D2D2D3 #79797A #4D4D4E #C0C0C1;
border-style: solid;
border-width: 1px;
line-height: 7px;
padding: 1px;
background: #d8dadb;
}​
Firefox bug (feature)
http://www.cssnewbie.com/input-button-line-height-bug/
This could help a little:
button::-moz-focus-inner {border: 0; padding: 0;}

Resources