工作中遇到的html和css的一些问题解决(1)

iconfont字体图标不能旋转

问题:字体图为内联元素,添加css3的一些2D和3D效果不起作用

解决:

转为行内块或块级元素即可(display:inline-block或者 dispaly:block

button按钮点击时出现边框

CSS控制 button 按钮的在Chrome点击时候出现黑色边框
解决:

button{
   border:0;
   outline:none;  /* 或者 outline:0 */
  }

button 按钮 位置不准确 ,转为块,再设置margin 值

button{
  display:block;
}

textarea和下一个元素之间间距处理问题

textarea框和下一个元素相交的地方出现边距,在google浏览器中调试出现的,但是在firebox中没有

解决:

textarea {
    display: block;   /* 重点是需要加上这一句  */
    width: 600px;
    height: 120px;
    padding: 20px 20px;
    margin-bottom: 12px;
}

和img标签一样,用display: block; 或者可以用vertical-align: middle;

当a需要设置宽高时,给a标签元素转元素类型时==>>转块级元素

解决:
在这里插入图片描述

input:checkbox 清除margin值

<input type="checkbox" name="" id=""> 
input{
  margin:0;
}

input :text 自带背景属性颜色

在这里插入图片描述
解决如下:


input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  /* 背景颜色  */
  /* 注意:这里的272px是input长度 建议写input长度即可 */
  box-shadow: 0 0 0 272px #fff inset!important;
  background-color: #fff;
}

/* 要解决输入的时候背景色变白色 可以设置input */
input:focus {
  background: transparent
}

border边框属性double

    .box {
      height: 100px;
      width: 100px;
      border: 50px double green;
      background: #fff;
    }

在这里插入图片描述

汉字拼音写法 ruby和 rt 标签

<rp> </rp> 定义不支持ruby元素的浏览器所显示的内容。

<rt> </rt> 定义字符的解释或发音。

<ruby> </ruby> 定义ruby注释

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    ruby {
      font-size: 50px;
      color: green;
    }

    rt {
      font-size: 14px;
      color: red;
    }
  </style>
</head>
<body>
  <ruby class="ruby-text"><rt>niu</rt><rt>xian</rt><rt>sen</rt>
  </ruby>
</body>
</html>

在这里插入图片描述

解决多行溢出隐藏,省略号代替

解决如下:

  overflow: hidden;
  text-overflow: ellipsis;
  text-overflow: -o-ellipsis-lastline;
  display: -webkit-box;
  -webkit-line-clamp: 3; // 行数
  line-clamp: 3;
  -webkit-box-orient: vertical; // 设置对齐模式

在这里插入图片描述

浏览器私有前缀解决兼容问题

width: 380px;
height: 288px;
margin: 280px auto;
border: 1px solid black;
background: -webkit-linear-gradient(right, yellow, red);
background: -moz-linear-gradient(right, yellow, red);
background: -ms-linear-gradient(right, yellow, red) ;
background: -o-linear-gradient(right, yellow, red);
background: linear-gradient(right, yellow,red)

在这里插入图片描述

改变input框中placeholder颜色的方法

input::-webkit-input-placeholder { /* WebKit browsers 适配谷歌 */
    color: #BDCADA;
}
input:-moz-placeholder { /* Mozilla Firefox 4 to 18 适配火狐 */
    color: #BDCADA;
}
input::-moz-placeholder { /* Mozilla Firefox 19+ 适配火狐 */
    color: #BDCADA;
}
input:-ms-input-placeholder { /* Internet Explorer 10+  适配ie*/
    color: #BDCADA;
}

select中实现placeholder效果和样式的重置

在这里插入图片描述

 <select name="" id="" class="ipt-num select-single" v-model="selectDay">
     <option value="" style="display: none">请选择投放周期</option>
     <option value="7天"  class="select-singe">7</option>
     <option value="14天" class="select-singe">14</option>
     <option value="21天" class="select-singe">21</option>
     <option value="28天" class="select-singe">28</option>
 </select>

谷歌、火狐、ie下 select 的默认下拉箭头图标差别还是比较大,一般我们都会清除默认样式,重新设计箭头图标;

/* --ie清除--*/
select::-ms-expand{ display: none; }

/* --火狐、谷歌清除--*/
select{
     appearance:none;  
    -moz-appearance:none;  
    -webkit-appearance:none;
     background: url("xxx.png") no-repeat scroll right center transparent;
     padding-right: 14px;
}
/* --箭头就用自己设计的箭头,padding 空出箭头的位置--*/

option样式的简单清除

option::-ms-expand{ display: none; }
option{
    -moz-appearance:none; /* Firefox */
    -webkit-appearance:none; /* Safari 和 Chrome */
    appearance:none;
}

/* --背景色字体颜色--*/
option:hover{
    color:#fff;
    background-color:#1E90FF;
}

input中的radio样式


input[type=radio]选中的样式变化

input[type=radio]:hover{
border: 1px solid #ccc;
}

input[type=radio]:focus{
border: 1px solid #ccc;
}

 

1、默认属性,input{样式}
2、鼠标悬浮:input:hover{样式}
3、点击属性:input:focus{样式}

type不同设置也不同,比如radio还要设置input:checked的样式,用tab切换表单使radio获得焦点和点击是两种样式!

清除样式

input{
	-webkit-appearance:none;
	border-radius: 0;
}

input{outline:none}

input中 radio空心写法

在这里插入图片描述

<input type="radio" id="interval" class="radio mr-23" name="way" value="间隔播放" v-model="selectWay">
<label for="interval" class="mr-60">间隔播放</label>
<input type="radio" id="continuous" class="radio mr-23" name="way" value="连续播放" v-model="selectWay">
<label for="continuous">连续播放</label>

记得先清除默认的样式

// 清除样式后自己添加的
.radio{
    width: 0.3rem;
    height: 0.3rem;
    border: 0.01rem solid #ddd;
    border-radius: 50%;
}
// 聚焦时样式
input[type=radio]:focus{
    width: 0.3rem;
    height: 0.3rem;
    background: #ffffff;
    border-radius: 0.09;
    border: 0.09rem solid #FEBA00;
} 
// 选中样式
input[type=radio]:checked{
    width: 0.3rem;
    height: 0.3rem;
    background: #ffffff;
    border-radius: 0.09;
    border: 0.09rem solid #FEBA00;
} 

解决横向滚动子元素撑开父元素(未知子元素多少个,不能设置父元素的宽)

// 这部分是小标签
// 下面两个wrapper 一个是判断定位的,不影响最终效果
.selected-wrapper{
    position: absolute;
    left: 0;
    top: -0.55rem;
    width: 7.08rem;
    height: 0.41rem;
    overflow: hidden;
}
.show-wrapper{
    width: 7.08rem;
    overflow: hidden;
    margin-top: 0.18rem;
}
.selected-box{
    white-space: nowrap;
    overflow: auto;
    // 隐藏滚动条
    &::-webkit-scrollbar{
        display: none;
    }
}
.selected-item{
    display: inline-block;
    margin-right: 0.08rem;
    background: #fff;
    color: #666677;
    height: 0.41rem;
    line-height: 0.41rem;
    border-radius: 0.07rem;
    padding: 0 0.17rem 0 0.18rem;
}
.close-sel{
    color:#DDDDDD;
    font-size:0.3rem;
    margin-left:0.08rem;
}

在这里插入图片描述
还有一种写法如下

	<div class="seckill-start ml-24 w702">
            <div class="wrapper">
                <div class="wrapper-item flex-column-center">
                    <div class="fs-24 color-A2A"><span>12</span><span>10:00</span></div>
                    <div class="fs-20 color-A2A mt-5">已开抢</div>
                </div>
                <div class="wrapper-item flex-column-center">
                    <div class="fs-30 color-333"><span>13</span><span>12:00</span></div>
                    <div class="fs-00 color-333 rushing">抢购中</div>
                </div>
                <div class="wrapper-item flex-column-center">
                    <div class="fs-24 color-A2A"><span>14</span><span>14:00</span></div>
                    <div class="fs-20 color-A2A  mt-5">即将开抢</div>
                </div>
                <div class="wrapper-item flex-column-center">
                    <div class="fs-24 color-A2A"><span>15</span><span>16:00</span></div>
                    <div class="fs-20 color-A2A  mt-5">即将开抢</div>
                </div>
                <div class="wrapper-item flex-column-center">
                    <div class="fs-24 color-A2A"><span>15</span><span>16:00</span></div>
                    <div class="fs-20 color-A2A  mt-5">即将开抢</div>
                </div>
            </div>
 	</div>
 
.seckill-start{
    width: 7.02rem;
    height: 1.03rem;
    ::-webkit-scrollbar {
        display: none;
    }
    .wrapper{
        width: 100%;
        overflow: auto;
        display: flex;
    }
    .wrapper-item{
        flex: none;
        width: 1.74rem;
        height: 1.03rem;
        text-align: center;
    }
    .rushing{
        width: 1.44rem;
        height: .32rem;
        text-align: center;
        line-height: .32rem;
        color: #fff;
        border-radius: .16rem;
        background: $main-color;
    }
}

在这里插入图片描述

隐藏滚动条方法

具体看上个案例

.selected-box{
    white-space: nowrap;
    overflow: auto;
    // 隐藏滚动条
    &::-webkit-scrollbar{
        display: none;
    }
}

移动端1px问题(使用伪类+transform实现)

		.top:after{
			content: '';
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			-webkit-transform: scale(1, 0.5);
			transform: scale(1, 0.5);
			border-top: 1px solid #DDDDDD;
		}
		.bottom:after{
			content: '';
			position: absolute;
			bottom: 0;
			left: 0;
			right: 0;
			-webkit-transform: scale(1, 0.5);
			transform: scale(1, 0.5);
			border-bottom: 1px solid #DDDDDD;;
		}
		.left:after{
		  content: '';
		  display: block;
		  position: absolute;
		  top: 0;
		  bottom: 0;
		  left: 0;
		  -webkit-transform: scale(0.5, 1);
		  transform: scale(0.5, 1);
		  border-left: 1px solid #DDDDDD;
		}
		.right:after{
          content: '';
          display: block;
          position: absolute;
          top: 0;
          bottom: 0;
          right: 0;
          -webkit-transform: scale(0.5, 1);
          transform: scale(0.5, 1);
          border-right: 1px solid #DDDDDD;
		}

引用:移动端1px误差的原因以及解决方案
在这里插入图片描述

三角形加弧度的实现

看图先
在这里插入图片描述

  <div class="selectTick"></div>
  
 .selectTick{
        position: absolute;
        top: 2.69rem;
        left: 2.79rem;
        width: 0;
        height: 0;
        border-bottom-right-radius: 0.18rem;
        border-left: 0.3rem solid transparent;
        border-top: 0.3rem solid transparent;
        border-bottom:0.3rem solid #FECB00;
        border-right:0.3rem solid #FECB00;
        // 对勾图标
        &:after {
            position: absolute;
            content: "\e625";
            font-family: "iconfont" !important;
            font-style: normal;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
            right: -0.26rem;
            color: #fff;
            font-size: 0.24rem;
            top: -0.05rem;
        }
    }

视频上下留白问题

<style>
	video {
		object-fit:fill;
		width:700px;
		height:320px;
	}
</style>

<video src="xxx.mp4" controls autoplay loop></video>

vue中背景色和渐变同时存在

  :style="{
            'background-size': '7.5rem 4rem',
            'background-position-y': '0.88rem',
            'background-image': 'linear-gradient(rgba(255,255,255,0.75) 5%, rgba(0,0,0,0.3) 45%, rgba(0,0,0) 75%), url(' + hotPackageData.picUrlView + ')',
            'background-repeat': 'no-repeat',
            'background-color':'#000',
   }"

在这里插入图片描述

底部样式居中

在这里插入图片描述

.activeName{
    font-size: .36rem;
    color: #000;
    font-weight: bold;
    position: relative;
    &::after{
        content: '';
        width: .96rem;
        height: .04rem;
        background: $main-color;
        display: block;
        position: absolute;
        bottom: -0.2rem;
        left: 50%;
        right: 50%;
        transform: translateX(-50%);
    }
}

input标签添加上disable属性在ios端字体颜色和placeholder颜色不兼容的问题

因工作是嵌入H页面,导致在安卓上没问题,但是ISO各种浮出水面,慢慢改吧,处理兼容问题;

input[disabled],input:disabled,input.disabled{  
    color: #333333;  
    -webkit-text-fill-color: #333333;  
    -webkit-opacity:1;  
    opacity: 1;  
} 
input::-webkit-input-placeholder{
  color: #cccccc;
  -webkit-text-fill-color: #ccc;
  opacity: 1;
  -webkit-opacity:1;
}
input:disabled{
  background: none;
  color: #333;
  -webkit-text-fill-color: #333;
  opacity: 1;
  -webkit-opacity:1;
}
input:disabled::-webkit-input-placeholder{
  color: #cccccc;
  -webkit-text-fill-color: #ccc;
  opacity: 1;
  -webkit-opacity:1;
}

position:sticky粘性定位的使用

注意 :移动端可以使用,但是适配IE有兼容问题

.tab-control{
    position: sticky;
    top:0rem;
}

stylus写法

$green = #02a774;
$yellow = #F5A100;
$bc = #f4f4f4;

// 一像素下边框
bottom-border-1px($color)
  position relative
  border none
  &:after
    content ''
    position absolute
    left 0
    bottom 0
    width 100%
    height 1px
    background-color $color
    transform scaleY(0.5)

// 一像素上边框
top-border-1px($color)
  position relative
  &::before
    content ''
    position absolute
    z-index 200
    left 0
    top 0
    width 100%
    height 1px
    background-color $color

//根据像素比缩放1px像素边框
@media only screen and (-webkit-device-pixel-ratio: 2 )
  .border-1px
    &::before
      transform scaleY(.5)

@media only screen and (-webkit-device-pixel-ratio: 3 )
  .border-1px
    &::before
      transform scaleY(.333333)

//根据像素比来使用 2x图 / 3x图 
bg-image($url)
  background-image: url($url + "@2x.png")
  @media (-webkit-min-device-pixel-ratio: 3),(min-device-pixel-ratio: 3)
    background-image: url($url + "@3x.png")

//清除浮动
clearFix()
  *zoom 1
  &::after
    content ''
    display block
    clear both

去除浏览器自带的滚动条

在这里插入图片描述
在vue中设置app

<style lang="scss" scoped>
#app{
  width: 100%;
  height: 100%;
  @include clearfix;
  // 去除浏览器自带滚动条
  ::-webkit-scrollbar {
    display:none;
  }
}
</style>

点击按钮的禁止选择图示

在这里插入图片描述

cursor:not-allowed; 

在这里插入图片描述

### 回答1: HTMLCSS遇到问题解决方法很多,以下是一些常见问题和对应的解决方案: 1. 元素没有居显示:使用flex布局,并设置justify-content和align-items为center,或者将元素的position设置为absolute,再设置top、bottom、left、right为0,再设置margin为auto即可居显示。 2. 页面加载速度慢:可以通过压缩图片大小和文件大小、减少HTTP请求、使用缓存等方式来优化页面加载速度。 3. 元素显示位置错乱:可能是由于box-sizing属性设定不当或选择器权重不够导致的,可以通过调整box-sizing属性和更改选择器的权重来解决。 4. 元素样式不生效:可能是由于样式优先级低或者CSS文件引入有误,可以使用!important提升样式优先级,或检查CSS文件引入是否正确。 5. 页面适配问题:在不同设备上,页面大小和分辨率不同,这可能导致页面适配问题,可以通过使用响应式布局、媒体查询等方式来解决。 希望这些常见问题解决方案能够帮助您更好地开发HTMLCSS页面。 ### 回答2: HTMLCSS是网页设计和开发必不可少的两个方向。在学习和实践过程,不可避免地会遇到一些问题,下面给出一些常见的问题解决方法。 一、HTML常见问题解决方法 1. 图片无法加载:通常是图片路径问题,需要确认文件路径是否正确。 2. 标签未正确嵌套:每个标签都有其特定的嵌套规则,如果嵌套不正确,会导致布局和功能出现问题。 3. 表单验证失败:必填项未填、输入内容格式不符等均可能导致表单验证失败,需要仔细检查表单字段设置和输入内容是否符合要求。 4. 页面显示错位、错乱:这可能是由于样式冲突或样式覆盖等原因,需要检查CSS代码,尝试使用更具体的选择器或调整样式顺序来排除冲突。 5. SEO优化不足:需要注意页面标题、描述和关键字等元素,增加页面语义化标签,以及重要内容在页面的位置等细节。 二、CSS常见问题解决方法 1. 样式无法应用或未生效:检查选择器是否正确、样式表路径是否正确、样式名是否拼写正确等。 2. 样式重复或覆盖:需要检查CSS代码,尝试使用更具体的选择器、增加权重或重构样式代码等方式来解决。 3. 布局无法达到预期效果:布局实现过程需要考虑盒模型、浮动、定位、清除浮动等布局原则,需要根据具体情况进行调整。 4. 响应式布局问题:需要使用媒体查询和弹性布局等技术来实现响应式布局,需要在不同设备上进行测试和调整。 5. 浏览器兼容性问题:不同浏览器对CSS属性的兼容性有差异,需要根据具体情况进行重构或添加浏览器私有前缀等解决方法。 综上所述,HTMLCSS的开发过程,需要不断尝试和调整,才能达到最终预期效果,更好地提升用户体验和网站质量。 ### 回答3: HTMLCSS是前端开发必不可少的两个基础技术,但是在使用过程常常会遇到各种问题,需要找到解决方法。以下是HTMLCSS遇到问题解决方法。 1.居问题 在布局,要对元素进行居操作,可能遇到水平、垂直两个方向的居问题HTML用来划分页面结构,CSS用来控制页面样式。通常使用margin和padding属性对元素进行设置,但是对于居问题,需要采用以下方法: • 水平居:可以使用text-align:center属性将元素文本进行水平居;也可以使用margin:auto和position:relative来实现元素水平居。 • 垂直居:可以使用display:inline-block和vertical-align:middle属性来实现元素垂直居;如果使用绝对定位,可以设置top:50%和transform:translateY(-50%)实现元素垂直居。 2.浮动问题 元素浮动是CSS布局的重要方式,但是浮动也可能引起其他问题,如高度塌陷、外边距合并等问题。 • 高度塌陷:当子元素设置浮动属性时,父元素高度无法自动撑高,导致高度塌陷,可以通过以下方法解决:给父元素设置overflow:hidden属性;利用伪元素清除浮动。 • 外边距合并:元素设置margin属性时,可能会产生外边距合并问题解决方法包括:给元素设置border、padding属性;通过触发BFC来避免外边距合并。 3.兼容性问题 不同浏览器对HTMLCSS的解析存在差异,兼容性问题也经常出现。 • CSS Hack:利用浏览器差异来进行样式设置,可解决不同浏览器的兼容性问题。 • CSS Reset:针对不同浏览器的默认样式进行重置,以减少兼容性问题。 4.响应式布局问题 随着移动设备的普及,响应式布局成为了必须考虑的问题,为此需要采用以下方法: • 使用@media查询实现响应式布局,利用媒体类型、分辨率等属性设置不同的样式表。 • 使用Flexbox布局来实现响应式布局,它是一种更直接、更简单的方式,通过设置容器属性,即可实现不同屏幕大小下的排列方式。 综上所述,HTMLCSS常见问题解决方法包括居问题、浮动问题、兼容性问题和响应式布局问题。需要根据具体情况采用不同的方法进行解决,避免影响整体页面的显示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值