I'm trying to take an :after element, which is an image frame and flip the second one in a group of 3 horizontally.
Here's my current css:
.photo-frame {
position: relative;
width: 354px;
height: 244px;
}
.photo-frame:after {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: block;
width: 354px;
height: 244px;
background: url(images/photo-frame.png) no-repeat 0 0;
}
.photo-frame img {
display: block;
margin: 0 auto;
}
.photo-frame:nth-child(2):after {
-moz-transform: scaleX(-1);
-o-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
filter: FlipH;
-ms-filter: "FlipH";
}
HTML:
<div class="shell">
<div class="section-body">
<ul>
<li>
<a href="#">
<div class="photo-frame">
<img width="354" height="244" src="/uploads/2014/10/dierks-354x244.jpg" class="attachment-photo-image" alt="dierks" />
</div><!-- /.photo-frame -->
</a>
<div class="top-section-img-title">
<strong>
ARTIST NAME
</strong>
</div>
</li>
<li>
<a href="#">
<div class="photo-frame">
<img width="354" height="244" src="/uploads/2014/10/carrie-354x244.jpg" class="attachment-photo-image" alt="carrie" />
</div><!-- /.photo-frame -->
</a>
<div class="top-section-img-title">
<strong>
ARTIST NAME
</strong>
</div>
</li>
<li>
<a href="#">
<div class="photo-frame">
<img width="354" height="244" src="/uploads/2014/10/luke-354x244.jpg" class="attachment-photo-image" alt="luke" />
</div><!-- /.photo-frame -->
</a>
<div class="top-section-img-title">
<strong>
ARTIST NAME
</strong>
</div>
</li>
</ul>
<div class="more">
VIEW FULL LINEUP HERE
</div><!-- /.more -->
</div><!-- /.section-body -->
</div><!-- /.shell -->
It's not working however.
I'm fairly new to this nth child selector magic. Can you guys give me a hand?
The problem is that .photo-frame is an only child within each li so your selector does not match anything. You should also know that :nth-child() only selects elements not classes or ID's like how you're currently trying.
Because the li's are children elements, and ancestors of each .photo-frame, I suggest targeting them with :nth-child() instead to select the .photo-frame you want to style:
li:nth-child(2) .photo-frame:after {
/* ... */
}
Related
I'm trying to achieve a solution where a horizontal line appears to the left of the text but the text remains centre aligned. Please see image below.
I've also added my mark-up below. I'm currently using Bootstrap 4.
<div class="text-center nav-items">
<ul>
<div class="pb-5">
<li>
<h2 class="sidebar-first-item">About</h2>
</li>
<p>Behind the brand // Meet the team</p>
</div>
<div class="pb-5">
<li>
<h2>Our Work</h2>
</li>
<p>Take a look at our marvelous creations</p>
</div>
<div class="pb-5">
<li>
<h2>Services</h2>
</li>
<p>Learn more about what we can do for you</p>
</div>
<div class="pb-5">
<li>
<h2 class="sidebar-last-item">Contact</h2>
</li>
<p>Get in touch today. Let's make some magic</p>
</div>
</ul>
</div>
Use pseudo-elements to do so:
.sidebar-first-item {
position: relative;
}
.sidebar-first-item:before {
content: '';
position: absolute;
width: 45%;
height: 5px;
background-color: red;
top: 50%;
left: 0%;
}
CodePen: https://codepen.io/manaskhandelwal1/pen/xxEaQYg
First cleanup your html, a <ul> list may not have children other than <li>, <script> or <template> elements (see The Unordered List element). Hence remove the div's inside the <ul> and add their classes to the <li>.
A solution to your design problem is to add a element before and after your anchor elements, size them (width) with a percentage you like and set a min-width for the anchor, so you have a nice responsive layout also on small devices. This creates an equal width red line
If you want the red line to align with the width of the text, you can make your anchor non-breaking white space and a set a padding, so the red line comes as close as defined in the padding towards the text.
.redline,
.spacer {
width: 100%;
height: 3px;
display: inline;
background-color: red;
}
.spacer {
height: 0px;
}
li {
display: flex;
align-items: center;
}
li a {
margin: 0 auto;
border: 0px solid gold;
padding: 0 20px;
white-space: nowrap;
}
li p {
width: 100%; margin:-50px 0 50px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<div class="text-center nav-items">
<ul>
<li class="pb-5">
<span class="redline"></span>
<a href="#">
<h2 class="sidebar-first-item">About</h2>
</a>
<span class="spacer"></span>
</li>
<li>
<p>Take a look at our marvelous creations</p>
</li>
<li class="pb-5">
<span class="redline"></span>
<a href="#">
<h2>Our Work</h2>
</a>
<span class="spacer"></span>
</li>
<li>
<p>Behind the brand // Meet the team</p>
<li>
</ul>
</div>
This is where a CSS pseudo element can come into play! A pseudo element can be used to place designs before or after an element.
I added a class called horizontal-line to your h2.
<div class="text-center nav-items">
<ul>
<div class="pb-5">
<li>
<h2 class="horizontal-line sidebar-first-item">About</h2>
</li>
<p>Behind the brand // Meet the team</p>
</div>
<div class="pb-5">
<li>
<h2>Our Work</h2>
</li>
<p>Take a look at our marvelous creations</p>
</div>
<div class="pb-5">
<li>
<h2>Services</h2>
</li>
<p>Learn more about what we can do for you</p>
</div>
<div class="pb-5">
<li>
<h2 class="sidebar-last-item">Contact</h2>
</li>
<p>Get in touch today. Let's make some magic</p>
</div>
</ul>
The CSS will look like this.
.horizontal-line {
position: relative;
}
.horizontal-line::before {
content: "";
display: block;
width: 60px;
height: 2px;
position: absolute;
top: 50%;
left: 35%;
border-radius: 30px;
background-color: #DE657D;
}
By adding the pseudo element it will know to place it before any content with that class name. In this case, we are leaving content blank and placing in
https://jsfiddle.net/rc463gb8/1/
I am using a code from this site: https://codepen.io/tutsplus/pen/rQrVBg to make an image grid with transition whey you touch or move over it shows some text. The transition works fine on PC, but when I was testing on my mobile phone I got the opacity color over a picture. I tested in Safari, Chrome and Edge and doesn't work neither.
body {
padding: 20px;
font-family: sans-serif;
background: #f2f2f2;
}
img {
width: 100%;
/* need to overwrite inline dimensions */
height: auto;
}
h2 {
margin-bottom: .5em;
}
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
grid-gap: 1em;
}
/* hover styles */
.location-listing {
position: relative;
}
.location-image {
line-height: 0;
overflow: hidden;
}
.location-image img {
filter: blur(0px);
transition: filter 0.3s ease-in;
transform: scale(1.1);
}
.location-title {
font-size: 1.5em;
font-weight: bold;
text-decoration: none;
z-index: 1;
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
opacity: 0;
transition: opacity .5s;
background: rgba(90, 0, 10, 0.4);
color: white;
/* position the text in t’ middle*/
display: flex;
align-items: center;
justify-content: center;
}
.location-listing:hover .location-title {
opacity: 1;
}
.location-listing:hover .location-image img {
filter: blur(2px);
}
/* for touch screen devices */
#media (hover: none) {
.location-title {
opacity: 1;
}
.location-image img {
filter: blur(2px);
}
}
<div class="child-page-listing">
<h2>Our Locations</h2>
<div class="grid-container">
<article id="3685" class="location-listing">
<a class="location-title" href="#">
San Francisco
</a>
<div class="location-image">
<a href="#">
<img width="300" height="169" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/san-fransisco-768x432.jpg" alt="san francisco">
</a>
</div>
</article>
<article id="3688" class="location-listing">
<a class="location-title" href="#">
London
</a>
<div class="location-image">
<a href="#">
<img width="300" height="169" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/london-768x432.jpg" alt="london">
</a>
</div>
</article>
<article id="3691" class="location-listing">
<a class="location-title" href="#">
New York
</a>
<div class="location-image">
<a href="#">
<img width="300" height="169" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/new-york-768x432.jpg" alt="new york">
</a>
</div>
</article>
<article id="3694" class="location-listing">
<a class="location-title" href="#">
Cape Town
</a>
<div class="location-image">
<a href="#">
<img width="300" height="169" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/cape-town-768x432.jpg" alt="cape town">
</a>
</div>
</article>
<article id="3697" class="location-listing">
<a class="location-title" href="#">
Beijing
</a>
<div class="location-image">
<a href="#">
<img width="300" height="169" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/beijing-768x432.jpg" alt="beijing">
</a>
</div>
</article>
<article id="3700" class="location-listing">
<a class="location-title" href="#">
Paris
</a>
<div class="location-image">
<a href="#">
<img width="300" height="169" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/210284/paris-768x432.jpg" alt="paris">
</a>
</div>
</article>
</div>
<!-- end grid container -->
</div>
Since there is no hover effect in mobile browsers (no mouse cursor to move/hover over the images), you can't get the same behaviour on mobile/touchscreen devices.
The media query at the end of the CSS is applying a style to all '.location-title' elements, and a blur to all '.location-image img' elements. These effects will be applied to these regardless of whether the user is interacting with those elements. I'd say in this sample, that's an acceptable fallback behaviour, using the #media query to assign styles to elements in the event the hover capability isn't available in the browser. Your specific solution may need a different approach if you want something more like the desktop behaviour on mobile devices (e.g., CSS rules applied to active elements on a touch event).
I'm developing this website for an animal shelter in my city, because the old website is displaying very bad on smaller devices like smartphones.
I made a color gradient with gimp for the part of the HTML.
#image {
position: relative;
width: 100%;
/* for IE 6 */
}
#headline {
position: absolute;
top: 0px;
left: 0;
width: 100%;
}
#logo {
position: absolute;
top: 120px;
}
#menu-btn {
position: absolute;
top: 60px;
}
<header id="image">
<img src="bar.png" width="100%" height="100px">
<h3 class="w3-center" id="headline">Tierschutzverein</h3>
<div class="w3-bar" id="menu-btn">
<a class="w3-button w3-bar-item" href="#">Home</a>
<div class="dropdown w3-bar-item">
<span>Zuhause gesucht</span>
<div class="dropdown-content">
<p>Test</p>
</div>
</div>
<a class="w3-button w3-bar-item" href="#">Über uns</a>
<a class="w3-button w3-bar-item" href="#">Links</a>
<a class="w3-button w3-bar-item" href="#">Kontakt</a>
<a class="w3-button w3-bar-item" href="#">Pension</a>
</div>
</header>
But now there is the problem, that the dropdown content isn't visible below the color gradient. I think it's because of the CSS at #menu-btn.
How can I fix this mistake?
So, I have this code below with images and a countdown below the images. How do I make all the images the same dimension, but still make it responsive for Bootstrap? I've tried doing min & max height, but the problem still continues. I've tried setting the width & height, but then the image is no longer responsive. I have tried setting the properties for the img-responsive class, but then the image looks all distorted.
Any ideas? I heard about this idea of having the images not being the same dimension, but having the rest of the uneven dimension be filled with the background of the image. Thanks :)
Thanks...
/* Books */
#books_div {
position: absolute;
left: 50%;
top: 25%;
transform: translatex(-50%);
}
#books_text {
position: absolute;
left: 50%;
top: 15%;
transform: translatex(-50%);
}
.description_one, .description_two, .description_three {
color: #9B0103;
max-width: 100%;
text-align: center;
border: 1px solid #9B0103;
border-top: none;
font-weight: bold;
}
.description_one a {
text-decoration: none !important;
}
#book_column a {
text-decoration: none !important;
}
/* End of Books */
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Books -->
<h2 id='books_text'> We Giveaway Free Books </h2>
<div class="row" id='books_div'>
<!-- First Book -->
<div class='col-lg-3 col-sm-6 portfolio-item' id='book_column'>
<a href='#'>
<img class='img-responsive' src='https://images.gr-assets.com/books/1472913234l/29563587.jpg' alt='' id='book_cover_one' token_id='4ce0e43b806457bbc21881748d6a50d2'>
<div class='description_one'>
5:05:12
</div> </a>
</div>
<!-- End of First Book -->
<!-- Second Book -->
<div class='col-lg-3 col-sm-6 portfolio-item' id='book_column'>
<a href='#'>
<img class='img-responsive' src='https://images.gr-assets.com/books/1388211242l/69571.jpg' alt='' id='book_cover_two' token_id='bb8673cb597c7fc7cba7bc13d9f08a4b'>
<div class='description_two'>
6:32:14
</div> </a>
</div>
<!-- End of Second Book -->
<!-- Third Book -->
<div class='col-lg-3 col-sm-6 portfolio-item' id='book_column'>
<a href='#'>
<img class='img-responsive' src='https://images.gr-assets.com/books/1342493368l/3636.jpg' alt='' id='book_cover_three' token_id='25ea7f6c20f1f185841ed88c9a9d2f2c'>
<div class='description_three'>
7:12:04
</div> </a>
</div>
<!-- End of Third Book -->
Just add a min-height to your images to modulate width add width:some%
Working Snippet
/* Books */
#books_div {
position: absolute;
left: 50%;
top: 25%;
transform: translatex(-50%);
}
#books_text {
position: absolute;
left: 50%;
top: 15%;
transform: translatex(-50%);
}
.description_one, .description_two, .description_three {
color: #9B0103;
max-width: 100%;
text-align: center;
border: 1px solid #9B0103;
border-top: none;
font-weight: bold;
}
.description_one a {
text-decoration: none !important;
}
#book_column a {
text-decoration: none !important;
}
.img {
min-height: 300px;
}
/* End of Books */
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Books -->
<h2 id='books_text'> We Giveaway Free Books </h2>
<div class="row" id='books_div'>
<!-- First Book -->
<div class='col-lg-3 col-sm-6 portfolio-item' id='book_column'>
<a href='#'>
<img class='img-responsive img' src='https://images.gr-assets.com/books/1472913234l/29563587.jpg' alt='' id='book_cover_one' token_id='4ce0e43b806457bbc21881748d6a50d2'>
<div class='description_one'>
5:05:12
</div> </a>
</div>
<!-- End of First Book -->
<!-- Second Book -->
<div class='col-lg-3 col-sm-6 portfolio-item' id='book_column'>
<a href='#'>
<img class='img-responsive img' src='https://images.gr-assets.com/books/1388211242l/69571.jpg' alt='' id='book_cover_two' token_id='bb8673cb597c7fc7cba7bc13d9f08a4b'>
<div class='description_two'>
6:32:14
</div> </a>
</div>
<!-- End of Second Book -->
<!-- Third Book -->
<div class='col-lg-3 col-sm-6 portfolio-item' id='book_column'>
<a href='#'>
<img class='img-responsive img' src='https://images.gr-assets.com/books/1342493368l/3636.jpg' alt='' id='book_cover_three' token_id='25ea7f6c20f1f185841ed88c9a9d2f2c'>
<div class='description_three'>
7:12:04
</div> </a>
</div>
<!-- End of Third Book -->
I have code that displays images and a countdown below the images. How do I make all the images the same dimensions but also let Bootstrap be responsive? At the same time, also making sure the countdown box below stays with the dimensions of the images? Thanks :)
/* Books */
#books_div {
position: absolute;
left: 50%;
top: 25%;
transform: translatex(-50%);
}
#books_text {
position: absolute;
left: 50%;
top: 15%;
transform: translatex(-50%);
}
.description_one, .description_two, .description_three {
color: #9B0103;
max-width: 100%;
text-align: center;
border: 1px solid #9B0103;
border-top: none;
font-weight: bold;
}
.description_one a {
text-decoration: none !important;
}
#book_column a {
text-decoration: none !important;
}
/* End of Books */
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Books -->
<h2 id='books_text'> We Giveaway Free Books </h2>
<div class="row" id='books_div'>
<!-- First Book -->
<div class='col-lg-3 col-sm-6 portfolio-item' id='book_column'>
<a href='#'>
<img class='img-responsive' src='https://images.gr-assets.com/books/1472913234l/29563587.jpg' alt='' id='book_cover_one' token_id='4ce0e43b806457bbc21881748d6a50d2'>
<div class='description_one'>
5:05:12
</div> </a>
</div>
<!-- End of First Book -->
<!-- Second Book -->
<div class='col-lg-3 col-sm-6 portfolio-item' id='book_column'>
<a href='#'>
<img class='img-responsive' src='https://images.gr-assets.com/books/1388211242l/69571.jpg' alt='' id='book_cover_two' token_id='bb8673cb597c7fc7cba7bc13d9f08a4b'>
<div class='description_two'>
6:32:14
</div> </a>
</div>
<!-- End of Second Book -->
<!-- Third Book -->
<div class='col-lg-3 col-sm-6 portfolio-item' id='book_column'>
<a href='#'>
<img class='img-responsive' src='https://images.gr-assets.com/books/1342493368l/3636.jpg' alt='' id='book_cover_three' token_id='25ea7f6c20f1f185841ed88c9a9d2f2c'>
<div class='description_three'>
7:12:04
</div> </a>
</div>
<!-- End of Third Book -->
Solution 1
You can add below at the bottom of your css
img[id^="book_cover"]{
width:500px;
height:500px;
}
The above will target all img elements with id that starts with book_cover, example book_cover_one, book_cover_two, etc
See snippet below
/* Books */
#books_div {
position: absolute;
left: 50%;
top: 25%;
transform: translatex(-50%);
}
#books_text {
position: absolute;
left: 50%;
top: 15%;
transform: translatex(-50%);
}
.description_one, .description_two, .description_three {
color: #9B0103;
max-width: 100%;
text-align: center;
border: 1px solid #9B0103;
border-top: none;
font-weight: bold;
}
.description_one a {
text-decoration: none !important;
}
#book_column a {
text-decoration: none !important;
}
img[id^="book_cover"]{
width:500px;
height:500px;
}
/* End of Books */
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Books -->
<h2 id='books_text'> We Giveaway Free Books </h2>
<div class="row" id='books_div'>
<!-- First Book -->
<div class='col-lg-3 col-sm-6 portfolio-item' id='book_column'>
<a href='#'>
<img class='img-responsive' src='https://images.gr-assets.com/books/1472913234l/29563587.jpg' alt='' id='book_cover_one' token_id='4ce0e43b806457bbc21881748d6a50d2'>
<div class='description_one'>
5:05:12
</div> </a>
</div>
<!-- End of First Book -->
<!-- Second Book -->
<div class='col-lg-3 col-sm-6 portfolio-item' id='book_column'>
<a href='#'>
<img class='img-responsive' src='https://images.gr-assets.com/books/1388211242l/69571.jpg' alt='' id='book_cover_two' token_id='bb8673cb597c7fc7cba7bc13d9f08a4b'>
<div class='description_two'>
6:32:14
</div> </a>
</div>
<!-- End of Second Book -->
<!-- Third Book -->
<div class='col-lg-3 col-sm-6 portfolio-item' id='book_column'>
<a href='#'>
<img class='img-responsive' src='https://images.gr-assets.com/books/1342493368l/3636.jpg' alt='' id='book_cover_three' token_id='25ea7f6c20f1f185841ed88c9a9d2f2c'>
<div class='description_three'>
7:12:04
</div> </a>
</div>
<!-- End of Third Book -->
Solution 2
Instead of solution 1, this seems much more simpler
.img-responsive{
width:500px;
height:500px;
}
Try add one more class to yor CSS:
.thumb img {
width: 100%;
height: 300px;
}
This should fix your problem.