Language Specific CSS Selectors

The site that I am working on is bilingual, specifically in english and in spanish. This presents complications for any site of course, so this is a good trick to have in your arsenal. This is especially good for Drupal but will work on any site.

media=”screen”

:lang(es) #menu-4184-1

{
position:relative;
width: 122px;
}
This will allow the particular selector to be used only when the language is set to spanish. Please note that many other languages can be used by this by replacing the two letter language code with the one that you need. EI – de for german.

Advanced CSS Selectors and Drupal

Drupal can be difficult to override at times in terms of styling unless you place your intercepts in a submodule’s PHP so creative CSS knowledge and implementation is a must to keep your site from looking “too Drupaly”.

One CSS technique that I have been using a bit lately that you don’t usually run into in systems where the HTML is more easily customizable is the title attribute selector. Warning – this is really a hack. But I think that it deserves a place in any Drupal Developer’s toolkit.

The title attribute looks like this:

a[title~=Request]{

/*css stuff goes here*/

}

This selector targets hyperlinks (a) that have a title that contains the word Request (case sensitive too). This selector will add whatever you add in the following curly brackets. There are other options too. See the w3s link at the bottom.

Image

The SS is really two SSs: one with the selector disabled so you see the element and one with it turned on. The element that needs to disappear is a link to the /user/password page. For whatever reason (this is Drupal and sometimes it takes so long to figure out the mystery that it becomes a Pyrrhic victory as the deadline is missed) this link will take you to a place where the UX sucks. The workaround is pretty easy though. Use the Password reset form and hide the link using CSS. But since the link has nothing special in its selectors that gets tough. So, use the title attribute selector. The green box in the SS is the form for passwords, BTW.

http://www.w3schools.com/css/css_attribute_selectors.asp

Advanced CSS Selectors for Drupal – Page class tied to low level IDs

Customizing Drupal content placement can be tricky. If you have a piece of content

Image

that appears in more than one area, you may need flexibility in your CSS to style the elements independently of one another.

What has worked well for me is CSS selectors that utilize the cascading nature of CSS for advanced

In the SS, you can see that the selector combined a class and an ID. The ID is for the individual node, in this case an amazon book ad generated externally, and the class is for the page itself. It’s important to note that the selector will work as long as the two selectors are in the same hierarchy. I could just use the ID but that is assigned to the individual node and that node appears (may or may not, hard to tell with Drupal) in other areas. Style by the ID, fix one, break the other. But, using the class of the page and the ID of the node allows an easy to find hierarchy that will cascade every time for that page and will only hit that element on that page. So unless you have the same node twice on the same page, this will always allow consistent styling  selection.

CSS for Mobile/Responsive Design – IE Hacks

I’m testing on IE11, which is supposed to be standards compliant. And it is, except when it isn’t. Here is a great example of a hack that I had to use to make some sweet JQuery Superfish menu items behave in IE11.

#superfish-1 {
font-size: 98.9%;
float: left;
margin: -75px -86px 15px;
padding: 0 0 7px 58px;
position: relative;
}
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
/* IE10-specific styles go here */
#superfish-1 {
font-size: 93%;
float: left;
margin: -77px -86px 15px;
padding: 0 0 7px 58px;
position: relative;
}
}

CSS for Mobile – IE Hacks

I’m testing on IE11, which is supposed to be standards compliant. And it is, except when it isn’t. Here is a great example of a hack that I had to use to make some sweet JQuery Superfish menu items behave in IE11.

#superfish-1 {
font-size: 98.9%;
float: left;
margin: -75px -86px 15px;
padding: 0 0 7px 58px;
position: relative;
}
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
/* IE10-specific styles go here */
#superfish-1 {
font-size: 93%;
float: left;
margin: -77px -86px 15px;
padding: 0 0 7px 58px;
position: relative;
}
}

Styling Drupal Table Columns

Tables can be a pain. And they can be quite a bit of pain when they are used in Drupal. I used Advanced Forum and am pretty happy with it. But there are some margin issues that really don’t seem to lend themselves to easy fixing via CSS.

Image

I need to expand the Forum Title Column. To do this easily and effectively in Drupal, I choose the corresponding column header and expand that. This will also expand the entre

column below. Look to the examples that are illuminated in yellow. This makes it much easier to add space to an area that needs it, like a title while leaving a # visits smaller.

Mobile Testing – Free Tools

Here is another site that will provide you with many options for styling your site at several different screen widths/heights. What I really like about this site is that it shows so many resolutions on one page.

While this will be more of a distraction (info overload) if you are just starting to style a site for mobile devices, it is really nice once you have most of the changes in place and want to see what the site looks like on a wide variety of devices at a glance.

http://www.responsinator.com

Drupal Panel Pages, CSS and Mobile Tip

If you use Panels for your layouts, add a column CSS class to the most left hand column of your layout. Since Adaptive Themes will place this column first after the header stuff, this class will more easily allow you to adjust the margins of your content relative to the header.

You’ll need to add a custom style to the column in the Page Manager layout. If you choose no stylistic choices at all you will wind up with something like this selector:

.region-plain-box-fp-25-left-col {
  1. background-color: #ffffff;
  2. color: #000000;
  3. margin-bottom: 10px;
  4. padding: 10px;

}

Note that the Administrative title (so that it can be reused) that I have used will show in the selector. Since I have added this late in the development, I have to adjust it to the current style of my page.
.region-plain-box-fp-25-left-col {
  1. background-color: rgba(0, 0, 0, 0);
  2. color: #000000;
  3. margin-bottom: 0;
  4. padding: 0;
  5. margin-top: -59px;
}
 I have added the Margin-top parameter to move all the content closer to the header for the 320px width layout. Sort of a hack, but a really useful one!

Customizing Drupal Confirmation Pages

If you use Panels Pages for the bulk of you site building, you may have noticed that there are frequent limitations on some of the more random pages.

Image

An example is the comment confirmation delete form. I don’t need much on this form, the stock info is fine, but I want to add my logo at least. I don’t use the logo function that Drupal provides standard, I implement it with my own CSS.

On the form, I use the background element on the #node-confirmation-form ID to add the logo via the CSS shown in the SS. But since that places the background right underneath the form text, I have to tweak it a bit to move things around so that they look OK. I ended up using a combination of height, top, padding and relative positioning. I really just had to experiment until I got it right.

This is not the best approach, but it is a good quick and dirty way to customize a form strictly through CSS when Page Manager doesn’t offer to intercept it for you.

CSS Tip – Customize without Theme Intercepts

A thorough knowledge of CSS is a must for customizing a layout using Drupal. Today, I needed to move an input field on a form. The issue is that the field shares its Drupal defined selector class with several other fields of the same type on other forms. Fix one form by the selector, break the same field on a different form.

Image

By using the CSS ID of the parent form, (which is several divs up in the HTML) and inserting a space in between the ID and the class selector, I can zero in on the particular field that I want. The other way that this would have to be done is via an intercept at the theme level, which would be more involved and require subtheming, PHP and a TPL file. Using the two selectors together is easier for someone who doesn’t want (or know how to) take that approach.