Styling ASP.Net forms with CSS - asp.net

I'm transitioning a website from plain html to ASP.Net.
I have two forms in the website frmRegister and frmLogin
I have css for the each of these like this...
form#frmRegister .floatRight input{
width: 100%;
font-family: Arial, Helvetica, sans-serif;
font-size: 0.9em;
border: 1px solid #a1d19d;
font-weight: normal;
}
form#frmRegister .textRow input, form#frmRegister .textRow textarea, form#frmLogin .textRow input, form#frmLogin .textRow textarea, form#frmRegister .textRow select{
width: 90%;
font-family: Arial, Helvetica, sans-serif;
font-size: 0.9em;
border: 1px solid #a1d19d;
}
but because asp renames the forms to aspNetform, the styles are not applied.
I tried adding aspNetform to the css but then every form gets given the same style.
I'm using master pages btw.

Don't style your CSS by ID. Use CSS classes instead.
<form id="myForm" runat="Server" class="someClass">
in css:
.someClass {background-color: blue; color:red; }
Although technically, I've never applied css to a form, so I'm not 100% sure the above will work. If I need to do that, I nest a div within the form, and apply the style to the div. So I'd change
<form id="myForm" runat="Server" class="someClass">
...
</form>
to
<form id="myForm" runat="Server" >
<div class="someClass">
...
</div>
</form>

Try giving the style based on the class name, instead of the ID.

I don't work with web forms, so there may be a better solution, but you could just address your forms via CSS classes rather than ids.
E.g., add a class frmRegister to that form tag, and then address it in CSS like this:
form.frmRegister .floatRight input{ width: 100%;
....

Have you tried the ClientID property of your controls?
Also on your css you can do something like:
form#<%=myControl.ClientID%>{
/* css in here */
}

Yes, forms represent a special element in a webforms app. Better to just define a class and apply that to your form, or even putting a div within the form and styling that.
Also, one big advantage over regular HTML is that you can stick all this in a master page. This way, you can tweak your overall page layout only in one place (the master page) and have those changes reflected on every page.

Are you embedding the styles in the pages/master page or is it in an external file? If you add the styles to the master page it will affect all of its child pages.

Related

CSS Master Styling Clarification

I have seen conflicting information about how to use a master style sheet and have experienced some bugs when testing methods. Just want to get clarification on the proper way to do this.
I would like to store cross website branding styles in a master global.css sheet and make page specific adjustments on a second .css file.
For example, this code would live on the master sheet:
#headline1{
font-family: 'Roboto', sans-serif;
font-size: 96px;
letter-spacing: -1.5px;
}
and this code would be page specific:
.headline {
color: #FFFFFF;
text-align: center;
}
I have recently read something that said you should not use ID in this manner. I've also run into issues when using it multiple times in the same grouping. I initially tried doing this using just classes instead of the ID, but it never worked. Not sure why.
Is this method considered proper? If not what is the proper way to do this?
If you create a master.css with:
.headline {
font-family: 'Roboto', sans-serif;
font-size: 96px;
color:#000
letter-spacing: -1.5px;
}
You can build upon/replace it per page as long as your custom css comes after the master.css
.headline {
font-size: 45px;
color: #FFFFFF;
text-align: center;
}
Quick example of a page:
<link rel="stylesheet" type="text/css" href="master.css"/>
<style>
.headline { //
font-size: 120px; // size overides master
color: #FF0000; // color overides master
text-align: right; // added alignment, which is overiding the browsers base css
}
</style>
I'm not sure if this is quite what you are looking for, but I hope it helps
In the example you provided a can only assume you have something along the lines of:
<div id="headline1"><span class="headline">Title</span></div>
This would basically mean any style applied to the div, the span would inherit unless told otherwise.
To further expand on this, you can also use inline styles <span style="color:#FFF"> which will dominate any other styling UNLESS an !important; has been added to a style element.

How to remove heading styles with an inline CSS code

I have a question about CSS, i don't know how to remove​styles of a class with an inline CSS code.
Let me explain more,
I have a CSS file named styles.css
In this file for example my h2 has some styles, now in my article i want to use h2 but i want to remove h2's default styles(written in styles.css) for this heading.
I guess there should be a way for this case, but i don't know how?
Please tell me this css code and teach me something new.
Thanks
Edit:
Please take a look to bellow picture. As you can see this h2 has some styles, can you see the pink vertical line in right side?
Now i want to remove this h2's styles with a css code. I guess something like my heading here should exist in CSS3. Am i right? Is there any css code for removing external css styles with an inline css code?
https://preview.ibb.co/m4BLda/Screenshot_2017_09_04_01_44_09_1.png
Here is the code:
h2 {
border-right: 4px solid #E20070;
font-size: 22px;
margin: 1.5em 0;
padding-right: 1em;
font-family: "Yekan",'irans',tahoma;
font-weight: normal !important;
}
You said inline, but you should really keep your styles in a separate stylesheet file. Now, in your styles.css file add your own class:
/* styles.css */
h2 {
font-size: 18px;
}
.my-other-title {
color: red;
border-right: 0;
}
<h2>My title</h2>
<h2 class="my-other-title">My other title</h2>
Why does this even work? Because of CSS specificity:
Specificity determines, which CSS rule is applied by the browsers
Take your time learning more by reading this article
Remove the existing class for your heading if there is and use your own custom class instead of writing everything inline.
h1{
font-size:15px;
color:blue;
}
/* target your h1 element */
.custom-css{
font-size:25px;
color:red;
}
<h1>Heading with general css<h1>
<h1 class="custom-css">Heading with custom css</h1>
Although its not good to change the semantic of an HTML Element.
CSS - Default for h2 (from external css source)
h2 {
border-right: 4px solid #E20070;
font-size: 22px;
margin: 1.5em 0;
padding-right: 1em;
font-family: "Yekan",'irans',tahoma;
font-weight: normal !important;
}
You want to override the default css through inline css. Try using below code for your h2.
<h2 style="border-right: 0px; padding: 0; margin: 0;"> Hello </h2>
You can also add a class to the h2 and call the class to your stylesheet if this style is applied to most of the h2 tags. Try to avoid inline css if possible, it may cause loading time.
<h2 style="color:white; font-size:80px"> My Cool Text </h2>
You have to write what you want to replace, for example, I changed color here.

Xpages using Dojo elements

I am confused about applying CSS to some dojo elements in my Xpage.
I have a CSS style sheet with the following in it:
.formFields {
color: rgb(5, 56, 107);
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-style: normal;
font-variant: normal;
font-weight: normal;
height: 18px;
text-align: left;
width: 400px;
}
I have a sample test page with the following code:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:this.resources>
<xp:styleSheet href="/custom.css" />
</xp:this.resources>
<xe:firebugLite id="firebugLite1" />
<xe:djTextBox id="LocNum" styleClass="formFields" value="#{document1.locNum}" />
<xp:br />
<xp:br />
<xp:inputText id="inputText1" styleClass="formFields" />
</xp:view>
When I run this and look at Firebug, I noticed that my CSS was not being applied. For dojo elements this appears to be applied:
.dijitReset {
-moz-font-feature-settings:inherit;
-moz-font-language-override:inherit;
border:0 none;
color:inherit;
font-family:inherit;
font-size:**24px;**
font-size-adjust:inherit;
font-stretch:inherit;
font-style:inherit;
font-variant:inherit;
font-weight:inherit;
line-height:normal;
margin:0;
padding:0;
}
I confirmed this by changing the font size.
I want to be able to have all my input fields look the same. Some of the fields have a blue color and some have a black color. I also want to have them look the same when in edit mode, and the same in read mode. That way the user can tell what mode they are in.
What the heck is going on here? I find CSS so darn hard at times.
Bryan
I believe your issue is less of a direct CSS problem and more a combination issue with how XPages builds out the dijit element (the xe:djTextBox) and where it applies the CSS style you've defined with the fact that you're attempting to use CSS solely from an external file. What's happening is that it is applying your formFields class, but to the root element it generates, a div. The input that the user actually types into is nested two elements in, inside of yet another div.
To account for this, I would recommend adjusting your CSS to be defined within the XPage, in a <style type="text/css> tag, which would, by nature of CSS inheriting from the "bottom up", take priority over the styles you're being given via XPages and Dojo.
Inheritance of CSS:
inline styles take precedence (style="...")
page styles (defined in a tag, like I'm describing)
external style sheets (defined with <link rel="stylesheet"...>)
You might be able to get it to apply with your externally defined styles, you may wish to try changing your definition for .formFields to .formFields, .formFields input and throwing in some !important flags to the ends of your property lines. This will make it apply to inputs underneath elements with the formFields class.
Here's an example with in-page defined styles:

How to customize css style in facebook guestbook plugin (html5 version)?

When the page is loaded, I can see the huge css code generated by facebook plugin (HTML5) with specific tools like Firebug and I can change it. But how can I change the style without using Firebug?
I tried to overwrite the classes in my css code, but my code is ignored by the plugin.
If by guestbook you mean facebook comments the trick is to wrap it in a div like so:
<div id="comments">
<fb:comments xid="XXXXXXXXXXXXXXX" numposts="15"></fb:comments>
</div>
Then in your css you can do
#comments {
width: 100%;
float: left;
font-family: Arial, Helvetica, sans-serif;
color: #ff6600;
}
#comments a { color: #ff6600; }
And so forth, for full styling information this link should help you
http://www.daddydesign.com/wordpress/how-to-customize-the-facebook-comments-social-plugin-on-a-static-fbml-tab/

Form element messes up imported HTML/CSS layout template in ASP.NET

I want to use this pure HTML/CSS template for my ASP.NET website:
http://sub3.tanguay.de
I copy it inside my Default.aspx page, inside the FORM element, but the form messes up the layout:
http://sub2.tanguay.de
UPDATE: this now displays correctly, thanks to Devio.
I tried altering the style of the form tag but can't get it to stop affecting the layout, I tried:
style="margin: 0px; padding: 0px; display: inline; background-color: transparent;"
Is this a common issue when copying in layout templates into ASP.NET?
Is there an easy work around, like some margin:-2px fix or something like that?
I need to keep the form tag, of course, for the ASP.NET functionality.
I had the same issue and changing the form element to the following fixed things:
<form id="form1" runat="server" style="display: inline; background-color: transparent;">
1) try removing the background-color attribute from the form class:
form {
margin:10px; padding: 0;
border: 1px solid #f2f2f2;
background-color: #FAFAFA; /* remove this */
}
2) you cannot nest forms, but the searchform is contained inside the ASP.Net form, and ASP.Net requires exactly one form tag per page.

Resources