how do I control width of a dojo combobox using css, i tried #comboId{width:50px} where comboId is the Id of <select id="comboId">. but it does not work
ComboBox is a little tricky, because the way this widget works, the node with the id comboId will end up being the inner input node inside the widget, not the widget's top-level domNode (which receives the id widget_comboId instead). This is probably why that's having no effect for you.
Note that not nearly all widgets do funny things like this, but namely widgets like dijit.form.TextBox and dijit.form.ComboBox (and widgets that extend them) do.
Perhaps the simplest way around this would be to also add a class to your widget and style based on that instead (which is generally encouraged as it is more reusable than coupling specific IDs into your css anyway). Assuming you're instantiating declaratively:
<select id="comboId" class="comboClass" dojoType="dijit.form.ComboBox">
...
</select>
Then in your css:
.comboClass { width: 50px; }
Other solutions
If you're instantiating this widget declaratively, you can apply the style inline and it will become properly mapped to the widget's domNode automatically:
<select id="comboId" dojoType="dijit.form.ComboBox" style="width: 50px">
...
</select>
Alternatively, you can set the style attribute of the widget after it is instantiated:
dijit.byId('comboId').set('style', {width: '50px'});
This is programmatically the equivalent to setting the width style inline on the DOM node declaratively.
Setting width using css did not work for me. However, setting style at construction did:
var spatialQueryComboBox = new ComboBox({
id: "selectionType",
style:{width: "100px"},
store: spatialSelectionStore,
searchAttr: "name"
}, "spatialSelectionType");
Did you try:
dojo.style("comboId", "width", "50px");
It could be done by calling the function "forceWidth(true)", and define the class .mblComboBoxMenu with desired height in your css file.
for example:
.mblComboBoxMenu {
position: relative;
overflow-y: hidden !important;
overflow: hidden;
border: 1px solid #00677f;
border-radius: 0;
background-color: white;
color: #868e96;
width: 80% !important;
}
Related
I have created a textarea element with a maximum character limit. When the limit is reached, it should display an error message. I am using a pre-existing component called lib-error-alert-message. This is how the HTML code looks like -
<textarea class="my-text" rows="10" maxlength="500" [formControl]="textControl"> </textarea>
<lib-error-alert-message class="alert" *ngIf="(text | async) == 50" [alertMsg]="limitAlertMessage">
</lib-error-alert-message>
I have used this component elsewhere and it is working fine, however, in this particular page, the component has an internal class named "msgs" which has a margin-left property of -3rem.
This is causing the error alert and the textarea orientation to be askew.
While inspecting the element, if I uncheck the margin-left property then it looks correct.
I tried to create a class "alert" for the lib-error-alert-message and used the following code for that -
.alert {
margin-left: 0 !important;
width: fit-content;
}
But this does not override the inherent margin-left property for the internal class "msgs". How would I change the property for the internal class "msgs" (which is not accessible to me) in order to serve my purpose?
Add this style to your global styles.scss file. It selects the div with class msgs inside lib-error-alert-message element:
lib-error-alert-message div.msgs {
margin-left: 0 !important;
width: fit-content;
}
It’s right that you don't have direct access to the library component, but good news is that the global styles.scss is applied to all dom elements.
Use the Angular deep selector - it can be used to target inner component of external libs
:host ::ng-deep {
lib-error-alert-message div.msgs {
margin-left: 0;
width: fit-content;
}
}
I have Asp.net Core 5.0.1 app with multiple MVC views. I also have a CSS file, generated by an app. I want this file to be unmodified (as it will be changed in future using same app). I want separate CSS file, which styles certain elements (eg input or button) to be styled using classes from the generated CSS. I dont want to write class on each input or button etc element (there are 35 views needs to be styled).
For example if generated file has class dx-theme-text-color I want a CSS file which has something like input { color:.dx-theme-text-color}
How can I achieve this?
To clarify: the question is - how to use a class from one CSS in another by name not copy/pasting values etc
I can only think of #extend from SASS:
.dx-theme-text-color {
border: 1px solid red;
}
input, button {
#extend .dx-theme-text-color;
}
You can use css variables.
define css variavles in global scope:
:root {
--my-custom-color: #000;
}
use variables in every css file like this:
.my-element {
color: var(--my-costum-color)
}
You can also use css pre-proccesors like sass(scss), less and etc.
I am working on my first web dev project, with someone, and I am responsible for the front-end part. In my personal projects I've been using plain css, but in this template I have seen that they are using something else, a different structure, I think. I kind of figure it out how it works, but because I never crossed paths with it before, it makes developing hard for me. I would like to know what it is so I can read some documentation and understand it better. (as an example: usually ,when I use className, I put the class name between "", but here is like css.something) Can you tell me what it is ? I will leave a snippet here
.menuItem {
#apply --marketplaceListingAttributeFontStyles;
color: var(--matterColor);
/* Layout */
position: relative;
min-width: 300px;
margin: 0;
padding: 4px 30px;
display: flex;
align-items: center;
justify-content: center;
/* Override button styles */
outline: none;
text-align: left;
border: none;
white-space: nowrap;
cursor: pointer;
&:focus,
&:hover {
color: var(--matterColorDark);
}
&:hover .menuItemBorder {
width: 6px;
}
}
<button className={css.menuItem} onClick={()=> this.selectOption(queryParamName, option.key, dates)}>
This is CSS Modules and you can read more about this usage of CSS in these 2 links:
link1
link2
Although I'm not overly familiar with React, this (className={css.menuItem}) is some sort of model binding so that when React has done it's thing it will bind the value of css.menuItem to the rendered HTML probably ending up with something like
<button className=".menuItem" ...>
The Javascript format you see there is a view binding, or something we might describe as a Domain Specific Language (DSL). It is Javascript used by some framework (likely React or another frontend framework) to build the HTML you see on the page. I can't be certain since I don't know what framework I'm looking at, but I'm willing to bet that if you use the "inspect" feature in your browser, you will see this in the resulting HTML that is created by that Javascript:
<button class="menuItem" onClick="[...]">
This format should look familiar to you if you are expecting plain HTML. That Javascript you linked to just builds this HTML dynamically. In the example you provided, the curly braces ({ }) are just an indicator to the Javascript library that it need to fill in that placeholder with something, in this case css.menuItem, which translates to a class name of menuItem rendered into a css class tag (class="menuItem").
Have you looked into what that css object holds?
From what I can see, the #apply puts the css part to be in pre-compiled language like SASS or SCSS.
You have not mentioned if it is ReactJS. If it is then there is a high possibility that whatever you are dealing with is in JSS.
In my Angular application, I have components pages like <app-page-home>, <app-page-login>, <app-page-documentation>, etc. that are mounted when required in my <router-outlet>.
I am trying to target all these components together from a global stylesheet (./src/styles.styl that applies everywhere in the application), but CSS doesn't seem to accept wildcards for custom tags.
I would like to avoid listing my tags one by one and instead, something like app-page-* { border : blue solid 1px; }
app-page-* {
border : blue solid 1px;
}
<app-page-login>Login stuff</app-page-login>
<br>
<app-page-documentation>Documentation</app-page-documentation>
I can't add classes (or can I?) because these component are being dynamically mounted by the router, otherwise I could obviously use something like class="page".
Any idea how to target custom tags with a wild card? Thanks
That's correct, css doesn't have partial type wildcards. Most easy solution is to just group them together, like this;
app-page-login, app-page-documentation { border: 1px solid blue; }
Or apply a class to them;
<app-page-login class="app-page" />
<app-page-documentation class="app-page" />
and target the class;
.app-page { border: 1px solid blue; }
You could do fancy stuff with attribute selectors, but imo for your use case the two solutions above are the most suitable.
-- edit; I see you can't add classes. Use the first solution then.
I have a table that i want to "highlight" during onmouseover/onmouseout. I already know this is required in IE but not in other browsers.
I have managed to detect the events triggering and this TR tag effectively works. (Note that the originating class "contentTableRow" doesn't seem to be causing any issues.)
class="contentTableRow" onclick="openForm('SomeID');" onmouseover="highlight('someRowID', true);" onmouseout="highlight('someRowID', false);" id="someRowID"
All is fine and dandy, the "highlight" function fires and actually sets the appropriate class.
It's just that IE won't process the CSS class name change.
Here is a snippet of the CSS I am using to make the change.
.HighlightOn {
cursor:pointer;
background-color: #D1DFFF;
}
.HighlightOff {
background-color: #E1EEFE;
}
I can see that the Class names are getting updated when I debug it, and also check it in Firebug. But it seems that IE doesn't like this usage of classes with a TR tag.. Is it the way I am structuring the class for Tables ? Any advice ?
Are you changing class instead of className? class is reserved in Javascript as the actual class declaration keyword, so the property is called className:
function highlight(id, b) {
document.getElementById(id).className = (b ? "HighlightOn" : "HighlightOff");
}
Incidentally, you might just want to pass "this" to highlight instead of the id, so it doesn't need to do the document.getElementById() call
Thanks for all the pointers. But this seems to have worked.
TR.HighlightOn td {
cursor:pointer;
background-color: #D1DFFF;
}
TR.HighlightOff td {
cursor:pointer;
background-color: #E1EEFE;
}
Basically have to be explicit in this case about where the class is used in the HTML.
Note that I had to reference the TR tag and the TD tags relative to where I am using the Highlighton/off classes in the table. Thanks jensgram.
Hope this helps anyone else with the same problem.
(thanks Jensgram for the lead)
IE won't recognize "class" in JavaScript. You must use "className" as the property in IE.