简体   繁体   English

在锚点内插入一个 div,删除 div 元素中的锚点样式

[英]Insert a div inside an anchor removing the anchor styling in the div elements

I'm trying to make the whole div clickable, but removing any styling that the anchor adds to the div.我试图使整个 div 可点击,但删除锚添加到 div 的任何样式。 I cannot use JS for this.我不能为此使用 JS。

HTML code HTML代码

<a href="https://stackoverflow.com" target="_blank">
  <div class="style1">
    <div class="style2">
      <div class="style3_">
        <div>
          <div class="text1">
            Here is the Text 1
          </div>
          <span class="text2">
            Here is the text 2
          </span>
        </div>
        <a href="https://stackoverflow.com" target="_blank">
          Link
        </a>   
      </div>
   </div>
  </div>
</a>

CSS code: CSS 代码:

.style1 {
  padding: 16px;
}

.style2 {
  border-radius: 8px;
  background-color: #fff;
  border: 1px solid #dadce0;
  box-shadow: none
}

.style3 {
  display: flex;
  padding: 16px;
  justify-content: space-between;
  align-items: center;
}

.text1 {
  line-height: 1.5rem;
  font-size: 1rem;
  letter-spacing: .00625rem;
  font-weight: 500;
}

.text2 {
  line-height: 1rem;
  font-size: .75rem;
  letter-spacing: .025rem;
  font-weight: 400;
}

a tags usually adds an underline to indicate that it is a link, that's actually just a text decoration, to remove that you can add text-decoration: none; a标签通常会添加一个下划线来表示它是一个链接,这实际上只是一个文本装饰,删除它可以添加text-decoration: none; to whatever class you want the style to be removed, or you can add that to the anchor tag directly.到您希望删除样式的任何 class ,或者您可以直接将其添加到锚标记。 See the snippet below for your reference:请参阅下面的代码段供您参考:

 .style3 { display: flex; align-items: center; justify-content: space-between; border-radius: 8px; background-color: #fff; border: 1px solid #dadce0; box-shadow: none; padding: 16px; width: max-content; gap: 2rem; }.text1 { line-height: 1.5rem; font-size: 1rem; letter-spacing: .00625rem; font-weight: 500; }.text2 { line-height: 1rem; font-size: .75rem; letter-spacing: .025rem; font-weight: 400; } a{ text-decoration: none; color: black; flex: 1; height: 100%; }
 <a href="https://stackoverflow.com" target="_blank"> <div class="style3"> <div> <div class="text1"> Here is the Text 1 </div> <span class="text2"> Here is the text 2 </span> </div> <div> Link </div> </div> </a>

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

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