Archive for category CSS

Expand a DIV width beyond its parent

I had an issue where a content management system restricted the layout of the page to have three columns. I wanted the results of a search, which were displayed in a div tag, to expand to fill (almost) the entire width of the screen. After just a bit of tweaking with padding and width, I ended with this:

<div id=”results” style=”margin-left: calc(-50vw + 50%);padding-left: 15px; width: 98vw; “></div>

Note that your mileage may vary. This particular code worked with the arrangements of elements in my page, and I have not tested it thoroughly enough to say it would work in all instances.

Leave a comment

IE and the CSS margin-top tag

Oh, the joy of web design. Chrome was behaving as it should, but Internet Explorer 11 wasn’t. I had a header div element on my body, but the background from the main page was showing above the header. I was using a negative margin along the top, like so:

 margin-top: -10px;

What worked for me was modify the units for the margin-top statement to “vh” instead of “px”:

 margin-top: -1.4vh;

This did throw off the Chrome alignment slightly, and it wasn’t exactly vertically centered as it was before, but it was pretty close, and I was happy enough with the result to not throw things at the screen.

Leave a comment

li hover styling in HTML

To create a hover effect on <li> elements (you know, all those elements inside a <ul>), style the elements in the style block in the HTML page header, like so:

<style type=”text/css”>

     li div {height: 50px; width: 150px; background-color: green;}

     li div:hover {background-color: blue;}

</style>

The HTML portion looks like this:

<ul>

     <li><div>Room 1</div></li>

     <li><div>Room 2</div></li>

     <li><div>Room 3</div></li>

</ul>

 

(I have other styling that I have removed. If I was just using text, I wouldn’t have used a div.)

The first time I tried to add a hover effect, I had the styling on the element and not in the style block:

 

     <li><div style=”height: 50px; width: 70px; background-color: green”>Room 1</div></li>

 

This didn’t turn out right, though. The first  row looked funky when I hovered over it:

li hover1

That’s pretty ugly regardless of the color scheme. So remember, keep the styling outside of the <li> to get the hover effect working.

Leave a comment