CSS: Position and Visibility

CSS: Position and Visibility

osition: {position: normal/relative/absolute}
The position property lets you set a box’s position in the layout of a page.

The default value is normal; the box’s position is calculated according to other boxes. Relative lets you specify the box’s position in the layout relative to its default position, so other boxes still affect its final position. Absolute lets you specify the box’s precise position in the layout according to the box’s containing block, so other boxes cannot affect its position.

The position property allows a Web browser to process the top and left properties. Some browsers skip the top and left properties if the boxes have the default position value. To make sure that the browser processes the top and left properties, the position value of the boxes must be set to relative.

Left: {left: XXunits/%}
The left property lets you set the distance between the element box and the left edge of the containing block.

Positive values move an element to the right and negative values move an element to the left. The default value should be 0 if the left property is not used so the element is directly aligned with the left edge of the containing block. Remember that different browsers have different default values for different elements, so it is best not to assume anything.

You can specify values for the left property in either absolute or relative units. A relative unit calculates the distance from the edge of the containing block using the width of the containing block.

Some web browsers will skip the left property if the box has the default position value. Set the position value of the box to relative to make sure that the left property is processed.

Example:

	img {position: relative;		 left: 3in}

logo

If you are using a CSS-enabled browser, the Project Cool logo appears 3 inches from the left edge of the browser window.

	img {position: relative;		 left: 25%}

logo

If you are using a CSS-enabled browser, the Project Cool logo appears one quarter of the way across the browser window.

Top: {top: XXunits/%}
The top property lets you set the distance between the element box and the top edge of the containing block.

Positive values move an element down and negative values move an element up. The default value should be 0 is the left property is not used so that the element is directly aligned with the top edge of the containing block. Remember that different browsers have different default values for different elements, so it is best not to assume anything and to test everything.

You can specify values for the top property in either absolute or relative units. A relative unit calculates the distance from the edge of the containing block using the height of the containing block.

Some Web browsers will skip the top property if the box has the default position value. To make sure the top property is processed, set the position value of the box to relative.

Example:

	img {position: relative;		 top: 100px}

If you are using a CSS-enabled browser, the Project Cool logo appears 100 pixels below the top of thisbrowser window.

	img {position: relative;		 top: 50%}

If you are using a CSS-enabled browser, the Project Cool logo appears half-way down this browser window.

Display: {display: none/””/block/inline/list-item}
The display property’s most practical function is to hide or show an element. This function is often used in Dynamic HTML to hide and display elements based on the user’s actions. (See Hide and Zeek).

The value none prevents the contents of an element from being displayed by telling the computer to ignore the element. Unlike the visibility property where invisible boxesare still generated and still affect the layout, {display: none} prevents the box from being generated at all, so the element’s box does not affect the layout. “” is the null command; it shows a box that was previously hidden.

The display property also lets you define what kind of object an element is; this function is not used often. Elements can belong to three categories: block, in-line (inline), and list-item. A block element is usually a heading, paragraph, or another element that is displayed as a unit. An in-line element is located inside a block. A list-item element is an item located within a list tag.

Example:

If you are using a CSS-enabled browser, click on “Display” below to see the different values for the display property.

  • none
  • “”
  • block
  • inline
  • list-item

Click again to make the list disappear. Notice how the layout changes as the list appears and disappears.

This is part of the code that was used for the above function:

	{ 	target = document.all( targetId );  		if (target.style.display == "none")  		{ 			target.style.display = "";  		}   		else   		{  			target.style.display = "none";  		}  	}	

For more explanation, see Hide and Zeek.

Visibility: {visibility: visible/hidden}
The visibility property lets you control the visibility of an element’s box;it is often used to display only one of many overlapping elements.

Visible makes a box visible, and hidden makes a box invisible. The layout of a document is still affected by an invisible box as though it were visible. A hidden box is rendered transparently and takes up space. In contrast, the display property prevents a box from being generated at all, so the element’s box does not affect the layout and does not take up space.

Example:

	img {visibility: hidden}

logo

If you are using a CSS-enabled browser, the above Project Cool logo is not visible, but it still takes up space in this page’s layout because the image’s box is being generated.

	img {visibility: visible}

logo

If you are using a CSS-enabled browser, you can now see the Project Cool logo.

Z-index: {z-index: XX}
The z-index property lets you set the stacking order of positionable elements. The boxesof elements can be stacked like pancakes. An element’s z-index value determines if it appears in front or back of another element.

Z-index values are integers that place elements on specific stack levels relative to their siblings and parent elements. Elements can have the same z-index value and be placed on the same stack level. Using the z-index, sibling boxes are stacked by increasing z-index value from bottom to top. Although parent elements may have any z-index value, within their own z-orders they have a z-index value of 0. Children elements with negative z-index values generate boxes below their parent element, and children elements with positive z-index values generate boxes above their parent element.

If the z-index property is not used, the stack level of an element is determined by default by the element’s position in the object hierarchy. Elements are stacked from bottom to top in the order they appear in the document tree, so an element is placed directly in front of its parent element.

The z-index property is useful when two elements occupy the same space and you need to specify which one should be visible. By default, if an element with transparent areas is stacked above another, it allows the element below it to be visible through its transparent areas.

Example:

These three elements are to occupy the same area on a Web page:

  • img.window window
  • img.logo logo
  • h1

    The z-index property.

Here are three different ways they could be stacked:

	img.window {z-index: 1}	img.logo {z-index: 2}	h1 {z-index: 3}	

If you are using a CSS-enabled browser, see what the above code would look like here.

	img.window {z-index:3}	img.logo {z-index: 1}	h1 {z-index: 2}	

If you are using a CSS-enabled browser, see what the above code would look like here.

	img.window {z-index: 2}	img.logo {z-index: 3}	h1 {z-index: 1}	

If you are using a CSS-enabled browser, see what the above code would look like here.

devx-admin

devx-admin

Share the Post:
AI Girlfriend Craze

AI Girlfriend Craze Threatens Relationships

The surge in virtual AI girlfriends’ popularity is playing a role in the escalating issue of loneliness among young males, and this could have serious

AIOps Innovations

Senser is Changing AIOps

Senser, an AIOps platform based in Tel Aviv, has introduced its groundbreaking AI-powered observability solution to support developers and operations teams in promptly pinpointing the

Malyasian Networks

Malaysia’s Dual 5G Network Growth

On Wednesday, Malaysia’s Prime Minister Anwar Ibrahim announced the country’s plan to implement a dual 5G network strategy. This move is designed to achieve a

Advanced Drones Race

Pentagon’s Bold Race for Advanced Drones

The Pentagon has recently unveiled its ambitious strategy to acquire thousands of sophisticated drones within the next two years. This decision comes in response to

Important Updates

You Need to See the New Microsoft Updates

Microsoft has recently announced a series of new features and updates across their applications, including Outlook, Microsoft Teams, and SharePoint. These new developments are centered

AI Girlfriend Craze

AI Girlfriend Craze Threatens Relationships

The surge in virtual AI girlfriends’ popularity is playing a role in the escalating issue of loneliness among young males, and this could have serious repercussions for America’s future. A

AIOps Innovations

Senser is Changing AIOps

Senser, an AIOps platform based in Tel Aviv, has introduced its groundbreaking AI-powered observability solution to support developers and operations teams in promptly pinpointing the root causes of service disruptions

Bebop Charging Stations

Check Out The New Bebob Battery Charging Stations

Bebob has introduced new 4- and 8-channel battery charging stations primarily aimed at rental companies, providing a convenient solution for clients with a large quantity of batteries. These wall-mountable and

Malyasian Networks

Malaysia’s Dual 5G Network Growth

On Wednesday, Malaysia’s Prime Minister Anwar Ibrahim announced the country’s plan to implement a dual 5G network strategy. This move is designed to achieve a more equitable incorporation of both

Advanced Drones Race

Pentagon’s Bold Race for Advanced Drones

The Pentagon has recently unveiled its ambitious strategy to acquire thousands of sophisticated drones within the next two years. This decision comes in response to Russia’s rapid utilization of airborne

Important Updates

You Need to See the New Microsoft Updates

Microsoft has recently announced a series of new features and updates across their applications, including Outlook, Microsoft Teams, and SharePoint. These new developments are centered around improving user experience, streamlining

Price Wars

Inside Hyundai and Kia’s Price Wars

South Korean automakers Hyundai and Kia are cutting the prices on a number of their electric vehicles (EVs) in response to growing price competition within the South Korean market. Many

Solar Frenzy Surprises

Solar Subsidy in Germany Causes Frenzy

In a shocking turn of events, the German national KfW bank was forced to discontinue its home solar power subsidy program for charging electric vehicles (EVs) after just one day,

Electric Spare

Electric Cars Ditch Spare Tires for Efficiency

Ira Newlander from West Los Angeles is thinking about trading in his old Ford Explorer for a contemporary hybrid or electric vehicle. However, he has observed that the majority of

Solar Geoengineering Impacts

Unraveling Solar Geoengineering’s Hidden Impacts

As we continue to face the repercussions of climate change, scientists and experts seek innovative ways to mitigate its impacts. Solar geoengineering (SG), a technique involving the distribution of aerosols

Razer Discount

Unbelievable Razer Blade 17 Discount

On September 24, 2023, it was reported that Razer, a popular brand in the premium gaming laptop industry, is offering an exceptional deal on their Razer Blade 17 model. Typically

Innovation Ignition

New Fintech Innovation Ignites Change

The fintech sector continues to attract substantial interest, as demonstrated by a dedicated fintech stage at a recent event featuring panel discussions and informal conversations with industry professionals. The gathering,

Import Easing

Easing Import Rules for Big Tech

India has chosen to ease its proposed restrictions on imports of laptops, tablets, and other IT hardware, allowing manufacturers like Apple Inc., HP Inc., and Dell Technologies Inc. more time

Semiconductor Stock Plummet

Dramatic Downturn in Semiconductor Stocks Looms

Recent events show that the S&P Semiconductors Select Industry Index seems to be experiencing a downturn, which could result in a decline in semiconductor stocks. Known as a key indicator

Anthropic Investment

Amazon’s Bold Anthropic Investment

On Monday, Amazon announced its plan to invest up to $4 billion in the AI firm Anthropic, acquiring a minority stake in the process. This decision demonstrates Amazon’s commitment to

AI Experts Get Hired

Tech Industry Rehiring Wave: AI Experts Wanted

A few months ago, Big Tech companies were downsizing their workforce, but currently, many are considering rehiring some of these employees, especially in popular fields such as artificial intelligence. The

Lagos Migration

Middle-Class Migration: Undermining Democracy?

As the middle class in Lagos, Nigeria, increasingly migrates to private communities, a PhD scholar from a leading technology institute has been investigating the impact of this development on democratic

AI Software Development

ChatGPT is Now Making Video Games

Pietro Schirano’s foray into using ChatGPT, an AI tool for programming, has opened up new vistas in game and software development. As design lead at business finance firm Brex, Schirano

Llama Codebot

Developers! Here’s Your Chatbot

Meta Platforms has recently unveiled Code Llama, a free chatbot designed to aid developers in crafting coding scripts. This large language model (LLM), developed using Meta’s Llama 2 model, serves

Tech Layoffs

Unraveling the Tech Sector’s Historic Job Losses

Throughout 2023, the tech sector has experienced a record-breaking number of job losses, impacting tens of thousands of workers across various companies, including well-established corporations and emerging startups in areas

Chinese 5G Limitation

Germany Considers Limiting Chinese 5G Tech

A recent report has put forth the possibility that Germany’s Federal Ministry of the Interior and Community may consider limiting the use of Chinese 5G technology by local network providers

Modern Warfare

The Barak Tank is Transforming Modern Warfare

The Barak tank is a groundbreaking addition to the Israeli Defense Forces’ arsenal, significantly enhancing their combat capabilities. This AI-powered military vehicle is expected to transform the way modern warfare

AI Cheating Growth

AI Plagiarism Challenges Shake Academic Integrity

As generative AI technologies like ChatGPT become increasingly prevalent among students and raise concerns about widespread cheating, prominent universities have halted their use of AI detection software, such as Turnitin’s