Archive for category CSS
Centering a Blazored.Modal window
Posted by scottstoecker in Blazor, CSS on May 26, 2021
I had a modal window in Blazor using the Blazored.Modal component. From that modal window, I needed to open another modal window. The problem was the “sub-modal” window was expanding to the full width of the parent modal and took the margin-top value of the parent as well. It didn’t look well:
To get around this, I defined a new stylesheet specifically for the modal classes in the wwwroot\css folder called Modal.css. In it, I added the classes that would define my modal styles. (You could just do this in an existing stylesheet as well.)
.coaster-modal {
float: none;
margin-left: auto;
margin-right: auto;
margin-top: -150px;
max-width: 500px;
text-align: center;
left: 40%;
right: 40%;
}
In the _Host.cshtml, I added a link to the stylesheet:
<head>
...
<link href="~/css/Modal.css" rel="stylesheet" />
</head>
In the parent modal window, I had defined the method that opened the modal window when I clicked a button. It is in this method where I tell the child modal how to be styled by setting a ModalOptions object and settings the Position to “Custom” and the PositionCustomClass to the CSS class I defind, “coaster-modal”:
async Task ShowCoasterModal()
{
var parameters = new ModalParameters();
var options = new ModalOptions()
{
Position = ModalPosition.Custom,
PositionCustomClass = "coaster-modal"
};
parameters.Add("CoasterId", coasterId);
var coasterModal = Modal.Show<CoasterModal>("Edit Coaster", parameters);
var result = await coasterModal.Result;
if (!result.Cancelled)
{
// Do Stuff
}
}
Much better:
Highlight a parent “row” of DIVs with CSS
Posted by scottstoecker in CSS on October 3, 2018
The bad news is that CSS doesn’t actually have a parent operator, so you can’t specifically get a reference to that parent. However, you can work around this.
I was working with a third-party component which created a table using DIV tags, not an actual HTML table with <tr> and <td> elements. So the usual method of using tr:hover wouldn’t work. Instead, I had to work with nested DIV tags. And these DIV tags would have certain classes associated with them, depending on the hierarchy, like so:
OneTwo</div>So the CSS for this to highlight the row is:
div.row:hover > div.cell{ background-color: #008EC6; }If you instead wanted to just highlight the row, then this would be the CSS:
div.row> div.cell:hover { background-color: #008EC6; }
Expand a DIV width beyond its parent
Posted by scottstoecker in CSS on February 7, 2017
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.
IE and the CSS margin-top tag
Posted by scottstoecker in CSS on September 30, 2015
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.
li hover styling in HTML
Posted by scottstoecker in CSS, HTML on October 18, 2014
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:
That’s pretty ugly regardless of the color scheme. So remember, keep the styling outside of the <li> to get the hover effect working.
Recent Comments