Remove HTML remove aligment using Java - html

I Have faces a issue with removeing alignment In HTML document.
<html>
<head>
</head>
<body>
<p style="margin-top: 0" align="center">
Hello World
</p>
<p style="margin-top: 0" align="center">
Java World
</p>
</body>
</html>
My Issue is how to remove alignment of first paragraph with out affecting second paragraph . If I use regex it will it will remove alignment of second para also. I really appricite you any comment regarding this issue.

Use the replaceFirst function.

I'd like to show you another way for that. It would be quite simple to use CSS pseudo-class: :first-child. According to your code above:
body p:first-child { text-align: left !important; }
Second thing would be to use JavaScript or any JS library, like jQuery to remove this property from first p element, e.g.:
$(document).ready(function(){
$("p").first().css("text-align","left");
});

Related

I can't make text direction right to left?

I'm trying to add the Arabic language to my paragraphs but it appears from left to right. I tried <HTML lang="ara"> and I tried to do it from .css file, but nothing worked with me.
note I'm using react and I just create the folder without changing anything and the first thing I did is to add the following paragraph.
<p lang="ara" dir='rtl' className='title-field' contentEditable />
the html-tag gets the direction-attribute
<html dir="rtl">
<body>
<p>aligned right</p>
</body>
</html>
You can also style specific elements with the direction property:
direction: rtl;
This seems to work fine, run the code snippet to see
<p lang="ara" dir='rtl' className='title-field'> نص الاختبار</p>

Change TextSize in a container without css. Directly in HTML Document

is there a way to change the TextSize and Textcolor directly in the HTML Document?
It must be this kind of box (same class) because I need the backroundcolor.
Unfortunately it always has the same textsize.
This is the html line:
Welcher Button reagiert schneller?
Picture of HTML element
I know it is probably a very easy solution but I just can't find the solution.
You can not set a font-size via HTML, you can however use CSS inside a HTML document to edit any property like so:
Inside the head > style element (then however it is recommended to use classes [like I did] or ids).
<head>
<style>
.box {
font-size: 32px;
}
</style>
</head>
<body>
<div class="box">
<!-- content -->
</div>
</body>
Or directly inside the specific element's first tag, by adding a style="" attribute.
<div style="font-size: 32px;">
<!-- content -->
</div>
In this example I used a div you can really do this on any element and set the font-size to 32px you can choose any number and even different units.
Simplicius has a good response.
The closest you can get to what you’re asking for (as your question was originally worded) would be something no longer supported in html5
It still works but use at your own risk.
<font size=2 color=red face=Arial>
your text
</font>

I want to add a background image to this edit box, but the CSS is very complicated to me

I need to place a background inside an edit box, but I've tried various CSS code for hours. Nothing works!
I can customise the CSS, but I do not have access to modify the source code.
Here's the source code of the section I am interested in:
<div id="cke_1_contents" class="cke_contents cke reset" role="presentation" style="height: 200px;">
<span id="cke_26" class="cke_voice_label>Press Alt 0 for help</span>
<iframe class="cke_wysiwyg_frame cke_reset" style="width: 100%; height: 100%;" aria-describedby="cke_26" title="Rich Text Editor,form_essay_content" src="" tabindex="0" allowtransparency="true" frameborder="0">
#document
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head></head>
<body class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" spellcheck="false" contenteditable="true">
</body>
</html>
</html>
</iframe>
</div>
What I want to do is to add an image of a postcard in the background. Like so:
I've tried so many combinations of CSS code to add the image. Fail. Fail. Fail. Here's two of them. Please try not to laugh...
<style>
#cke_1_contents.cke_editable .cke_editable_themed .cke_contents_ltr .cke_show_borders {
background-image: URL(http://www.moodurian.com/tornado/images/postcard-mini.jpg);
}
#cke_1_contents body {
background-image: URL(http://www.moodurian.com/tornado/images/postcard-mini.jpg);
}
</style>
Well, it didn't work. Any ideas, anyone? Please note that I cannot modify the source code. So I can't add any additional < div >< /div > tags or < span >< /span > tags. I can only enter custom CSS to modify the page elements.
Thanks for reading this.
Regards
Frankie Kam
Malaysia
It looks like you're trying to add CSS rules that target elements inside the <iframe>, is that correct? If so - you will need to add those CSS rules to a CSS document that the iframe itself loads - CSS rules from the parent document won't affect the iframe content.
I found a relevant question here: CSS override body style for content in iframe?
Have you tried editing the body in CSS? You could try something like
body {background-image: URL(http://www.moodurian.com/tornado/images/postcard-mini.jpg);}
I'm not sure why you're only able to edit the css and not the html. Seems a bit odd. Try this line of code and let me know if it works.

Classes and Ids do not work in Style Tags

For some reason if I try to style elements using classes or ids in Style tags then nothing happens. It works fine if the CSS selector is just looking for a tag and no class or id. It also works fine in an external style sheet. I have tested this in both Chrome and Firefox and unless this is some rule that I have never heard of, then I have no idea what is going on.
Something as simple as this does not even work. The p is coloured blue however the h1.1 does not become red.
<html>
<head>
<style type="text/css">
h1.1 {color:red;}
p {color:blue;}
</style>
</head>
<body>
<h1 class="1">This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Could someone please explain why this is happening? How can style an element using its class in style tags?
Class names must begin with a letter.
That is because you have used 1 as class name – and .1 does not make a valid CSS selector, so it would have to be escaped: http://jsfiddle.net/wJsbj/
See also:
CSS character escape sequences
SO: What characters are valid in CSS class selectors?
check css class name conventions css name conventions
A css class name should be started with alphabet A-Z or a-z .
Class or id name should start with an alphabet.
You can't start the name of class with a number.
Try this:LIVE DEMO
<html>
<head>
<style type="text/css">
h1.a1 {color:red;}
p {color:blue;}
</style>
</head>
<body>
<h1 class="a1">This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
You don't even need the h1 as well. Just write: .a1 {color:red;} With the dot, you are defining a class which you apply in the html to any element you like by including class="a1" in any tag. That's the beauty of classes...you can use them as much as you like providing the html tag you're applying it to makes sense.

Is there an elegant way to make/generate spaces instead of &nbsp?

I need to generate spaces in a HTML file.
Use either &nbsp or <pre> tags. The <pre> tag preserves all spaces, tabs and newlines.
EDIT
Regarding your comment about its use, for padding, you may want to look at css padding
It all depends on the context, you can use letter-spacing, word-spacing or for example padding for surrounding span's.
Without more information it´s impossible to give a good advice.
Edit: if it´s for use in texts / in between words, I´d go for the word-spacing and perhaps letter-spacing.
I hardly ever use
margin and padding properties work well for spacing and <br /> for newlines. (I don't use <br /> too frequently either.)
is a non-breaking space. Alternatively I guess you could use a <br /> (XHTML there) tag just to generate a new line.
i use a span with css classes.
i have several class like spacer_1, spacer_2, spacer_3, etc..
i use different horizontal padding like this
.spacer_1
{
padding:0px 5px;
}
to use this spacer you can use the following
<span class="spacer_1" /> /*this will generate half the gap*/
<span class="spacer_1"></span>
<span class="spacer_1">|</span>
just do:
/* in your css code: */
pre
{
display:inline;
}
<!-- and then, in your HTML markup: -->
<pre> this text comes after 4 spaces.</pre>
<span> continue the line with other element without braking </span>
Yacoby is right. But i have something different:
<head>
<style type="text/css">
.left-space { margin-left: 10px; }
</style>
</head>
<body>
<div>
<p>This is a test line.<span class="left-space">This is a line with space before it.</span></p>
</div>
</body>
And by the way you should replace with   to conform to XHTML.