text wrapping incorrectly for radio button

2020-06-09 04:17发布

I have 2 html radio buttons (separated by <br /> tags) where the text is wrapping under the radio button instead of aligning with the left indent (due to the size it's containing div). The text wrapping is not the problem, the problem is that it is wrapping incorrectly under the radio button itself, instead of aligning with text in the line above it. I'm supposing someone styled the input tag somewhere in the cascade. I haven't done an exhaustive search of all the styles attached to this page, but shouldnt the text just automatically wrap correctly, like a bullet list?
enter image description here

And if not, how would i go about fixing this? Do i need to insert a <br /> tag where I want the lines to break so they will be properly aligned?

Thanks!

4条回答
虎瘦雄心在
2楼-- · 2020-06-09 04:34

You can simply use CSS to force the text to wrap correctly. I'm assuming that you have a <span> tag around the text and so you can use the following to adjust its position:

span {
  display: block;
  margin-top: -16px;
  margin-left: 28px;
}

Hope that this helps! Tomer

查看更多
兄弟一词,经得起流年.
3楼-- · 2020-06-09 04:43

Answer for 2015:
Since none of the other soultions worked for me, here's how I do it:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Radiobutton labels aligned</title>
<style type="text/css">
    div { display:table-row; }
    div span { display:table-cell; vertical-align:middle; } /* You can omit the entire span if you don't want the radiobutton vertically centered */
    div label { display:table-cell; }   
</style>
</head>
<body>
<form>
<div>
    <span><input type="radio" id="a"></span>
    <label for="a">First button's label<br>First button's label</label>
</div>
<div>
    <span><input type="radio" id="b"></span>
    <label for="b">Second button's label</label>
</div>
<input type="radio" id="c"><label for="c">For comparison: Standard-Label</label>
</form>
</body>
</html>

See http://jsfiddle.net/8jzss08p/
Works in: Firefox 41, Chrome 45, Internet Explorer 11

查看更多
一纸荒年 Trace。
4楼-- · 2020-06-09 04:51

Sorry for answering this so late, I just came across this post, here's another solution :

p { margin-left: 20px; text-indent: -20px; }
查看更多
别忘想泡老子
5楼-- · 2020-06-09 04:53

First of all, the use of a <br /> is generally not recommended, it's a lot better to try and use the margin CSS property to create space between elements.

It's also best in this situation to use CSS to do what you want to do. This is because by default those elements won't have this kind of behaviour.

In this case you would want something that looks like this:

<div style="width:300px">
    <input type="radio" class="radioLeft" />
    <div class="textBlock">
        Some text that is too long to fit inline and must be broken 
        up over multiple   lines.Some text that is too long to fit inline 
        and must be broken up over multiple lines.Some text that is too 
        long to fit inline and must be broken up over multiple lines.
    </div>
    <div style="clear:both;"></div> //this is important for repeated inputs
</div>

And then your CSS would look like this:

.radioLeft
{
   float: left;
}

.textBlock
{
    float: left;
    width: 80%; //Adjust this value to fit
}
查看更多
登录 后发表回答