The problem
I cannot alter the way in whcih the HTML below is output, but I do need to amend the way in which it is displayed. I know I can achieve my desired results with jQuery
, but I'd like to do it with pure CSS
possible?
What exactly I need to do
I need to show the input
from the HTML below, but the label
itself is superfluous. The tag can stay or go, I'm not bothered by that, but Username
and <br>
need to be gone.
Obviousely I cannot use label[for="user_login"]{ display: none; }
, as this will fail because it will hide everything within the selector.
The original HTML
<label for="user_login">
Username
<br>
<input id="user_login" class="input" type="text" size="20" value="" name="log">
</label>
The desired HTML
<label for="user_login">
<input id="user_login" class="input" type="text" size="20" value="" name="log">
</label>
jQuery approach
$(document).ready(function(){
var username_label = $('label[for="user_login"]'),
username_input = username_label.find('input');
username_label.html(username_input);
});
Why I don't want to use jQuery
The login for in question is displayed differently depending on screen size. On smaller devices I requre the labels hidden (to save space), while on larger screens the label should still be visible. Using the jQuery approach will remove the labels in both cases.
While I know I can check the screen widht on load, and then use resize
event (if necessary), should the screen size change (on a tablet, portrait to landscape for example) the labels could be removed and then not visible when they need to be.
Question
Can I achieve this result (or similar) with pure CSS
?
` the space that they occupy is still taken above the `inptu`. If you know of a way to remove that I'd be greatful. Thanks. – David Gard Jan 07 '15 at 11:23