Found 1566 Articles for CSS

How to auto-resize an image to fit a div container using CSS?

AmitDiwan
Updated on 16-Nov-2023 14:01:01

3K+ Views

On a web page if you want to auto-resize an image to fit a div, you need to work around tne heigh, width, max-width and max-height properties. To auto-resize an image to fit a div container, we have set the following CSS properties on the img tag − max-width: 100%; max-height: 100%; Set an Image First, we have set an image using the img tag in the div mydiv − Style the Container Height and Width We have set the mydiv with height and width auto to allow auto-resize the div. If height: auto; the element will automatically adjust its height to allow ... Read More

Center image using text-align center with CSS

AmitDiwan
Updated on 30-Oct-2023 14:31:57

2K+ Views

The text-align center is generally used to center text of an element. However, we can also center an image using the same text-align property. First, let us see how to center align a text, then we will center an image using the text-align. Additionally, we will also align an image horizontally and vertically as well. Center a Text Using the Text-align Property in CSS Let us first see how to center a heading using the text-align property − h1 { text-align: center; } Example Let us now see the example to center a text on ... Read More

How to display the file format of links using CSS?

Riya Kumari
Updated on 04-Apr-2023 10:40:38

283 Views

While browsing through a web page, you come across various documents which can be downloaded. Sometimes, you need to download a document but in different file format. However, you may have a problem in finding the document of your desired file format because there are various links each containing different file formats. It can be .docx, .png, .txt, .pdf etc.; Generally, file formats are not specified along with the links. So, we cannot know the type of file format just by looking the links. To solve the problem, you need to display the file format of the downloading links. In ... Read More

Difference between CSS Grid and Bootstrap

Pradeep Kumar
Updated on 21-Jul-2022 12:06:20

1K+ Views

The majority of the time, we will use CSS Grid in situations where we have strict requirements for the layout and want our content to flow on the page in accordance with those requirements.Bootstrap's grid system is based on the CSS Flexbox layout system, while the CSS Grid was influenced by print-based id. Bootstrap is a direct competitor to CSS Grid, and a significant comparison can be made between the two frameworks' respective grid layout systems.If we want to have control over the layout in either the row or column direction, then we should use the Flexbox-based grid that Bootstrap ... Read More

How to use CSS selector as a locator in Selenium?

Debomita Bhattacharjee
Updated on 08-Feb-2022 10:59:14

977 Views

We can locate elements with locator CSS Selector in Selenium webdriver. The general expression to create a CSS expression is tagname[attribute='value']. We can utilize the id and class attributes to create a CSS.With id, the syntax of a CSS expression is tagname#id. For instance, for a CSS expression - input#txt-loc, input is the tagname and the txt-loc is the value of the id attribute.With class name, the syntax of a CSS expression is tagname.class. For instance, for a CSS expression - input.txt-cls, input is the tagname and the txt-cls is the value of the class attribute.If there are n sub-elements(children) ... Read More

Difference Between HTML and CSS

AmitDiwan
Updated on 01-Nov-2023 15:45:41

599 Views

In this post, we will understand the difference between HTML and CSS HTML HTML refers to Hyper Text Markup Language. It helps create web pages and applications − It helps define structure of web page. It is a markup language. It helps create static pages as well. It helps display data. HyperText helps define link between multiple web pages. Markup Language helps define text document using tags, which gives a structure to the web page. It has less backup and support options. HTML can’t be used inside a CSS sheet. It helps annotate the text so that a system ... Read More

Revealing Hidden Elements by CSS Animations

AmitDiwan
Updated on 26-Dec-2023 15:39:04

747 Views

CSS animations allow us to display hidden elements. The elements can be set hidden using the opacity. Set the opacity to the value 0 and the element will hide. To display it, set the transition property with the opacity and also set the transition duration to make it look like fade in effect. Set the container The container div is set. Within that, set two child divs − Hide a child div A child div is set with the opacity value 0 to make it invisible when the ... Read More

How to Add CSS Rules to a Stylesheet with JavaScript?

AmitDiwan
Updated on 15-Nov-2023 14:10:30

323 Views

The insertRule() helps us add a rule at a defined position in the stylesheet while deleteRule() deletes a specific style on a web page. The following examples illustrate CSS rules that can be added to a stylesheet using JavaScript. Insert a Rule To insert a rule at a defined position, use the insertRule() method. The margin, padding, and box-shadow is also set. First, the custom id is set using the getElementById() − let newSheet = document.getElementById('custom').sheet let cs = 'p {'; cs += 'margin: 4%;'; cs += 'padding: 2%;'; cs += 'font-size: 22px;'; cs += 'box-shadow: ... Read More

Understanding clientHeight, offsetHeight & scrollHeight Properties in CSS

AmitDiwan
Updated on 02-Jan-2024 17:55:31

1K+ Views

To return the height of an element, scrollable height, height including padding, border and scrollbar, then use these properties; clientHeight − The clientHeight gives the measure of the height of an element including the padding. Note that border, margin, and scrollbar height (if rendered) are not included in this. offsetHeight − The offsetHeight gives the measure of the height of an element including the vertical padding, top and bottom borders. Margin is not including here. scrollHeight − scrollHeight gives the measure of the height of an element including the vertical padding and the content which is not visible on ... Read More

Auto Grow a Textarea with JavaScript in CSS

AmitDiwan
Updated on 27-Oct-2023 14:38:37

374 Views

Using JavaScript, we can set our TextArea element to automatically grow with its content. The following examples illustrate how we can achieve the above scenario. Let us say the following is our TextArea before adding content − The following is the TextArea after adding content − The following is the same TextArea that auto grows itself after adding more content − Auto Grow a Textarea Example Let us see how to auto grow a textarea − * { ... Read More

Advertisements