Inline “required” asterisk in Laravel form label

2019-07-19 08:49发布

I'm trying to add a red asterisk for my required fields in Laravel, but I'm not sure how to add them inline with the label.

What I'm doing currently is

{{ Form::label('took_act_or_sat' , 'Did you or will you take the SAT or ACT?' ) }} <span style="color: red">*</span>

but when the label wraps to a second line, for some reason the asterisk is being bumped an extra line down.

asterisk

So I guess the first part of my question is: Can you add inline styling to a form label in Laravel?

And the second part is: Is there another way I should be going about adding the asterisk (or other marker) so that this wouldn't be an issue?

If it's relevant, I'm also using Bootstrap for the majority of my styling if that also affects anything.

4条回答
太酷不给撩
2楼-- · 2019-07-19 08:59

Add a class to your label with the third parameter

{{ Form::label('took_act_or_sat' , 'Did you or will you take the SAT or ACT?', array('class' => 'required') ) }}

And add asterisk with css

<style>
    .required:after{ 
        content:'*'; 
        color:red; 
        padding-left:5px;
    }
</style>
查看更多
冷血范
3楼-- · 2019-07-19 08:59
{{ Form::label('took_act_or_sat' , 'Did you or will you take the SAT or ACT? <span style="color: red">*</span>','',false ) }} 

All you need is false as parameter.

查看更多
Root(大扎)
4楼-- · 2019-07-19 09:08

There are multiple ways to achieve this. if you want to achieve required result without changing your HTML code then you can add some style to your span elemnt as follows

Code

{{ Form::label('took_act_or_sat' , 'Did you or will you take the SAT or ACT?' ) }} <span style="color: red; display:block; float:right">*</span>
查看更多
叛逆
5楼-- · 2019-07-19 09:08

Try this

<label for="took_act_or_sat">Did you or will you take the SAT or ACT? <span style="color: red">*</span></label>
查看更多
登录 后发表回答