0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【備忘録】inputタグに必須マークをつけるCSS

Posted at

はじめに

inputタグにつけるlabelタグに必須マークをつけるCSSの 備忘録 です。

スクリーンショット

・参考記事リンクでは必須マークが下にずれてしまいますが、
この記事では縦方向の中央に揃えています。

image.png

必須マークのコード

.required {
  position: relative;
}

.required::after {
  content: "必須";
  background-color: #f0ad4e;
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  min-width: 10px;
  padding: 3px 7px;
  margin: 0px 5px;
  line-height: 1;
  white-space: nowrap;
  text-align: center;
  border-radius: 10px;
  display: inline-block;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: -50px; /* 必要に応じて調整 */
}
<label htmlFor="deploy-url" className="font-bold text-xl required">デプロイ先URL</label>

さいごに

参考にさせていただいた記事のリンクです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?