Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - display: none; not working

Tags:

I'm trying to develop a mobile stylesheet and in this stylesheet I want to remove a particular div.

In the HTML code of the div, I place an id called "tfl", as shown below:

<div id="tfl" style="display: block; width: 187px; height: 260px; font-family: Verdana, Arial, Helvetica, sans-serif !important; background: url(http://www.tfl.gov.uk/tfl/gettingaround/journeyplanner/banners/images/widget-panel.gif) #fff no-repeat; font-size: 11px; border: 1px solid #103994; border-radius: 4px; box-shadow: 2px 2px 3px 1px #ccc;">             <div style="display: block; padding: 30px 0 15px 0;">                 <h2 style="color: rgb(36, 66, 102); text-align: center; display: block; font-size: 15px; font-family: arial; border: 0; margin-bottom: 1em; margin-top: 0; font-weight: bold !important; background: 0; padding: 0">Journey Planner</h2>                 <form action="http://journeyplanner.tfl.gov.uk/user/XSLT_TRIP_REQUEST2" id="jpForm" method="post" target="tfl" style="margin: 5px 0 0 0 !important; padding: 0 !important;">                     <input type="hidden" name="language" value="en" />                     <!-- in language = english -->                     <input type="hidden" name="execInst" value="" /><input type="hidden" name="sessionID" value="0" />                     <!-- to start a new session on JP the sessionID has to be 0 -->                     <input type="hidden" name="ptOptionsActive" value="-1" />                     <!-- all pt options are active -->                     <input type="hidden" name="place_origin" value="London" />                     <!-- London is a hidden parameter for the origin location -->                     <input type="hidden" name="place_destination" value="London" /><div style="padding-right: 15px; padding-left: 15px">                         <input type="text" name="name_origin" style="width: 155px !important; padding: 1px" value="From" /><select style="width: 155px !important; margin: 0 !important;" name="type_origin"><option value="stop">Station or stop</option>                             <option value="locator">Postcode</option>                             <option value="address">Address</option>                             <option value="poi">Place of interest</option>                         </select>                     </div>                     <div style="margin-top: 10px; margin-bottom: 4px; padding-right: 15px; padding-left: 15px; padding-bottom: 15px; background: url(http://www.tfl.gov.uk/tfl/gettingaround/journeyplanner/banners/images/panel-separator.gif) no-repeat bottom;">                         <input type="text" name="name_destination" style="width: 100% !important; padding: 1px" value="232 Kingsbury Road (NW9)" /><select style="width: 155px !important; margin-top: 0 !important;" name="type_destination"><option value="stop">Station or stop</option>                             <option value="locator">Postcode</option>                             <option value="address" selected="selected">Address</option>                             <option value="poi">Place of interest</option>                         </select>                     </div>                     <div style="background: url(http://www.tfl.gov.uk/tfl/gettingaround/journeyplanner/banners/images/panel-separator.gif) no-repeat bottom; padding-bottom: 2px; padding-top: 2px; overflow: hidden; margin-bottom: 8px">                         <div style="clear: both; background: url(http://www.tfl.gov.uk/tfl-global/images/options-icons.gif) no-repeat 9.5em 0; height: 30px; padding-right: 15px; padding-left: 15px"><a style="text-decoration: none; color: #113B92; font-size: 11px; white-space: nowrap; display: inline-block; padding: 4px 0 5px 0; width: 155px" target="tfl" href="http://journeyplanner.tfl.gov.uk/user/XSLT_TRIP_REQUEST2?language=en&amp;ptOptionsActive=1" onclick="javascript:document.getElementById('jpForm').ptOptionsActive.value='1';document.getElementById('jpForm').execInst.value='readOnly';document.getElementById('jpForm').submit(); return false">More options</a></div>                     </div>                     <div style="text-align: center;">                         <input type="submit" title="Leave now" value="Leave now" style="border-style: none; background-color: #157DB9; display: inline-block; padding: 4px 11px; color: #fff; text-decoration: none; border-radius: 3px; border-radius: 3px; border-radius: 3px; box-shadow: 0 1px 3px rgba(0,0,0,0.25); box-shadow: 0 1px 3px rgba(0,0,0,0.25); box-shadow: 0 1px 3px rgba(0,0,0,0.25); text-shadow: 0 -1px 1px rgba(0,0,0,0.25); border-bottom: 1px solid rgba(0,0,0,0.25); position: relative; cursor: pointer; font: bold  13px/1 Arial,Helvetica,sans-serif; text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.4); line-height: 1;" />                     </div>                 </form>             </div>         </div> 

This code is not mines as this an embedded code given by the TFL website.

I want to hide this div to make it more friendly for a mobile user, I did:

#tfl { display: none; } 

This code doesn't work me though, and I even applied to the corresponding header before it and that didn't work, as shown again:

h3.tfl { display: none; } 

What's the issue here? This code worked on another page on a mapped image. (I can't use jQuery nor JavaScript (uni assingment looking at CSS)).

like image 681
RoyalSwish Avatar asked Dec 18 '13 16:12

RoyalSwish


People also ask

How do I show display none in CSS?

getElementById("element"). style. display = "none"; To show an element, set the style display property to “block”.

What does CSS display none do?

display: none; is commonly used with JavaScript to hide and show elements without deleting and recreating them.

Does display none still load?

Images or wrapper elements that have display: none set, will still get loaded. So if you want to eg. load a different image for desktop and mobile, you can either: use display: none , but with the loading="lazy" parameter set on img .

What is the opposite of display none in CSS?

There is no opposite, they all are the opposite.


2 Answers

This is because the inline style display:block is overriding your CSS. You'll need to either remove this inline style or use:

#tfl {   display: none !important; } 

This overrides inline styles. Note that using !important is generally not recommended unless it's a last resort.

like image 128
Brian Phillips Avatar answered Sep 23 '22 16:09

Brian Phillips


Remove display: block; in the div #tfl style property

<div id="tfl" style="display: block; width: 187px; height: 260px; 

Inline styles take priority over an external CSS file.

like image 38
Vinay Pratap Singh Bhadauria Avatar answered Sep 19 '22 16:09

Vinay Pratap Singh Bhadauria