This question already has answers here:
CSS3's attr() doesn't work in major browsers
(5 answers)
Closed 6 years ago.
I'd like to have CSS that uses attr(data-attribute) to apply a CSS-rule.
For example, in my CSS:
#media max-width(480px) {
.mobile-float {
float: attr(data-mobile-float);
}
}
Then, in my HTML, I define the data-attribute:
<div data-mobile-float="right">
Floats right on mobile!
</div>
<div data-mobile-float="left">
Floats left on mobile!
</div>
I feel like I'm missing a character and it's not working. How do I do this correctly? Thanks!
you are using wrong selector in CSS try this
[data-mobile-float="left"]{font-size: 50px;}
<div data-mobile-float="right">
Floats right on mobile!
</div>
<div data-mobile-float="left">
Floats left on mobile!
</div>
Related
This question already has answers here:
How to adjust the width of a horizontal rule element
(7 answers)
Closed 2 years ago.
How do you change length of an hr tag?
<hr>
Takes the full length of the browser. I tried setting padding and margin but no effect. Any solution for this using plain css or using Bootstrap 5?
You need to set margin for the hr tag. The following would work
hr {
margin: auto 220px
}
/* just for demo*/
.div {
text-align: center;
margin: 20px;
}
<div class='div'> div - 1</div>
<hr>
<div class='div'> div - 2</div>
You can write the following style tag on your html.
<style> hr{margin: auto 220px;}</style>
<hr>
Get more information here.
This question already has answers here:
Bootstrap 3 fluid grid layout issues?
(7 answers)
Closed 6 years ago.
I have a standard bootstrap-grid. The columns differ in their height sometimes which causes this:
Instead what I need is this:
I know, usually this is achieved by grouping 3 items in a row. But: as the browser resizes, it changes from a 3-column to a 2-column and then 1-column layout. So how can I achieve the same effect without using multiple rows?
Code:
<section class="container margin_60">
<div class="row">
<div class="col-md-4 col-sm-6">
// content
</div>
<div class="col-md-4 col-sm-6">
// content
</div>
....
</div>
</section>
Got it!
The solution is indeed to add a clear:both after every 3rd element, so the next element can break. But as the grid shall be dynamic and switch the amount of columns, it cannot be implemented directly into the html.
Solution: :nth-child
#media (min-width: 992px) {
.my-grid-item:nth-child(3n+4) {
clear: both;
}
}
For the 3-column layout and
#media (max-width: 991px) {
.my-grid-item:nth-child(2n+3) {
clear: both;
}
}
for 2-column and 1-column layout.
After every 3 div add that div:
<div style="clear: both;"></div>
This question already has answers here:
Is there a CSS parent selector?
(33 answers)
Closed 7 years ago.
I have DOM like this
<div class="outer">
<div class="inner">
</div>
</div>
and corresponding CSS is like
.outer {
width: 700px;
}
, where inner could by typeA, typeB.....
Later I found that I want to enlarge outer when particular typeX show up, but
.outer .typeX {
width: 90%;
}
will apply style width: 90% to .typeX div not .outer div. How do I solve this? Is it possible in pure CSS? (Assume .outer is fixed since it is generated by other library)
Unfortunately, what you are looking for would be a parent selector, which does not yet exist in CSS.
Maybe someday (e.g., in Selectors Level 4).
This question already has answers here:
CSS - is there a cousin selector?
(2 answers)
Closed 8 years ago.
Am I able to select .button based on a pseudo-class of .main?
I want div.button to be blue only if div.main is empty (.main:empty). How can I do this using only CSS?
<div class="container">
<div class="header">
<div class="button">I should have color:blue when .main is empty</div>
</div>
<div class="content">
<div class="main"></div>
</div>
</div>
(please don't offer to solve using jQuery)
No, there's no way to select a "cousin" with pure CSS.
If #header were after .content, then you could select .button from a pseudo-class of .content -- an "aunt/uncle" -- using the adjacent sibling combinator (+) like this:
.content:hover + #header .button{/* styles */}
But even then, you're not able to select .button from a pseudo-class of .main (the "cousin")
This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Closed 1 year ago.
For this fiddle, why is there a space at the bottom of div#imageDiv?
JSFiddle
<div>
<div>
<div>
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/SIPI_Jelly_Beans_4.1.07.tiff/lossy-page1-256px-SIPI_Jelly_Beans_4.1.07.tiff.jpg" />
</div>
</div>
</div>
<div id="text"><div id="inner">text goes here</div></div>
html {
line-height: 1.5em;
}
#text {
background-color: grey;
margin-top:-7px;
}
Set your image to img { display: block; }. And please next time add your code here on SO to prevent link rot and lets us easily review your code here.
Give your image a bottom vertical alignment and the space goes away.
jsFiddle example
img {
vertical-align:bottom;
}
you could also margin-top property to achieve that
http://jsfiddle.net/meetravi/7Knyx/14/
P.S Its always great to avoid negative values in css if you are planning to support relatively old browsers