Selecting a div without a .Class or #Id - javascript

For some reason, it is much easier for me if it is possible to select all the divs that match a particular set of similar style attributes.
Example of div that I want to select
<div style="background-image: url(http://localhost/website/images/template/markers/cluster.png); height: 34px; line-height: 34px; width: 34px; text-align: center; cursor: pointer; color: rgb(255, 255, 255); position: absolute; font-size: 12px; font-family: Arial, sans-serif; font-weight: bold; top: 78.15521871251985px; left: 725.3256078213453px; background-position: 0px 0px; ">15</div>
Other than this div, other divs that needs to be selected can be similar to this one, but with say different height and top left positions. However, the good thing is that the background-image url() remains the same.
How can this selection be made with jQuery? Thank you !!
EDIT
Surrounding Code
Easier to provide a screencap

I don't think it's a good idea, but you can select elements by specific inline style with this:
$('div[style*="height: 34px"]')
Example

Related

Underline blank rows area in handlebars

Using HandlebarsJS
I have a blank area with with dynamic content rendered. When text is not reaching min-height the content must contain empty underlined blank rows.
I tried using a background image in css like follows:
.regimul-juridic {
/*background-color: red;*/
margin-top: -5px;
min-height: 100px;
position: relative;
background-position: fixed;
line-height: 18px;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAASAQMAAACgmSb/AAAABlBMVEUAAAAAAASiCn3WAAAAAXRSTlMAQObYZgAAAAtJREFUCNdjIAwaAACkAIHWnJmDAAAAAElFTkSuQmCC);
backdrop: static;
}
.regimul-juridic > p {
color: #000000;
font-weight: normal;
font-size: 9px;
margin-top: 0 !important;
margin-bottom: 0 !important;
}
but without success, because if there is more content on the area above the image will not expand properly. Does anyone have a solution ?
Picture showing what I am trying to achieve here:
For the underline you can use hr tags in the html

Apply styling only on the text inside a DIV

I'm having a div in HTML which is dynamically creating from the server side. I want to apply css in HTML(front-end) only on that div if and only if its having some-content. If it doesn't have any content then I have no need to apply the new styling.
The sample of HTML code is:
<div class="attr-marker">
Some-text-content <!-- Apply New Styling on it -->
</div>
<div class="attr-marker">
<!-- No need of new styling -->
</div>
<div class="attr-marker">
<!-- No need of new styling -->
<i class="fas fa-car" style="color:#d42424;font-size:px"></i>
</div>
And the CSS which I tried but failed is:
.attr-marker text {
display: block;
width: 12px;
height: 12px;
border-radius: 50%;
line-height: 12px;
font-size: 9px;
text-align: center;
background: #000;
color: #fff;
}
I can achieve it by using javascript but I want purely CSS solution so it'll help me to minimize the code.
You can set default style for empty div by using :empty pseudo selector. And then for regular div, just set the style as given above.
Or you can use :not(:empty) Pseudo Selector to set the style for the div that is not empty.
Here's an example:
.attr-marker:not(:empty) {
display: block;
width: 12px;
height: 12px;
border-radius: 50%;
line-height: 12px;
font-size: 9px;
text-align: center;
background: #000;
color: #fff;
}
Let me know in case you have any questions.
Regards,
AJ
You can use the :empty pseudo-class. However your server will need to output the .attr-marker div with no whitespace.
Like...
<div class="attr-marker"></div>
not
<div class="attr-marker">
</div>
And then the css would be,
.attr-marker:empty {
display: block;
width: 12px;
height: 12px;
border-radius: 50%;
line-height: 12px;
font-size: 9px;
text-align: center;
background: #000;
color: #fff;
}
Additional reading, https://developer.mozilla.org/en-US/docs/Web/CSS/:empty
Writing .attr-marker text { } means you want to access child elements with tag text of class attr-maker. No such tag exists in HTML.
There are specific CSS text and CSS font properties which work only on text. They are to be used in the text's parent element (in your case div with class name attr-marker):
.attr-marker {
/* text properties */
/* some other properties */
}
Properties like display: block;, width: 12px;, height: 12px; and so on, won't work on text.
That being said, you don't need to worry whether your CSS properties will be applied to the text or to the whole div. If you're using the right properties, you can be sure they are only applied to the text.
As for the content(text) presence, you don't need to worry about it. If there is no text, CSS won't change anything.
Either add another class to that div from the server side if it will send content or wrap content with another element and give it some styling.
Edit:
If you know exact position of your element then you can select it with nth-child pseudo-class:
.attr-marker:nth-child(1):not(:empty) {
border: 1px solid #333;
background-color: yellow;
}
If these markers are block rendered elements, the browser should not display them, unless they have content, therefore you can trust the browser to not render the elements with no content, use the max-width and max-height properties below:
.attr-marker {
display: block;
max-width: 12px;
max-height: 12px;
border-radius: 50%;
line-height: 12px;
font-size: 9px;
text-align: center;
background: #000;
color: #fff;
/*If required*/
overflow:hidden
}

Edit Google Recaptcha CSS to make it responsive

So I have this chunk of html that displays the inserted Recaptcha div wrapped with my own comment_recaptcha div:
<script src='https://www.google.com/recaptcha/api.js' async defer></script> <div class='comment_recaptcha' id='comment_recaptcha'><div class='g-recaptcha' data-sitekey='".$this->recaptcha_public_key."'></div></div>
Problem is, it looks horrible on mobile -
In the picture above it could look worse, but it's not ideal at all and even that recatpcha centering I've solved by making comment_recaptcha display: grid and making the g-recaptcha class margin: auto.
comment_recaptcha's father div is #insert_element -
#insert_comment {
margin-top: 10px;
font-family: 'Roboto', sans-serif;
color: #424242;
font-size: 14px;
background-color: #f7f7f7;
border-radius: 3px;
border: 1px solid #eaeaea;
padding: 10px 20px;
max-width: 100%;
}
But the true horror is when the window's width is less than about 365 pixels it could like that -
How do I fix that so the Recaptcha fits the full width of its container instead of staying at the same size and look like it?

Change class and css , with jQuery , of a flaticon

This is the situation
<div id="idDiv">
<span class="flaticon-edit23"></span>
</div>
to change the css of the span i have to do this
#idDiv > span::before{
position: relative;
font-size: 26px;
line-height: 60px;
margin-left: 13px;
color: white;
}
if i click on #idDiv, I have to change the icon of the span, and also change some parameters of the css span (in this case, the font-size)
this works , and change correctly the icon
$("#idDiv").find("span:first").removeClass().addClass("flaticon-floppy13");
but I should change the css of the ::before selector , and i try this (and other similar combinations)
$("#idDiv").find("span:first").removeClass().addClass("flaticon-floppy13").find("span:before").css({"font-size":"36px"});
but it does not work properly
how can I do this ? thanks
UPDATE
this don't work
$("#idDiv").find("span:first").removeClass().addClass("flaticon-floppy13");
$("#idDiv").find("span:before").css("font-size","36px");
this don't work
$("#idDiv").find("span:first").removeClass().addClass("flaticon-floppy13");
$("#idDiv").find("span:before").css({"font-size":"36px"});
this don't work
.new_class{font-size: 36px; }
$("#idDiv").find("span:first").removeClass().addClass("flaticon-floppy13");
$("#idDiv").find("span:first").addClass("new_class");
this don't work
.new_class > span::before{font-size: 36px; }
$("#idDiv").find("span:first").removeClass().addClass("flaticon-floppy13");
$("#idDiv").find("span:first").addClass("new_class");
I don't think pseudo elements can be selected and modified as you are trying to do here.
What you can instead do is to have two different pseudo elements defined and either of them would get applied based on the span's CSS class.
e.g.
#idDiv > span.flaticon-edit23::before{
position: relative;
font-size: 26px;
line-height: 60px;
margin-left: 13px;
color: white;
}
#idDiv > span.flaticon-floppy13::before{
position: relative;
font-size: 36px;
line-height: 60px;
margin-left: 13px;
color: white;
}
and then, only changing the CSS class of the span
$("#idDiv").find("span:first").removeClass().addClass("flaticon-floppy13");
should be sufficient..
$("#idDiv").find("span:first").removeClass().addClass("flaticon-floppy13");
$("#idDiv").find("span:before").css("font-size":"36px");
Also
if (!$('.your class').val()) {
$('#idDiv').val("flaticon-floppy13");
} else {
$('#idDiv').val("");
}
or just remove {} but its better to separate the functions. I don't think they work together.
Have you done the same like this?
.new_class{font-size: 36px !important; }
$("#idDiv").find("span:first").addClass("new_class");

line-height is uneven. Larger space above text than under

I'm having issues with fonts such as Josefin Sans where the space above, and below the text is uneven. This makes it impossible to vertical align the text.
Look at this http://jsfiddle.net/G5aVK/.
HTML
<div class="text">
Hello World
</div>
<div class="text2">
Hello World
</div>
CSS
.text{
font-family: 'Josefin Sans';
font-size: 36px;
background: #ff0000;
margin-bottom: 10px;
}
.text2{
font-family: serif;
font-size: 36px;
background: #ff0000;
margin-bottom: 10px;
}
As you can see the normal serif font is aligned vertical center in the div. But the Josefin Sans one is not, it has more space above each letter than under.
Is there any way to fix this? Is there any way with CSS or maybe Javascript to change the height above, and below the font? If you try line-height you will see it does not fix the issue.
EDIT: A lot of suggestions seem to be quickfixes that would only solve exactly this font size, exactly this font and so on. I would need a solution that would work over different fonts and sizes, because the content in this case is generated by the users so I can't control what size or font they will be using.
So if talking pseudo-code, a solution that I would look for would be "font-vertical-align: middle" or something like that. But maybe the only way to fix this is by doing ugly pixel-specific fixes.
That space belongs to the characters themselves; Which means you have to edit the font via a Font editor application to align the characters vertically in their code point.
However, you can play with line-height and min-height properties to achieve the goal:
.text {
font-family: 'Josefin Sans';
font-size: 36px;
background: #ff0000;
margin-bottom: 10px;
line-height: .95em; /* Reduce the line height */
min-height: 1.2em; /* Set a min-height to the container */
}
WORKING DEMO.
Try this,
.text{
font-family: 'Josefin Sans';
font-size: 36px;
background: #ff0000;
margin-bottom: 10px;
height:36px; // add height
line-height:24px;// add line-height
}
Demo
The Reason why the font isn't aligning vertically is due to the font type (some font types can have their typography lines offset to most conventional fonts)
http://jsfiddle.net/denistsoi/28zx2/
I added the following css rule
.text {
padding-top: 8px;
}
Update
http://jsfiddle.net/denistsoi/28zx2/3/
Another way is to
HTML
<link href='http://fonts.googleapis.com/css?family=Josefin+Sans' rel='stylesheet' type='text/css'>
<div class="text">
<p class="content">Hello World</p>
</div>
<div class="text2">
Hello World
</div>
This way you can also adjust the vertical alignment with your margins~
CSS
.text > .content {
display: inline-block;
vertical-align: middle;
margin: 2px 0 -2px 0;
}

Categories