I have a lot of progress bars which I am currently using inline style to set the width. Is there a way for me to utilise data type with LESS or just CSS?
For example:
<div class="progress" aria-valuenow="3"></div>
<div class="progress" aria-valuenow="50"></div>
Can I do something like this in LESS/CSS:
.progress[aria-valuenow=x] {
width: x%;
}
impossible to map a variable attribute value in css. can be done in less using a for loop but the output css would just be a ton of css for every possible value. my suggestion- if youre already applying the value inline using js, just apply that value to a style selector like width or translateX() and style youre progress bars accordingly
<div class="progress" width="x"></div>
.progress {
background: blue;
transition: width 300ms;
}
Related
Say I have this code:
<div style="width:100%" id="a"></div>
<div id="b"></div>
I want the #b's height to equal #a's width and always following that value.
What I can do is to use JS to get #a's width and set it to #b's height.
However, is there any pure CSS way to do so, something like this:
#b {
height:getvalue('#a', 'width');
}
As Sangam Belose said setting both values in css is a valid option.
You could define a variable in :root and access it from everywhere:
root:{
--lenght: 100vw;
}
#a{
width: var(--lenght);
}
#b{
height: var(--lenght);
}
Unfortunally you would need JS to change this variable but most of the time there is a workaround for this like using aspect ratio.
In my AngualrJS application we use angular-ui-bootstrap tooltips.
I have one tooltip that needs to accommodate long text.
The answer to SO question Displaying long text in Bootstrap tooltip shows me how to make tooltips go wider...
... but what if I don't want to make all tooltips wider, just one specific tooltip?
(Notes: AngularJS 1.2.24, jQuery available... but I'd rather just be able to apply a style to that single tooltip than get more complicated)
If on the other hand you have tooltip-append-to-body="true", you can use the following modified version of #Daryn's code
CSS
.tooltip-400max .tooltip-inner {
max-width: 400px;
}
HTML
<div id="element1"
tooltip-append-to-body="true"
tooltip-class="tooltip-400max"
tooltip="{{ model.longTooltip }}">Text</div>
<div>More page content</div>
As long as you don't have tooltip-append-to-body="true", you can use the following CSS (in this example, making the tooltip max width 400px):
CSS
.tooltip-400max + .tooltip .tooltip-inner {
max-width: 400px;
}
HTML
<div id="element1"
class="tooltip-400max"
tooltip="{{ model.longTooltip }}">Text</div>
<div>More page content</div>
The key in the CSS above is the adjacent sibling selector, +.
That's because, as you probably know, when you hover over element1, the tooltip is inserted as a div after element1, approximately like this:
<div id="element1"
class="tooltip-400max"
tooltip="{{ model.longTooltip }}">Text</div>
<div class="tooltip fade in" and other stuff>...</div>
<div>More page content</div>
Thus the CSS selector .tooltip-400max + .tooltip will select only this inserted tooltip, which is an adjacent sibiling. The descendant .tooltip-inner max-width styling will not affect all tooltips, only tooltips for elements with tooltip-400max class.
This would be easier to explain with an example:
I have a div ID that is used many times on my page.
I would like to style only 1 of these div's differently, without changing its name.
Is there a way to style this 1 div, if it is inside another div?
For example, my page contains many of these:
<div id="text2">Some text</div>
And the one I wish to change is:
<div id="container">
<div id="text2">Some different styled text</div>
</div>
Is this possible?
PS. This is all with Wordpress, therefore they are dynamically generated. Adding individual inline CSS with style will not work. This MUST be done in my external CSS sheet.
In your case you could treat the inner div witin a div as a child and as a result you can use this css
#container #text2 {
/* Unique Div Style */
}
It is correct that if you have an element that is being repeated a lot,, you should use a class and not an id.
If you have a lot of
<div id="text2">Some text</div>
then it should really be like this
<div class="text2">Some text</div>
If you do that then your CSS could look like this for that ONE div that you want to style differently
#container .text2 {
/* Unique Div Style */
}
Of course, provided that your container ID is unique ID.
ALSO, if you changed your code and you styled repetitive elements with classes then you could apply multiple classes to the same element..
Like so:
<div class="text2 text2new">Some text</div>
Now you could write CSS for class .text2new
.text2new{
/* make sure your css code overrides the old class*/
}
If it is important to you to have the site display correctly in older browsers multiple classes are not supported btw.
Hope this makes it clearer.
Try:
#container #text2 {
/* YOUR CSS HERE */
}
As commented above, if you want to apply the same style to multiple elements, use class instead of id. Styles could be applied to specific elements following the specified structure, which means in your case, you should be using
#container .text2 {
// styles go here...
}
If however your text2 remains an id, the style would only be applied to the first element with that particular id found.
This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
How do I prevent CSS inheritance?
is there a way to exclude a tag from css class
I have CSS like this
.div1 img {
// ...
}
.myimg {
// ...
}
and my HTML code is like this,
<div class="div1">
...
<img src="..." class="myimg"> // image html
...
</div>
The css formatting defined in .div1 img is obviously applied to the image html code. However, I actually don't want it happen. What can I do to not to have '.div1 img' effects on that image html code? I don't want to modify the content of div1 img or related html code because it is used in other places already (and it is a template code that I don't want to mess with).
P.S. I cannot remove or modify <div class="div1"> either because there is other template code around.
Thanks.
You have two options:
You can explicitly override all of the styling defined in .div1 img with what they should be in .myimg
You can write .div1 img:not(.myimg) for the first rule.
You could do:
.div1 img:not(.myimg) {
// ...
}
:not selector explained here
There is a nice little not selector that would work, but unfortunately it doesn't work in all browsers.
One sure way to do that is redefine all your .div1 styles in your child .mying class so it overrides the parent.
here is a little demo in jsfiddle: http://jsfiddle.net/u6MnN/1/
mess around with it and see what's best for you.
you need to neutralize all those stylings you are giving to ".div1 img" for example if you say "width:100px" there you need to say "width:auto" in the other one.
Although if you have lots of rules in the first set it would be very dirty this way and you need to change your layout.
If you have img tags inside a container div with class .div1 they will of course get the styling you define in .div1 img, but if you want lets say 2 images out of 8 in that div to have another style (which i believe is why you made class .myimg), you need to put !important after the defined stylings in .myimg like so:
.div1 img
{
height: 125px;
width: 125px;
}
.myimg
{
height: 150px !important;
width: 150px !important;
}
This is only if you are NOT using CSS 3.0
Ok here is the site:
http://danberinger.com/
If you view the source for the HTML and CSS you can see that I have set the height of the div in the middle to 100% and given it an overflow property value of hidden, it is called "main_content". I realized that the height value is having no effect on what is displayed, the overflow value of hidden is allowing the background color of the main_content div to extend down to the footer. I guess I am wondering what the best way for me to achieve a variable div height on each page or "main_content" while maintaining the background color. Am I doing this the right way or am I using some kind of css hack that is not the proper way to do it. All insight is welcome. Make sure to take a look at the source HTML and CSS before giving me an answer.
The easiest solution would be to assign the background color to your body element. Something like this:
body {
margin: 0;
padding: 0;
width:100%;
height:100%;
background-color:#cccccc;
}
This will also eliminate the few pixel white border around the edges, if you want to maintain that, take out the margin and padding declarations.
I might have misunderstood what you want, but try this:
Replace div#intro_container with:
div#intro_container {
width:830px;
margin:auto;
overflow: hidden;
background-color:#333333;
}
And remove the height property from div#messagebox.
I prefer to do in this way:
In the content of div 'main-content', add
In your case it was
<div id="main_content">
<div id="navigation">..</div>
<div id="intro_container">..</div>
</div>
It cam be rewritten as
<div id="main_content">
<div id="navigation">..</div>
<div id="intro_container">..</div>
<div style="clear:both"></div>
</div>
AFAIK This is a standard way to achieve what are you doing.