For work I have to go through and create a ton of html pages and I find that many of the custom classes I have created can be used repeatedly if I can figure out a way to add to attributes such as height and width.
example:
.custom_class{font-size:1em;height:100px;width:80px;}
Lets say I have that class that I use on many of the divs in my pages but I stumble upon a template I am creating where the width needs to be a little bit wider. We will say I need the width to be 95px. Is there a way to add +15px to the current width and not have to go in and find out the current width of 80px and then either make a new class or right inline css to compensate for it?
.custom_class_differnt{font-size:1em;height:100px;width:95px;}
I dont want to have to recreate this entirely. I was hoping there was a way to just do maybe style="width:+15px;" or something. (a little in line css is fine, no more than that though)
thanks
It goes up in its parent chain to set the property value to its parent value. CSS properties such as height , width , border , margin , padding , etc. are not inherited.
If you want the parent dive to get the children height you need to give to the parent div a css property overflow:hidden; But to solve your problem you can use display: table-cell; instead of float... it will automatically scale the div height to its parent height... Save this answer. Show activity on this post.
Answer: Set the 100% height for parents too And we all know that the default value of the height property is auto , so if we also set the height of <body> and <html> elements to 100%, the resulting height of the container div becomes equal the 100% height of the browser window.
With JQuery you could add the width you need:
$(".yourSelector").css("width","+=15px")
This will add 15px to the current width.
Perhaps an acceptable solution would just be to provide additional classes with alternate widths (or other styles).
For example:
.custom_class {
font-size: 1em;
height: 100px;
width: 80px;
}
.custom_class.wide {
width: 95px;
}
And then in areas where you need the width to be wider, you'd simply create the element like <div class="custom_class wide">
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With