2015-08-17 29 views
1

我在锚标签中有一个img标签。 ancher标签位于div标签内。我正在使用img标签的alt属性。 alt属性的值是一个长度为68个字符的文本。我的问题是alt属性值(文本)正在div &之外,它隐藏在IE中。我的意思是在显示几个字符后,通常休息字符被隐藏或裁剪。这是我的html代码片段。如何为img标签的alt属性(word-break:break-all属性在IE中不起作用)编写css

<div class="products"> 
    <div class="prod-image" id="catEntryImage"> 
     <div class="prodClass" id=WCCE> 
      <a><img alt="some text total around 70 character" src="someURL"/></a> 
      <P class=gasCode></P> 
     </div> 
    </div> 
    <div class="prod-content"></div> 
    <script type="text/javaScript"></script> 
</div> 

CSS对于给定的HTML片段

div { 
    line-height: 1.4em; 
    word-break: break-all; 
    position: relative; 
    margin: 0; 
    padding: 0; 
    border: 0; 
    font-family: arial, helvetica, sans-serif; 
    font-size: 100%; 
} 

img { 
    text-decoration: none; 
    border:0; 
} 

a { 
    color: #e10014; 
    text-decoration: none; 
    font-size: 1.2em; 
} 
.products .prod-image { 
    width: 135px; 
    float: left; 
    margin-right: 20px; 
    margin-bottom: 20px; 
    text-align: center; 
    vertical-align: bottom; 
    overflow: hidden; 
    max-height: 250px; 
    overflow: hidden; 
} 
.products .prod-content { 
    width: 288px; 
    float: left; 
    margin-bottom: 20px; 
    text-align: left; 
    vertical-align: bottom; 
} 

我申请自动换行&断行CSS属性图像的alt属性,但它也没有工作。任何机构能帮助我吗?这只发生在IE中。如果我为img标签使用“word-break:break-all”CSS属性,而不是在Chrome中正常工作,但在IE中不起作用。

+0

可以请你提供HTML代码..让我们可以更找出你的问题。 – pedram

+0

我已经提供了上面的html&css代码片段。 –

+0

其中'IE'作为它在IE11和IE10上正常工作的地方。 – vivekkupadhyay

回答

4

你只需要设置一个heightwidth其上.prodClass并设置heightwidth<img> 而alt应该自己照顾自己的形象的父。

https://jsfiddle.net/Lu3tu98b/5/

<div class="prodClass"> 
    <a> 
     <img alt="This will contain a really long sentence with more than 70 characters right here." src="someURL"/> 
    </a>  
</div> 

.prodClass { 
    height: 150px; 
    width: 150px; 
    background-color: wheat; 
} 

.prodClass img { 
    background-color: pink; 
    width: 100%; 
    height: 100%; 
} 
+0

你拨弄没有工作在IE 11 :( –

+0

更新了IE 11 –

0

只是风格

img { color: red; } 

的ALT标签的文本样式

+1

你的建议工作正常改变颜色的文本内alt属性,但我的问题是文字没有包装在父div因此大部分字符不显示或我必须说alt标签值是隐藏的。 –

1

请通过我的JSFIddle,我希望这是你想实现什么。

我已经创建两个单独的images与大alt文本。

HTML

<a class="a1"><img alt="some text total around 70 character some text total around 70 character some text total around 70 character some text total around 70 character some text total around 70 character" src="someURL"/></a> 

<a class="a2"><img alt="some text total around 70 character some text total around 70 character some text total around 70 character some text total around 70 character some text total around 70 character" src="someURL"/></a> 

CSS

.a1{ 
    text-decoration: none; 
    border:0; 
    width:270px; 
    word-break:break-all; 
    height:auto; 
    display: block; 
    } 

.a2{ 
    text-decoration: none; 
    border: 0px none; 
    width: 270px; 
    word-break: break-all; 
    height: auto; 
    text-overflow: ellipsis; 
    overflow: hidden; 
    display: block; 
    white-space: nowrap; 
} 

在第一image,我用word-break:break-all断裂,包裹img包装内的文字alt。而在后者中,我使用text-overflow:ellipsis隐藏额外的alt文本,当它超过img包装。

+0

你的小提琴(https://jsfiddle.net/Lu3tu98b/)未在IE 11 –

+0

对不起@PrakharJain我的错误的工作,我更新了我的答案。 – vivekkupadhyay

1

使用本。

img{width:100px} // change this as per you requirement 

这应该欺骗IE浏览器的问题..

也是在IE仅风格指定。所以不会影响其他浏览器的工作..

像:

<!--[if IE]><style type="text/css"> img{width:100px}</style><![endif]--> 

为了对付IE 11问题:请在这里请参阅本old post

+0

的例子中,我试过,但并不在IE工作。 –

+0

请注明IE版本,我想你正在服用约11 IE浏览器,它是。一个新的挑战,我有我的答案对付IE 11 – MarmiK

+0

如果我不保持背景色的CSS则显示在格边境更新旧帖子的链接我一直在边界:无;但它仍然是显示边框有没有什么办法去除这个边框? –

相关问题