分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

css 实践记录

发布时间:2023-09-06 01:28责任编辑:蔡小小关键词:暂无标签

子绝父相

https://developer.mozilla.org/zh-CN/docs/Web/CSS/position

利用子绝父相来实现一种比较老的居中方式:1.明确宽度;2.定位左边到容器的中间位置;3.margin-left负值来左移元素的一半,实现元素容器居中

<style> ???.container{ ???????position: relative; ???} ???.item{ ???????position: absolute; ???????background-color: #0F9E5E; ???????display: inline-block; ???????width: 90px; ???????left: 50%; ???????margin-left: -45px; ???????height: 10px; ???}</style><div class="container"> ???<div class="item"></div></div>

小三角

思路很简单,就是输入法输入一个菱形,然后隐藏掉一半就行了。

<style rel="stylesheet"> ???.tri:before{ ???????content: ‘◇‘; ???????line-height: 1; ???????font-size: 30px; ???????display: inline-block; ???????height: 15px; ???????overflow: hidden; ???}</style><span class="tri"></span>

+ 和 ~ 选择器

div+p:选择紧接在 <div> 元素之后的 一个 <p> 元素。

p~ul:选择 <p> 元素后的 所有 <ul> 元素。

应用场景:选中第一个以为的所有元素。以下两种方式都可以实现

<style> ???/*.item ~ .item*/ ???.item + .item{ ?????????color: red; ???}</style><div class="item first">1</div><div class="item">2</div><div class="item">3</div><div class="item">4</div>

运行结果:

1234

行高和字体大小一致

line-height:1

容器半透明,内容不透明

使用opacity的话会导致容器以及内容都透明,使用rgba可以实现容器透明,但内容不透明

<style> ???.container{ ???????background-color: rgba(99,99,99,0.5); ???}</style><div class="container"> ???123131</div>

css 实践记录

原文地址:http://www.cnblogs.com/hellohello/p/7954221.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved