FatalErrors
Home Blogs

What kinds of CSS positioning are there?HTML, CSS

position positioning

Before we talk about relative positioning, let's first talk about one of our techniques for using HBuilder. We create a way to group divs into boxes. If we want to create a div with a class name box, we can do thisDiv.box+ tab.

If three or more can do thisDiv.box$*3 + tab.

Okay, now let's say a question, we created three boxes, and we want to change the position of the boxes like this:

We can divide this action into two steps.

  1. Move box2 200 PX to the right.
  2. Move box2 down by 200px.

Let's do the first step to set a left margin margin for box2-Left:200px.

Successfully, let's move on to the second step.Set an upper margin margin for box2-Top:200px.

We found that we could not achieve the expected results.So let's go ahead and we'll adjust the box 3 up by 200px.

It looks like OK, but it seems like a hassle. We just want to adjust the position of box2, but we have to adjust box3. That's a hassle.So we're leading to positioning!!!

  • Let's talk about positioning:
  • Positioning refers to placing a specified element anywhere on the page.
  • Elements can be placed arbitrarily by positioning.
  • How to set the position?
  • By position property!!

Let's look at the reference manual for the novice bird tutorial to find possible values:

valuedescribe
absoluteGenerate absolutely positioned elements relative to the first parent element other than static positioning.The position of the element is specified by the attributes "left", "top", "right" and "bottom".
fixedGenerates fixed positioned elements that are positioned relative to the browser window.The position of the element is specified by the attributes "left", "top", "right" and "bottom".(Fixed positioning is also one of the determinants of positioning)
relativeGenerates relatively positioned elements that are positioned relative to their normal position.So, "left:20"Adds 20 pixels to the LEFT position of the element.
staticDefault value.No positioning, elements appear in the normal flow (ignoring top, bottom, left, right, or z-index declarations).
stickySticky positioning, which is based on where the user scrolls.It behaves likePosition:relative;When a page scrolls beyond the target area, it behaves like a pagePosition:fixed;, it will be fixed to the target position.Note: Internet Explorer, Edge 15 and earlier versions of IE do not support sticky positioning.Safari needs to use -webkit-prefix (see the example below).
inheritSpecifies that the value of the position attribute should be inherited from the parent element.
initialSet this property as the default value for details CSS initial keyword.

Relative relative positioning

When the position of an element is set to relative, the element is set to relative positioning.Characteristic:

  1. When relative positioning of an element is turned on without setting an offset, no change is made to the element.
  2. Relative positioning is positioning relative to the original position of an element in the document stream.
  3. Relatively positioned elements are not detached from the document stream.
  4. Relative positioning takes our elements one level higher.
  5. Relative positioning does not change the nature of an element, whether block or block, inline or inline.(Actually, it's the same thing as the third point)

When positioning of an element is turned on (the position attribute value is a non-static value), the offset of an element can be set by four attributes: left, right, top, and bottom.

  • Left: The left offset of the element relative to its positioning position.
  • Right: The offset of the element relative to the right of its positioning position.
  • top: The side offset of an element relative to its positioning position.
  • bottom: The offset of the element relative to the lower side of its positioning position.

Now let's look at using relative positioning to solve the problem we described above.

The fourth feature, what does it mean to elevate one level of our elements?Let's take a look:

Usually only two offsets are needed to locate an element.Typically, an offset in the horizontal direction and an offset in the vertical direction are chosen to locate an element.

We only need to imagine a planar coordinate system when setting relative positioning.

absolute positioning

When the position property value is set to absolute, the absolute positioning of the element is turned on.Characteristic:

  1. Turning absolute positioning on will detach elements from the document stream.

  2. If you do not set an offset after turning on absolute positioning, the position of the element will not change.(If not set after opening, the browser will automatically add a default offset to the element, which is the current location)

  1. Absolute positioning is relative to the closest ancestor element to which positioning was turned on.If all ancestor elements are not positioned on, they will be positioned relative to the browser window.(Typically, turning on absolute positioning of child elements will also turn on relative positioning of parent elements.)

  1. Absolute positioning raises an element one level.
  2. Absolute positioning changes the nature of elements, inline elements become block elements, and the width and height of block elements are stretched by default by content.

Fixed fixed position

Fixed positioning of elements is turned on when the position property of the element is set to fixed.Fixed positioning is also an absolute positioning, and most of its features are the same as absolute positioning.

The difference is:

  1. Fixed positioning is always relative to the browser window.
  2. Fixed positioning is fixed somewhere in the browser window and does not scroll with the scrollbar.eg: Advertising.(IE6 does not support fixed positioning)

z-index hierarchy problem

When we turn positioning on, we raise the element one level.

So what if box1 and box3 were also turned on and promoted to the same level?

We say that if the hierarchy of the positioned elements is the same, the elements below the structure will cover the elements above.

Can we adjust the hierarchy again?

Tolerable!!!

  • The z-index attribute allows you to set the hierarchy of elements.
  • You can set a positive integer for z-index as the value that will be the level of the current element.
  • The higher the level, the more preferred the display.

  • z-index is not useful for elements that do not have position ing turned on.
  • A parent element's hierarchy never covers a child element.(It can be understood that paternity is great)

opacity sets the transparent background of the element

opacity can be used to set the transparency of an element's background, which requires a value between 0 and 1.

  • 0 means full transparency.
  • 1 means completely opaque.
  • 0.5 means translucent.
<span style="color:#000000"><code class="language-html"><span style="color:#61aeee"><!DOCTYPE html></span>
<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"><</span>html</span><span style="color:#999999">></span></span>
	<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"><</span>head</span><span style="color:#999999">></span></span>
		<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"><</span>meta</span> <span style="color:#d19a66">charset</span><span style="color:#669900"><span style="color:#999999">=</span><span style="color:#999999">"</span>UTF-8<span style="color:#999999">"</span></span><span style="color:#999999">></span></span>
		<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"><</span>title</span><span style="color:#999999">></span></span><span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"></</span>title</span><span style="color:#999999">></span></span>
		<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"><</span>style</span> <span style="color:#d19a66">type</span><span style="color:#669900"><span style="color:#999999">=</span><span style="color:#999999">"</span>text/css<span style="color:#999999">"</span></span><span style="color:#999999">></span></span>
			<span style="color:#669900">.box1</span><span style="color:#999999">{</span>
				<span style="color:#98c379">width</span><span style="color:#999999">:</span> 200px<span style="color:#999999">;</span>
				<span style="color:#98c379">height</span><span style="color:#999999">:</span> 200px<span style="color:#999999">;</span>
				<span style="color:#98c379">background-color</span><span style="color:#999999">:</span> red<span style="color:#999999">;</span>
				<span style="color:#5c6370 ">/* Turn on relative positioning*/</span>
				<span style="color:#98c379">position</span><span style="color:#999999">:</span> relative<span style="color:#999999">;</span>
				<span style="color:#98c379">z-index</span><span style="color:#999999">:</span> 1<span style="color:#999999">;</span>
				<span style="color:#5c6370 ">/* Set translucency*/</span>
				<span style="color:#98c379">opacity</span><span style="color:#999999">:</span> 0.5<span style="color:#999999">;</span>
			<span style="color:#999999">}</span>
			<span style="color:#669900">.box2</span><span style="color:#999999">{</span>
				<span style="color:#98c379">width</span><span style="color:#999999">:</span> 200px<span style="color:#999999">;</span>
				<span style="color:#98c379">height</span><span style="color:#999999">:</span> 200px<span style="color:#999999">;</span>
				<span style="color:#98c379">background-color</span><span style="color:#999999">:</span> yellow<span style="color:#999999">;</span>
				<span style="color:#5c6370 ">/* Turn on absolute positioning*/</span>
				<span style="color:#98c379">position</span><span style="color:#999999">:</span> absolute<span style="color:#999999">;</span>
				<span style="color:#5c6370 ">/* Set offset */</span>
				<span style="color:#98c379">top</span><span style="color:#999999">:</span> 100px<span style="color:#999999">;</span>
				<span style="color:#98c379">left</span><span style="color:#999999">:</span> 100px<span style="color:#999999">;</span>
				<span style="color:#98c379">z-index</span><span style="color:#999999">:</span> 2<span style="color:#999999">;</span>
				<span style="color:#5c6370 ">/* Set translucency*/</span>
				<span style="color:#98c379">opacity</span><span style="color:#999999">:</span> 0.5<span style="color:#999999">;</span>
			<span style="color:#999999">}</span>
			<span style="color:#669900">.box3</span><span style="color:#999999">{</span>
				<span style="color:#98c379">width</span><span style="color:#999999">:</span> 200px<span style="color:#999999">;</span>
				<span style="color:#98c379">height</span><span style="color:#999999">:</span> 200px<span style="color:#999999">;</span>
				<span style="color:#98c379">background-color</span><span style="color:#999999">:</span> aqua<span style="color:#999999">;</span>
				<span style="color:#5c6370 ">/* Turn on absolute positioning*/</span>
				<span style="color:#98c379">position</span><span style="color:#999999">:</span> absolute<span style="color:#999999">;</span>
				<span style="color:#98c379">left</span><span style="color:#999999">:</span> 200px<span style="color:#999999">;</span>
				<span style="color:#98c379">top</span><span style="color:#999999">:</span> 200px<span style="color:#999999">;</span>
				<span style="color:#98c379">z-index</span><span style="color:#999999">:</span> 3<span style="color:#999999">;</span>
				<span style="color:#5c6370 ">/* Set translucency*/</span>
				<span style="color:#98c379">opacity</span><span style="color:#999999">:</span> 0.5<span style="color:#999999">;</span>
			<span style="color:#999999">}</span>
		<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"></</span>style</span><span style="color:#999999">></span></span>
	<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"></</span>head</span><span style="color:#999999">></span></span>
	<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"><</span>body</span><span style="color:#999999">></span></span>
		<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"><</span>div</span> <span style="color:#d19a66">class</span><span style="color:#669900"><span style="color:#999999">=</span><span style="color:#999999">"</span>box1<span style="color:#999999">"</span></span><span style="color:#999999">></span></span><span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"></</span>div</span><span style="color:#999999">></span></span>
		<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"><</span>div</span> <span style="color:#d19a66">class</span><span style="color:#669900"><span style="color:#999999">=</span><span style="color:#999999">"</span>box2<span style="color:#999999">"</span></span><span style="color:#999999">></span></span><span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"></</span>div</span><span style="color:#999999">></span></span>
		<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"><</span>div</span> <span style="color:#d19a66">class</span><span style="color:#669900"><span style="color:#999999">=</span><span style="color:#999999">"</span>box3<span style="color:#999999">"</span></span><span style="color:#999999">></span></span><span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"></</span>div</span><span style="color:#999999">></span></span>
	<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"></</span>body</span><span style="color:#999999">></span></span>
<span style="color:#e06c75"><span style="color:#e06c75"><span style="color:#999999"></</span>html</span><span style="color:#999999">></span></span>

</code></span>

We can use opacity to set transparency and create a hazy feeling.

Note: The opacity attribute is not supported in browsers with IE8 or below and needs to be replaced by the following attributesFilter:alpha(opacity=50);.

Posted by rambler at Jan 16, 2021 - 6:25 PM Tag: Front-end

哆哆女性网重庆汽车网站建设餐饮油水分离php制作视频网站时尚家居设计网站周易免费测名网超级无敌追女仔广州企业网站建设哪家服务好商丘第三方检验大兴网站建设价格广告设计类的网站运营公司起什么名字好姓周有孩子起名宝宝起名字带晨字的梦见下雨是什么意思周公解梦名声大噪声名鹊起翊字的怎么起名鑫字和哪个字搭配起名好听起个英文名软件宝可梦剑盾像素破解版下载起名字大全起名字有哪些江山网站建设周易名字大全生辰八字网站地图制作带东字起名唐诗宋词起名女孩名字关于包装设计网站十堰手机网站建设永城芒山赵大飞案吉林租房即可申请落户公司起名免费软件吗淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻不负春光新的一天从800个哈欠开始有个姐真把千机伞做出来了国产伟哥去年销售近13亿充个话费竟沦为间接洗钱工具重庆警方辟谣“男子杀人焚尸”男子给前妻转账 现任妻子起诉要回春分繁花正当时呼北高速交通事故已致14人死亡杨洋拄拐现身医院月嫂回应掌掴婴儿是在赶虫子男孩疑遭霸凌 家长讨说法被踢出群因自嘲式简历走红的教授更新简介网友建议重庆地铁不准乘客携带菜筐清明节放假3天调休1天郑州一火锅店爆改成麻辣烫店19岁小伙救下5人后溺亡 多方发声两大学生合买彩票中奖一人不认账张家界的山上“长”满了韩国人?单亲妈妈陷入热恋 14岁儿子报警#春分立蛋大挑战#青海通报栏杆断裂小学生跌落住进ICU代拍被何赛飞拿着魔杖追着打315晚会后胖东来又人满为患了当地回应沈阳致3死车祸车主疑毒驾武汉大学樱花即将进入盛花期张立群任西安交通大学校长为江西彩礼“减负”的“试婚人”网友洛杉矶偶遇贾玲倪萍分享减重40斤方法男孩8年未见母亲被告知被遗忘小米汽车超级工厂正式揭幕周杰伦一审败诉网易特朗普谈“凯特王妃P图照”考生莫言也上北大硕士复试名单了妈妈回应孩子在校撞护栏坠楼恒大被罚41.75亿到底怎么缴男子持台球杆殴打2名女店员被抓校方回应护栏损坏小学生课间坠楼外国人感慨凌晨的中国很安全火箭最近9战8胜1负王树国3次鞠躬告别西交大师生房客欠租失踪 房东直发愁萧美琴窜访捷克 外交部回应山西省委原副书记商黎光被逮捕阿根廷将发行1万与2万面值的纸币英国王室又一合照被质疑P图男子被猫抓伤后确诊“猫抓病”

哆哆女性网 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化