GVKun编程网logo

如何在LESS CSS嵌套类中指定html标记?(less嵌套规则)

22

最近很多小伙伴都在问如何在LESSCSS嵌套类中指定html标记?和less嵌套规则这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展angularJS如何忽略某些HTML标记?、c

最近很多小伙伴都在问如何在LESS CSS嵌套类中指定html标记?less嵌套规则这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展angularJS如何忽略某些HTML标记?、css – LESS:如何使用嵌套指定当前标记?、css – 具有指定HTML ID的Html.ActionLink?、css – 如何在LESS的类中定位id?等相关知识,下面开始了哦!

本文目录一览:

如何在LESS CSS嵌套类中指定html标记?(less嵌套规则)

如何在LESS CSS嵌套类中指定html标记?(less嵌套规则)

我有一个用于文章和 HTML5标签的类.

在家里:

<article>
    <a href="exit.PHP">
        <figurehttps://www.jb51.cc/tag/Box/" target="_blank">Box">
            <img src="assets/img/projects/exit-m.jpg" alt="">
            <figcaption>…</figcaption>
        </figure>
    </a>
</article>

在项目页面上:

<section>
    <div>
        <figurehttps://www.jb51.cc/tag/Box/" target="_blank">Box">
            <img src="assets/img/projects/exit.jpg" alt="">
            <figcaption>…</figcaption>
        </figure>
   </div>
   …

具有类exit的每个元素都在里面有一个数字HTML5元素.使用Less,我使用此代码来执行我想要的操作.

article.exit{width:260px; height:200px; top:315px; left:505px;
    figure{background-color:@exit-bg;}
    .Box:hover{.perspective-Box(se,10,@exit-shadow);}
}
section.exit{
    .Box:hover{.perspective-Box(nw,@exit-shadow);}
    .intro figcaption:hover{background:@exit-hover;}
}

但我必须指明它是文章还是部分!我有很多这样的课程,这有点烦人……

做这样的事情是否有解决方案?会很酷……

.exit{
    &article{
        width:260px; height:200px; top:315px; left:505px;
        figure{background-color:@exit-bg;}
        .Box:hover{.perspective-Box(se,@exit-shadow);}
    }
    &section{
        .Box:hover{.perspective-Box(nw,@exit-shadow);}
        .intro figcaption:hover{background:@exit-hover;}
    }
}

解决方法

如果他们不会在退出类中共享任何常见样式,那么在尝试嵌套这两个规则时,我认为没有多大意义.

也就是说,如果你仍想要嵌套它们,请记住在选择器中,元素名称总是位于其他简单选择器之前.尝试放置&在元素名称之后,看看它是否有效:

.exit{
    article&{
        width:260px; height:200px; top:315px; left:505px;
        figure{background-color:@exit-bg;}
        .Box:hover{.perspective-Box(se,@exit-shadow);}
    }
    section&{
        .Box:hover{.perspective-Box(nw,@exit-shadow);}
        .intro figcaption:hover{background:@exit-hover;}
    }
}

angularJS如何忽略某些HTML标记?

angularJS如何忽略某些HTML标记?

我收到此错误是因为其中一位用户在帖子中添加了< 3

Error: [$sanitize:badparse] The sanitizer was unable to parse the following block of html: <3

我写的代码是ng-bind-html =“Detail.details”

我希望他只被带走< a>标签和标签< br />

那可能吗?

谢谢!

您可以创建过滤器来清理您的html.

我在其中使用了strip_tags函数
http://phpjs.org/functions/strip_tags/

angular.module('filters',[]).factory('truncate',function () {
    return function strip_tags(input,allowed) {
      allowed = (((allowed || '') + '')
        .toLowerCase()
        .match(/<[a-z][a-z0-9]*>/g) || [])
        .join(''); // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>)
      var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,commentsAndPHPTags = /<!--[\s\S]*?-->|<\?(?:PHP)?[\s\S]*?\?>/gi;
      return input.replace(commentsAndPHPTags,'')
        .replace(tags,function($0,$1) {
          return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
        });
    }
});

控制器:

angular.module('myApp',['filters'])
.controller('IndexController',['$scope','truncate','$sce',function($scope,truncate,$sce){
  $scope.text="";

  $scope.$watch('text',function(){
    $scope.sanitized = $sce.trustAsHtml(truncate($scope.text,'<a><br>'));
  });
}]);

视图:

<div ng-bind-html="sanitized"></div>

http://plnkr.co/edit/qOuvpSMvooC6jR0HxCNT?p=preview

css – LESS:如何使用嵌套指定当前标记?

css – LESS:如何使用嵌套指定当前标记?

我有下一个CSS:

.button {
    background-color: black;
    border-radius: 4px;
    color: white;
}

a.button {
    text-decoration: none;
    color: white;
}

我想用LESS重新制作它,例如:

.button {
    background-color: black;
    border-radius: 4px;
    color: white;

    a& {
        text-decoration: none;
        color: white;
    }
}

但它会生成下一个(错误的)CSS:

.button {
    background-color: black;
    border-radius: 4px;
    color: white;
}

/* unexpected space */
a .button {
    text-decoration: none;
    color: white;
}

我该怎么办?

解决方法

这完全是一个版本问题.正如@freejosh评论的那样,它已在LESS的最新版本中得到解决.如果你把上面的代码带到 http://less2css.org/那么它运行正常(运行LESS 1.3.3,虽然你可以将版本更改为1.3.0并且看到它不再按预期运行并将空间放入).

由于您声明运行lessc 1.3.0,因此需要升级LESS版本.

css – 具有指定HTML ID的Html.ActionLink?

css – 具有指定HTML ID的Html.ActionLink?

我想给一个生成的Html.ActionLink HTML的id,所以我可以改变CSS取决于我在哪里。我有一个MasterPage与一组链接,我想区分活动的“Tab”与Jquery更改活动#id的CSS

现在我使用:

<%: Html.ActionLink("Some View","Index","controller")%>

它生成:

<a href="/controller">Some View</a>

我想生成:

<a id="something" href="/controller">Some View</a>

那可能吗?我试过了:

<%: Html.ActionLink("Some View","controller",new {id="blahbla")%>

但这产生:

<a href="/controller/Length?5">Some View</a>

解决方法

你在正确的轨道上。我不知道为什么它不适合你,因为你的代码有一个错字,会产生一个预期的错误。以下是您要寻找的内容:
<%= Html.ActionLink("Test Link","SomeAction","SomeController",null,new {id = "someID" }) %>

其中生成以下HTML:

<a href="/SomeController/SomeAction" id="someID">Test Link</a>

编辑:我只是意识到了什么问题,因为我错误地读你的尝试。你使用错误的重载传递id html元素。您可能将新的{id =“blah”}参数传递到routeValues参数,这将导致它在构建路由链接时使用,而不是htmlAttributes paramater,这是你想要的。

我想你在使用:

ActionLink(string linkText,string actionName,Object routeValues,Object htmlAttributes)

当你需要使用的是以下重载,像我上面在我的答案:

ActionLink(string linkText,string controllerName,Object htmlAttributes)

它确保新的{id =“blah”}被传递到htmlAttributes参数。

css – 如何在LESS的类中定位id?

css – 如何在LESS的类中定位id?

相对较新的LESS并尝试嵌套如何工作.我已经阅读了较少页面上的内容.

HTML

<!DOCTYPE html>

<html>
<head>
    <link rel="stylesheet/less" type="text/css" href="../LESS/core.less"/>
</head>
<div>
    <span id="Test1"></span>
</div>
</html>

.Test2 {
    display: block;
    #Test1 {
        .background1;
        width: 40px;
        height: 1000px !important;
    }
}

但如果我在没有嵌套的情况下写它就可以了

.Test2 {
    display: block;
}

#Test1 {
    .background1;
    width: 40px;
    height: 1000px !important;
}

.background只是{background:red;}.这个概念在我的脑海里搞砸了吗?

解决方法

嵌套问题和不匹配的标记

嵌套通常表示特定元素将出现在另一个元素下面,因此您当前的代码具有正确的想法.

目前,您的嵌套示例将尝试将id为“Test1”的元素作为目标,该元素嵌套在具有类“Test2”的元素下方,该元素与您的标记不同.

如果您想使用相同的标记来定位元素,请考虑将最外面的.Test2选择器更改为.Test:

/* This will target an element with id "Test`" below an element with class "Test" */
.Test {
    display: block;
    #Test1 {
        width: 40px;
        height: 1000px !important;
    }
}

您可以在下面看到如何将其转换为CSS:

背景检查语法

此外,您使用的.background选择器似乎存在问题.您的意思是在“Test2”元素下面定位一个额外的样式,如下例所示?

.Test {
    display: block;
    #Test1 {
        .background{
          width: 40px;
          height: 1000px !important;
        }
    }
}

其编译如下:

今天关于如何在LESS CSS嵌套类中指定html标记?less嵌套规则的讲解已经结束,谢谢您的阅读,如果想了解更多关于angularJS如何忽略某些HTML标记?、css – LESS:如何使用嵌套指定当前标记?、css – 具有指定HTML ID的Html.ActionLink?、css – 如何在LESS的类中定位id?的相关知识,请在本站搜索。

本文标签: