0

I have the following code:

<ul id="myList">
   <li class="li1">Example 1</li>
   <li class="li2">Example 2</li>
   <li class="li3">Example 3</li>
   <li class="li4">Example 4</li>
</ul>

Is there any way i can transform the list to:

<ul class="myList">
   <li class="li1"><div class="container">Example 1</div></li>
   <li class="li2"><div class="container">Example 2</div></li>
   <li class="li3"><div class="container">Example 3</div></li>
   <li class="li4"><div class="container">xample 4</div></li>
</ul>

using css only. without using javascript

3
  • thought so... currently i am using javascript to alter the html, however, i want it to work even if js is disabled on the browser. Does anyone know of an alternative way without using javascript then? Commented Aug 20, 2010 at 10:59
  • 1
    There's no way to add elements without JavaScript (can you not do this on the server?) If you're doing this for display purposes, take a look at the styling below...if that's not what you're after please comment what it doesn't do compare to what you're after. Commented Aug 20, 2010 at 11:03
  • my problem is, i have a list on a site, the contents of which is loaded dynamically(componenents developed by other users), i don't want them to bother with the container css, as that is applied by the admin (like dotnetnuke handles it). hence, i must be able to wrap the contents of the li with a container. but like i said, javascript should not be used Commented Aug 20, 2010 at 11:47

2 Answers 2

3

CSS cannot add elements, that really isn't its purpose.

That being said, you can achieve a similar effect by making the items display: block, like this:

#myList > li { display: block; }
Sign up to request clarification or add additional context in comments.

Comments

0

No. CSS is designed to instruct the browser on how elements look and are positioned. It isn't capable of editing the live HTML.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.