英文:
How to style the normal text inline with an h6 inside a <a>
问题
我有一个包含<a>
元素的情况,在其中包含有一个h6
和普通文本。我该如何为普通文本部分添加样式?
我尝试使用:not(h6)
来设置内边距和border-radius: 20px
等其他样式... 请查看我的CSS:
.uagb-taxomony-box {
background-color: transparent!important;
border: none!important;
text-decoration: none!important;
text-align: left!important;
}
a.uagb-tax-link h6 {
text-align: left!important;
}
.uagb-tax-link:not(h6) {
text-decoration: none!important;
padding: 5px!important;
background-color: #18419C!important;
border-radius: 20px!important;
}
如何正确为此添加样式?提前感谢您。
英文:
I have an <a>
element that inside has an h6
and normal text. How I can style the normal text part?
I'm trying to use :not(h6)
to put padding and border-radius:20px and others styles... see my css:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.uagb-taxomony-box {
background-color:transparent!important;
border:none!important;
text-decoration:none!important;
text-align:left!important;
}
a.uagb-tax-link h6{text-align:left!important;}
.uagb-tax-link:not(h6){
text-decoration:none!important;
padding:5px!important;
background-color:#18419C!important;
border-radius:20px!important;
}
<!-- language: lang-html -->
<div class="uagb-taxomony-box">
<a class="uagb-tax-link" href="https://dev3.netnerd.cat/tipus/desenvolupament-de-negoci/">
<h6 class="uagb-tax-title">Desenvolupament de negoci</h6>
" 16 Projectes "
</a>
</div>
<!-- end snippet -->
but watch what is happening in the screenshot below:
How can I style well this?
Thanks in advance
答案1
得分: 1
你可以为 "a" 元素添加 display: inline-block。如果你想要给文本添加背景,那么将文本放在 span 元素中并对其进行样式化。以下是更新后的代码:
.uagb-taxomony-box {
background-color:transparent!important;
border:none!important;
text-decoration:none!important;
text-align:left!important;
}
a.uagb-tax-link:not(h6){
display: inline-block;
text-decoration:none!important;
padding:5px!important;
border-radius:20px!important;
}
a.uagb-tax-link h6{
text-align:left!important;
}
.simple-text{
background-color:#18419C!important;
color: #fff;
}
<div class="uagb-taxomony-box">
<a class="uagb-tax-link" href="https://dev3.netnerd.cat/tipus/desenvolupament-de-negoci/">
<h6 class="uagb-tax-title">Desenvolupament de negoci</h6>
<span class="simple-text"> " 16 Projectes " </span>
</a>
</div>
这是翻译后的内容。
英文:
You can give display: inline-block to "a" element. If you want to give background to only text. Then put the text in span element and give styling to it. Here is the updated code:-
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.uagb-taxomony-box {
background-color:transparent!important;
border:none!important;
text-decoration:none!important;
text-align:left!important;
}
a.uagb-tax-link:not(h6){
display: inline-block;
text-decoration:none!important;
padding:5px!important;
border-radius:20px!important;
}
a.uagb-tax-link h6{
text-align:left!important;
}
.simple-text{
background-color:#18419C!important;
color: #fff;
}
<!-- language: lang-html -->
<div class="uagb-taxomony-box">
<a class="uagb-tax-link" href="https://dev3.netnerd.cat/tipus/desenvolupament-de-negoci/">
<h6 class="uagb-tax-title">Desenvolupament de negoci</h6>
<span class="simple-text"> " 16 Projectes " </span>
</a>
</div>
<!-- end snippet -->
答案2
得分: 1
你可以使用 position: absolute
:
.uagb-taxomony-box {
background-color: transparent!important;
border: none!important;
text-decoration: none!important;
text-align: left!important;
}
a.uagb-tax-link h6 {
text-align: left!important;
}
.uagb-tax-link {
display: inline-block;
margin-top: 80px;
position: relative;
text-decoration: none!important;
padding: 5px!important;
background-color: #18419C!important;
border-radius: 20px!important;
color: #fff;
}
.uagb-tax-link h6 {
position: absolute;
top: -80px;
color: #000;
}
<div class="uagb-taxomony-box">
<a class="uagb-tax-link" href="https://dev3.netnerd.cat/tipus/desenvolupament-de-negoci/">
<h6 class="uagb-tax-title">Desenvolupament de negoci</h6>
" 16 Projectes "
</a>
</div>
英文:
You can use position: absolute
:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.uagb-taxomony-box {
background-color:transparent!important;
border:none!important;
text-decoration:none!important;
text-align:left!important;
}
a.uagb-tax-link h6{text-align:left!important;}
.uagb-tax-link {
display: inline-block;
margin-top: 80px;
position: relative;
text-decoration:none!important;
padding:5px!important;
background-color:#18419C!important;
border-radius:20px!important;
color: #fff;
}
.uagb-tax-link h6 {
position: absolute;
top: -80px;
color: #000;
}
<!-- language: lang-html -->
<div class="uagb-taxomony-box">
<a class="uagb-tax-link" href="https://dev3.netnerd.cat/tipus/desenvolupament-de-negoci/">
<h6 class="uagb-tax-title">Desenvolupament de negoci</h6>
" 16 Projectes "
</a>
</div>
<!-- end snippet -->
答案3
得分: 0
Here is the translation of the provided code:
根据https://stackoverflow.com/users/16948533/developer的建议,我需要在这里添加一个元素,以正确样式化无
标签的部分。
然后我使用了以下代码:
$('.uagb-tax-link').each(function() {
var $link = $(this);
var $textNodes = $link.contents().filter(function() {
return this.nodeType === 3;
});
var $span = $('<span class="text-no-h6"></span>').text($textNodes.last().text());
$textNodes.last().replaceWith($span);
});
然后CSS样式被修改为:
.uagb-taxomony-box {
background-color: transparent!important;
border: none!important;
text-decoration: none!important;
text-align: left!important;
}
a.uagb-tax-link h6 {
text-align: left!important;
}
span.text-no-h6 {
text-decoration: none!important;
padding: 5px!important;
background-color: #18419C!important;
border-radius: 20px!important;
}
Please note that the code itself remains in English, and only the comments and descriptions have been translated into Chinese.
英文:
As https://stackoverflow.com/users/16948533/developer has pointed I need to add a span here for properly style the no-h6 part.
Then i've used something like:
$('.uagb-tax-link').each(function() {
var $link = $(this);
var $textNodes = $link.contents().filter(function() {
return this.nodeType === 3;
});
var $span = $('<span class="text-no-h6"></span>').text($textNodes.last().text());
$textNodes.last().replaceWith($span);
});
And then css get's modyfied as:
.uagb-taxomony-box {
background-color:transparent!important;
border:none!important;
text-decoration:none!important;
text-align:left!important;
}
a.uagb-tax-link h6{text-align:left!important;}
span.text-no-h6{
text-decoration:none!important;
padding:5px!important;
background-color:#18419C!important;
border-radius:20px!important;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论