2

here's the code (and, yes, i'm using a basic reset.css):

.checkbox { border: 1px solid black; width: 10px; height: 10px; }

<ul>
    <li>
        <p><div class="checkbox"></div>I will!</p>
    </li>
    <li>
        <p><div class="checkbox"></div>I won't!</p>
    </li>
</ul>

you can see what i'm trying to do. essentially create a checkbox. the reason i'm NOT using a checkbox tag is because i have to export this thing to PDF so that it can be printed and hamfisted bogots can drag their X mark through the box. if i use the checkbox tag, it's too small. if i use and image, PDF doesn't line up right.

so. i need the CSS box to line up as expected. what am i missing? i've tried changing the div to display: inline; but it freakin' disappears! inline-block useless.

i tried like mad to search this one out, but to no avail, so if this showed up somewhere else, apologies.

WR!

1
  • display: inline-block; seems to work for me: jsfiddle.net/xEtEK/2 in Chrome/Mac. What browser are you using? Commented Oct 25, 2011 at 19:55

7 Answers 7

7
.checkbox { 
    border: 1px solid black; 
    width: .65em; 
    height: .65em; 
    display: inline-block;
    margin-right: 4px;
}

See it working here: http://jsfiddle.net/ZeaLM/

Sign up to request clarification or add additional context in comments.

5 Comments

You shouldn't be using <p> inside of a <div>, as that might cause unexpected results in different browsers (the code is invalid as <p> is not permitted to contain any block-level elements).
Since when is using a <p> inside a <div> a bad thing? Also, I am not using a <p> inside a <div> and finally I was just modifying the CSS portion of his original code.
It's the other way around; <div> inside <p> is invalid html.
thanks. combined with @Inerdia's comment, i got it working. thanks. i often forget to use good ol' &nbsp instead of empty space.
@jessegavin yes, I meant it the other way around, sorry about that :P
0

inline-block is the display you need for this.

4 Comments

Hopefully WhiteRau will explain why it didn't work, since it's what I've always used for this kind of situation (inline box of defined width/height) and it's always worked for me.
And works in this case (see my comment on the question) – so I'm guessing the problem is somewhere else.
@Truth there have been many times when I make unorderlist navigation I have to use inline-block. Very useful.
I know how and when to use inline-block, OP stated it didn't work for him that's all.
0

Your browser might be persnickety about empty elements. Try adding a &nbsp; into the <div>.

Comments

0

<div> is not allowed inside of <p> elements (which doesn't allow any block-level elements inside of it).

See this example

In this example, I've used display: inline-block; and changed the <p> element into a <div>.

Comments

0

There's many ways to do it, one of which is this

Comments

0

Just to make sure - did you put the .checkbox selector inside a <style> tag in the actual HTML?

<style type="text/css">
    .checkbox { border: 1px solid black; width: 10px; height: 10px; }
</style>

Comments

0

1) Get rid of the <p> elements

2) Add float: left to your .checkbox style

3) Add &nbsp; after the div or a padding: right to the div block to make it look better

4) Add li { list-style-type: none; } in your style block

5) Play around with vertical-align in your .checkbox style until you're happy

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.