简体   繁体   English

为什么我的 html a 标签不能与 css float 一起使用:对吗?

[英]why does my html a tag not work with css float: right?

I have a bilingual site made with ruby on rails and in the top right corner is a link to the English version and Spanish version.我有一个用 ruby​​ on rails 制作的双语网站,右上角是英文版和西班牙文版的链接。 I have 2 layouts, one for each language.我有 2 种布局,每种语言一种。 Both use the same class.两者都使用相同的类。 Here is the html这是html

<a class="language" href="home">ENGLISH</a>

and the css:和CSS:

.language {
  float:right;
  color: white
}

My problem is that without css applied the links work fine.我的问题是没有应用 css 链接工作正常。 When I apply css the word ENGLISH appears on the screan but just as normal text and not a link.当我应用 css 时,屏幕上会出现 ENGLISH 一词,但就像普通文本一样,而不是链接。 I tried commenting out float:right;我试着注释掉float:right; and again the link works but the word is in the middle of the screen because the body has text-align set to justify.链接再次有效,但该词位于屏幕中间,因为正文已将text-align设置为对齐。 I have also tried using text-align: right;我也试过使用text-align: right; in stead of float: right and this seems to have no effect.而不是float: right ,这似乎没有效果。 What is happening?怎么了?

your codes should work fine.您的代码应该可以正常工作。 maybe your css file is overridden by another css however, you can try the inline styling approach也许您的 css 文件被另一个 css 覆盖,但是您可以尝试使用内联样式方法

<a href="home" class="language" style="float:right; color:white;">ENGLISH</a>

and it should work fine它应该可以正常工作

Your code works fine as it should. 您的代码可以正常工作。 Here is a JS Fiddle to show. 这是要显示的JS小提琴 Here is the code... 这是代码...

 .language { float:right; color: white } body { background-color: black; } 
 <body> <a class="language" href="#">ENGLISH</a> </body> 

However, if you want alternatives to float: right; 但是,如果您希望其他方法float: right; . Here are some. 这里有一些。

right: 0px;

And another: 还有一个:

text-align: right;
position: absolute;

Also, this may help. 此外, 可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM