久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

CSS選擇器用于選擇另一個元素之前的元素?

CSS Selector for selecting an element that comes BEFORE another element?(CSS選擇器用于選擇另一個元素之前的元素?)
本文介紹了CSS選擇器用于選擇另一個元素之前的元素?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在為我的網站創建一個登錄頁面,我想在文本框獲得焦點時將輸入框之前的標簽加粗.現在我有以下標記:

I'm working on a login page for my website and I want to bold the label that comes before the input box when the text box gains focus. Right now I have the following markup:

<label for="username">Username:</label>
<input type="textbox" id="username" />

<label for="password">Password:</label>
<input type="textbox" id="password" />

我可以使用相鄰選擇器選擇標簽after文本框,但我不能選擇它之前的元素.我可以使用這個 CSS 選擇器規則,但它只選擇后面的標簽,所以當用戶名文本框獲得焦點時,密碼標簽變為粗體.

I can use the adjacent selector to select the label after the text box, but I can't select the element before it. I can use this CSS selector rule, but it only selects the label after, so when the username text box gains focus, the password label becomes bold.

input:focus + label {font-weight: bold}

我能做些什么來完成這項工作嗎?我知道 JavaScript 可以很容易地做到這一點,但如果可能的話,我想使用一個純基于 CSS 的解決方案,我只是想不出辦法.

Is there anything I can do to make this work? I know JavaScript could be used to easily do this, but I'd like to use a purely CSS-based solution if possible, I just can't figure out a way to do it.

推薦答案

如果 inputlabel 之前,則可以使用相鄰兄弟選擇器".只需將 input 放在 label 之前,然后修改布局將 label 放在 input 之前.這是一個例子:

It would be possible to use the 'adjacent sibling selector' if the input was before the label. Just put the input before the label, and then modify the layout to put label before the input. Here's an example:

<head runat="server">
    <title></title>
    <style type="text/css">
    input:focus + label {font-weight: bold}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div style="direction:rtl">
        <input type="text" id="username" />
        <label for="username">Username:</label>
    </div>
    <div style="direction:rtl">
        <input type="password" id="password" />
        <label for="password">Password:</label>
    </div>
    </form>
</body>

(這是一種 hack,我個人會使用 javascript 來做到這一點)

(It's kind of a hack, I would personally use javascript to do this)

input:focus + label {font-weight: bold}

<form id="form1" runat="server">
  <div style="direction:rtl">
    <input type="text" id="username" />
    <label for="username">Username:</label>
  </div>
  <div style="direction:rtl">
    <input type="password" id="password" />
    <label for="password">Password:</label>
  </div>
</form>

這篇關于CSS選擇器用于選擇另一個元素之前的元素?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Style every third element?(每隔三個元素設置樣式?)
Why shouldn#39;t I use ID selectors in CSS?(為什么我不應該在 CSS 中使用 ID 選擇器?)
What does img[class*=quot;alignquot;] mean in CSS?(CSS 中的 img[class*=“align] 是什么意思?)
CSS: Last element on line(CSS:最后一個元素)
How do I select every other div class element using just CSS (no js)(如何僅使用 CSS(無 js)選擇所有其他 div 類元素)
Tool for checking unused CSS selectors?(檢查未使用的 CSS 選擇器的工具?)
主站蜘蛛池模板: 91麻豆精品一区二区三区 | 99热这里只有精品8 激情毛片 | 午夜影院网站 | 天天操网 | 欧美一区精品 | 国产精品久久久久久久久久久新郎 | 成人国产精品视频 | 狠狠骚| 日韩色综合 | 精品国产一区三区 | 日韩国产中文字幕 | 精品视频一二区 | 一区二区三区视频 | 日本精品在线播放 | 91在线电影 | 成人一区二区三区 | 国产日韩欧美中文字幕 | 操到爽 | 欧美区在线| 国产精品日本一区二区不卡视频 | 久久久久91 | 国产精品高潮呻吟久久aⅴ码 | 中文字幕视频在线 | 玖玖综合网 | 午夜国产一级片 | 男女又爽又黄视频 | 欧美不卡在线 | www日本在线播放 | 毛片久久久 | 久久久久亚洲精品 | 96av麻豆蜜桃一区二区 | 国产超碰人人爽人人做人人爱 | 亚洲精品中文字幕在线观看 | www久久久 | 99久久视频 | 91九色porny首页最多播放 | 成人午夜电影在线观看 | 日韩电影a| 久久精品国产亚洲一区二区三区 | 亚洲导航深夜福利涩涩屋 | 男人阁久久 |