开发者

How to restrict the length of the html anchor tag text?

开发者 https://www.devze.com 2023-04-04 12:47 出处:网络
I 开发者_JAVA技巧want to link a certain text which is too long. For instance, assume the text is:

I 开发者_JAVA技巧want to link a certain text which is too long. For instance, assume the text is:

"Link this text to a page that will have the corresponding result set. The result set page inturn would redirect to another page that would give individual item. The individual item would then redirect back to the original link".

I can do that by placing the above text between <a> ... </a> tags. Things are fine... Life is cool. Now comes the tough part. The above text would be displayed on a single line increasing the page size horizontally. I want to split the string while maintaining the anchor link for that. For instance I want some thing like this:

Link this text to a page that will have the corresponding result set.

The result set page inturn would redirect to another page that would give individualitem.

The result set page inturn would redirect to another page that would give individual item.

However, these three lines should be considered as a single link and hovering the mouse over any of these lines would however display the underline for all the three lines (i.e. each of the line should not be considered individual link).

Is this possible??


It's just a simple matter of nesting HTML tags properly. For example, to have those three lines all separate but the same link, place them in individual <p> tags but encapsulate the entire segment in a <a> tag.

<a href="#anchor">
<p>This is the first line.</p>
<p>Another line.</p>
<p>Down at the bottom, same link.</p>
</a>


If you want to split the string into sentences, you'll have to do some string manipulation.

A better idea would probably be to put the text in a container and give the container a fixed width.


not sure if it's standards compliant but you can do this:

http://jsfiddle.net/Nf2TW/

<a href="#">Link this text to a page that will have the corresponding result set.
<br>
The result set page inturn would redirect to another page that would give individualitem.
<br>
The result set page inturn would redirect to another page that would give individual item.</a>


The above text would be displayed on a single line increasing the page size horizontally.

No it wouldn't. The browser should wrap that text to the size of the container. Just like it will right here:

Link this text to a page that will have the corresponding result set. The result set page inturn would redirect to another page that would give individual item. The individual item would then redirect back to the original link


I would do something like this...

<a href="..."><div style="width:25%">bla bla bla bla bla bla bla</div></a>

This should make the div a link but also limit the spacing. If you want to break it up by sentence or something I would just place a <br /> tag where you would like it to go to the next line (do not use <br> as this is not web standard).

0

精彩评论

暂无评论...
验证码 换一张
取 消