- CSS Layout — The position Property
- The position Property
- position: static;
- Example
- position: relative;
- Example
- position: fixed;
- Example
- position: absolute;
- Example
- position: sticky;
- Example
- Positioning Text In an Image
- How to add static text inside an input form in Html?
- Method 1: Using a Label Element
- Method 2: Using a Span Element
- Method 3: Using a Paragraph Element
- Method 4: Using a Div Element
- Text
- Content properties
- General
- Text string
- Visible boolean
- Animate Loading boolean
- Disable link boolean
- Height string
- Style properties
- General
- Font family string
- Font size string
- Color
- Text Color string
- Text formatting
- Alignment string
- Emphasis String
- Border and shadow
- Border Width number
- Reference properties
- text string
- isVisible boolean
- Methods
- setVisibility (param: boolean): Promise
- setDisabled (param: boolean): Promise
- setRequired (param: boolean): Promise
- setText (param: string): Promise
- setTextColor (param: string): Promise
CSS Layout — The position Property
The position property specifies the type of positioning method used for an element (static, relative, fixed, absolute or sticky).
The position Property
The position property specifies the type of positioning method used for an element.
There are five different position values:
Elements are then positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depending on the position value.
position: static;
HTML elements are positioned static by default.
Static positioned elements are not affected by the top, bottom, left, and right properties.
An element with position: static; is not positioned in any special way; it is always positioned according to the normal flow of the page:
Here is the CSS that is used:
Example
position: relative;
An element with position: relative; is positioned relative to its normal position.
Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. Other content will not be adjusted to fit into any gap left by the element.
Here is the CSS that is used:
Example
position: fixed;
An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element.
A fixed element does not leave a gap in the page where it would normally have been located.
Notice the fixed element in the lower-right corner of the page. Here is the CSS that is used:
Example
position: absolute;
An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed).
However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.
Note: Absolute positioned elements are removed from the normal flow, and can overlap elements.
Here is the CSS that is used:
Example
div.relative <
position: relative;
width: 400px;
height: 200px;
border: 3px solid #73AD21;
>
div.absolute position: absolute;
top: 80px;
right: 0;
width: 200px;
height: 100px;
border: 3px solid #73AD21;
>
position: sticky;
An element with position: sticky; is positioned based on the user’s scroll position.
A sticky element toggles between relative and fixed , depending on the scroll position. It is positioned relative until a given offset position is met in the viewport — then it «sticks» in place (like position:fixed).
Note: Internet Explorer does not support sticky positioning. Safari requires a -webkit- prefix (see example below). You must also specify at least one of top , right , bottom or left for sticky positioning to work.
In this example, the sticky element sticks to the top of the page ( top: 0 ), when you reach its scroll position.
Example
div.sticky <
position: -webkit-sticky; /* Safari */
position: sticky;
top: 0;
background-color: green;
border: 2px solid #4CAF50;
>
Positioning Text In an Image
How to position text over an image:
How to add static text inside an input form in Html?
It is a common requirement to include static text within an input form to provide additional context or instructions for the user. However, simply adding plain text within a form element may not result in the desired appearance or accessibility. In this tutorial, we will explore different methods for adding static text within an input form.
Method 1: Using a Label Element
To add static text inside an input form using a label element, you can use the «for» attribute of the label element to associate it with the input element using the «id» attribute. Then, you can add the static text inside the label element as its content. Here’s an example:
label for="username-input">Username:label> input type="text" id="username-input" name="username">
In this example, the label element has the text «Username:» as its content, and it is associated with the input element using the «for» attribute with a value of «username-input». The input element has an «id» attribute with the same value, which allows the label to be associated with it.
You can also use the label element to wrap the input element, which can make it more accessible for users who use assistive technologies. Here’s an example:
label> Username: input type="text" name="username"> label>
In this example, the label element has the text «Username:» as its content, and it also contains the input element as its child. This allows the label to be associated with the input element implicitly, without the need for the «for» and «id» attributes.
Overall, using a label element to add static text inside an input form is a simple and effective way to improve the accessibility and usability of your forms.
Method 2: Using a Span Element
To add static text inside an input form using a Span Element, follow these steps:
div> input type="text" id="inputField"> span id="staticText">Static textspan> div>
#staticText position: absolute; left: 10px; top: 5px; >
const inputField = document.getElementById("inputField"); const staticText = document.getElementById("staticText"); inputField.style.paddingLeft = staticText.offsetWidth + "px";
- The static text will now appear inside the input field, aligned with the left edge of the input field.
div> input type="text" id="inputField" style="padding-left: 80px;"> span id="staticText">Static textspan> div>
Note: You can adjust the position and styling of the span element and input field using CSS to achieve the desired result.
This is one way to add static text inside an input form using a Span Element.
Method 3: Using a Paragraph Element
To add static text inside an input form using a paragraph element in HTML, follow these steps:
form> label for="username">Username:label> input type="text" id="username" name="username"> form>
- Add a paragraph element after the input element and include the desired static text within the paragraph tags.
form> label for="username">Username:label> input type="text" id="username" name="username"> p>Enter your usernamep> form>
style> p font-size: 14px; color: #999; margin-top: 5px; > style>
script> const input = document.getElementById('username'); const staticText = document.querySelector('p'); input.addEventListener('focus', () => staticText.style.display = 'none'; >); input.addEventListener('blur', () => if (input.value === '') staticText.style.display = 'block'; > >); script>
By following these steps, you can easily add static text inside an input form using a paragraph element in HTML.
Method 4: Using a Div Element
To add static text inside an input form using a div element, you can follow these steps:
- Create a div element with the desired static text inside it.
- Position the div element over the input element using CSS.
- Set the div element to be transparent to mouse clicks so that the input element can still be interacted with.
Here is an example code snippet:
div style="position: relative;"> input type="text" placeholder="Enter your name"> div style="position: absolute; top: 0; left: 0; pointer-events: none;"> Your Name: div> div>
In this example, the div element is positioned absolutely over the input element using position: absolute and top: 0 and left: 0 properties. The pointer-events: none property ensures that the div element is transparent to mouse clicks.
You can customize the styling of the div element to match your design needs.
Text
This page provides information on using the Text widget to display static or dynamic textual information.
Use the Text widget to display dataContent properties
These properties are customizable options present in the property pane of the widget, allowing users to modify the widget according to their preferences.
General
Text string
Sets the text to be displayed. The text remains unchanged until manually updated or edited.
You can dynamically change text by fetching data from queries or JS functions and binding the response to the Text property. For instance, when a row in a Table widget is clicked, the Text widget dynamically displays the specific name associated with that row.
You have the option to use HTML code within the Text property to customize the appearance of the displayed text. Note that the Text field supports only inline CSS. If you need to use external CSS, it is recommended to use the Iframe widget.
p style="color:blue;">Hello World/p>
This code displays the text Hello World in blue color.
Visible boolean
Controls the visibility of the widget. If you turn off this property, the widget is not visible in View Mode. Additionally, you can use JavaScript by clicking on JS next to the Visible property to control the widget’s visibility conditionally.
For example, if you want to make the widget visible only when the user selects «Yes» from a Select widget, you can use the following JavaScript expression:
Select1.selectedOptionValue === "Yes">>
Animate Loading boolean
This property controls whether the widget is displayed with a loading animation. When enabled, the widget shows a skeletal animation during the loading process. Additionally, you can control it through JavaScript by clicking on the JS next to the property.
Disable link boolean
Enabling this option treats any link in the widget as standard text instead of clickable links.
Height string
This property determines how the widget’s height adjusts to changes in its content. There are three available options:
- Fixed: The widget’s height remains as set using drag and resize.
- Auto Height: The widget’s height adjusts dynamically in response to changes in its content.
- Auto Height with limits: Same as Auto height, with a configurable option to set the minimum and maximum number of rows the widget can occupy.
Style properties
Style properties allow you to change the look and feel of the widget.
General
Font family string
Enables you to choose a font for the text, which can also be programmatically manipulated using JavaScript functions.
Font size string
Determines the font size of the text. It accepts CSS font-size values and can also be programmatically modified using JavaScript functions.
Color
Text Color string
Sets the color for the text, and when JS is enabled, you can dynamically modify the text color using JavaScript functions.
Text formatting
Alignment string
Sets the horizontal alignment of the text within the cells.
Emphasis String
Allows you to choose a font style for the widget, including options like bold or italic. When JS is enabled, you can dynamically modify the font style using JavaScript functions.
Border and shadow
Border Width number
Specifies the width of the widget’s border, accepting only numerical values in pixels (px).
Reference properties
Reference properties are properties that are not available in the property pane but can be accessed using the dot operator in other widgets or JavaScript functions. They provide additional information or allow interaction with the widget programmatically. For instance, to get the visibility status, you can use Text1.isVisible .
text string
The text property retrieves the current text value of the widget.
isVisible boolean
Reflects whether the widget is visible or not.
Methods
Widget property setters enable you to modify the values of widget properties at runtime, eliminating the need to manually update properties in the editor.
These methods are asynchronous and return a Promise. You can use the .then() block to ensure execution and sequencing of subsequent lines of code in Appsmith.
setVisibility (param: boolean): Promise
Sets the visibility of the widget.
setDisabled (param: boolean): Promise
Sets the disabled state of the widget.
setRequired (param: boolean): Promise
Sets whether the widget is required or not.
setText (param: string): Promise
Sets the text value of the widget.
setTextColor (param: string): Promise
Sets the selected option of the Select widget.