简体   繁体   中英

Horizontal alignment of table rows with CSS or JavaScript

I am stuck with my companies CRM for creating surveys. I can customize the JavaScript and CSS of the survey but not the junk HTML code it puts out.

I am trying to get answers for a survey question laid out as a range.

Example:

一系列答案的示例

But I can't seem to target the answers in order to either apply a display: inline attribute or a float: left attribute.

See the HTML code which I cannot edit below.

<div class="QuestionContainer"
    id="cont_id_f_6b97f5812768e81180f1005056a85b23" questionIndex="12">
    <table cellpadding="0" cellspacing="0">
        <tr style="font-family:Verdana; font-size:13px; color:#000000;">
            <td class="alignTop"><input
                    id="multioption0_6b97f5812768e81180f1005056a85b23"
                    name="multioption0_6b97f5812768e81180f1005056a85b23"
                    type="radio"
                    value="1 - Not at all satisfied"
                    onclick="ShowOneRadio(this);" />
            </td>
            <td class="alignTop">1 - Not at all satisfied</td>
        </tr>
        <tr style="font-family:Verdana; font-size:13px; color:#000000;">
            <td class="alignTop"><input
                    id="multioption1_6b97f5812768e81180f1005056a85b23"
                    name="multioption1_6b97f5812768e81180f1005056a85b23"
                    type="radio"
                    value="2 - Somewhat satisfied" onclick="ShowOneRadio(this);"
                    />
            </td>
            <td class="alignTop">2 - Somewhat satisfied</td>
        </tr>
    </table>
</div>
.QuestionContainer tr {
    float:left;
}

Probably you would also want to add a margin to it, like margin: 10px or so.

Flex box is awesome i'd suggest looking at its api

https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox

If you have access to change the HTML i would as the markup you've used is very verbose for what you're trying to achieve.

please let me know if you have any questions

 .QuestionContainer { width: 100%; } .QuestionContainer tbody { display: flex; flex-direction: row; } tr { padding: 10px; } tr:nth-of-type(odd) { background: #ccc; } 
 <div class="QuestionContainer" id="cont_id_f_6b97f5812768e81180f1005056a85b23" questionIndex="12"> <table cellpadding="0" cellspacing="0"> <tr> <td class="alignTop"> <input type="radio" value="1 - Not at all satisfied" onclick="ShowOneRadio(this);" /> </td> <td class="alignTop">1 - Not at all satisfied</td> </tr> <tr> <td class="alignTop"><input type="radio" value="2 - Somewhat satisfied" onclick="ShowOneRadio(this);" /> </td> <td class="alignTop">2 - Somewhat satisfied</td> </tr> <tr> <td class="alignTop"> <input type="radio" value="1 - Not at all satisfied" onclick="ShowOneRadio(this);" /> </td> <td class="alignTop">3 - Not at all satisfied</td> </tr> <tr> <td class="alignTop"> <input type="radio" value="2 - Somewhat satisfied" onclick="ShowOneRadio(this);" /> </td> <td class="alignTop">4 - Somewhat satisfied</td> </tr> </table> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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