如何将CSS应用于不在特定标记内的文本? [英] How to apply CSS to text that is NOT inside a certain tag?

查看:103
本文介绍了如何将CSS应用于不在特定标记内的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html>
<head>
<style>

(All but div) {
padding-left: 100px;
}

</style>
</head>
<body>

<div style="background-color: blue;">This is a div</div>
This is not a div

</body>
</html>

在不移动实际的蓝色div本身的情况下,我该替换什么(除div以外的所有内容),在文本左侧使用100px填充?

解决方案

您不能以这种方式应用CSS,但是可以使用负边距:

<html>
<head>
<style>
body {
    padding-left: 100px;
}

div {
  margin-left: -100px;
}
</style>
</head>
<body>

<div style="background-color: blue;">This is a div</div>
This is not a div

</body>
</html>

结果: https://codepen.io/cmbuckley/pen/zjOXWN

<html>
<head>
<style>

(All but div) {
padding-left: 100px;
}

</style>
</head>
<body>

<div style="background-color: blue;">This is a div</div>
This is not a div

</body>
</html>

What could I replace (All but div) with to apply 100px padding on the left to the text, "This is not a div", without moving actual blue div itself?

解决方案

You can't apply CSS in that way, but you could use negative margins:

<html>
<head>
<style>
body {
    padding-left: 100px;
}

div {
  margin-left: -100px;
}
</style>
</head>
<body>

<div style="background-color: blue;">This is a div</div>
This is not a div

</body>
</html>

Result: https://codepen.io/cmbuckley/pen/zjOXWN

这篇关于如何将CSS应用于不在特定标记内的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆