Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

set bg color to parent <LI> only?

Featured Replies

how do I set the bg color to a parent <LI> only

<style type="text/css">

* {
margin: 0;
padding: 0;
}

body {
padding: 50px;
}

ul#ddmenu, ul.sub1 {
list-style: none;
}

ul#ddmenu li {
border: solid 1px red;
width: 125px;
text-align: center;
position: relative;
float: left;
margin-right: 10px;
background: grey;
}

ul#ddmenu a {
text-decoration: none;
display: block;
width: 125px;
height: 25px;
line-height: 25px;
}

</style>

</head>

<body>

	<ul id="ddmenu">
		<li><a href="#">ABOUT US</a>
			<ul class="sub1">
				<li><a href="#">Company</a></li>
				<li><a href="#">Team</a></li>
				<li><a href="#">Careers</a></li>
			</ul>

		</li>
		<li><a href="#">OUR WORK</a>
			<ul class="sub1">
				<li><a href="#">Portfolio</a></li>
				<li><a href="#">Upcoming</a></li>
			</ul>
		</li>
		<li><a href="#">BLOG</a>
			<ul class="sub1">
				<li><a href="#">Blog</a></li>
			</ul>
		</li>
		<li><a href="#">PRODUCTS</a>
			<ul class="sub1">
				<li><a href="#">Websites</a></li>
				<li><a href="#">Add Ons</a></li>
			</ul>
		</li>
		<li><a href="#">CONTACT</a></li>
	</ul>		


</body>
</html>

The style ul#ddmenu li will style parent and sub levels unless you add a later style only for the sub-level:-

ul#ddmenu li {}/*all li levels*/
ul#ddmenu li li {} /*sub level which will be processed after the previous style and supersede it*/

ul#ddmenu li {}/*all li levels;*/
ul#ddmenu li li {float: left; width: ??px;} /*sub level which will be processed after the previous style and supersede it*/

Add the float to the parent li too, if you want those side by side.

 

You might have to add display: inline; in addition to float: left; but it isn't usually necessary.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.