Whenever I run this code on the HTML page, it shows the box with the text on the first sliding image for a brief second, then it disappears for some reason. Here is the HTML for the sliding images.
.containerSlider {
position: relative;
}
.text-block {
position: absolute;
bottom: 100px;
right: 150px;
background-color: black;
color: white;
}
<section>
<div id="containerSlider">
<div id="slidingImage">
<img src="https://via.placeholder.com/100" alt="image4">
<div class="text-block">
<p>This is a text to see if this works</p>
</div>
</div>
<div id="slidingImage">
<img src="https://via.placeholder.com/100/ffcccc" alt="image1">
<div class="text-block">
<p>This is a text to see if this works</p>
</div>
</div>
<div id="slidingImage">
<img src="https://via.placeholder.com/100" alt="image2">
<div class="text-block">
<p>This is a text to see if this works</p>
</div>
</div>
<div id="slidingImage">
<img src="https://via.placeholder.com/100/ffcccc" alt="image3">
<div class="text-block">
<p>This is a text to see if this works</p>
</div>
</div>
</div>
</section>
and the Javascript for the Slider is
<!-- <script src=“https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js”></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>
<script>
$(document).ready(function () {
$('#containerSlider').slick({
dots: true,
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
autoplay: true,
autoplaySpeed: 5000,
});
});
</script>
You have to add position:relative to the div you want your text to be placed in. In your case, .containerSlider contains the complete slider but we want to target individual slides which in this case are .slidingImage.
So, after updating your CSS to something like the code below, I believe I got what you wanted.
#slidingImage {
position: relative;
width: fit-content;
}
p {
position: absolute;
bottom: 10%;
background-color: black;
color: white;
}
<section>
<div id="containerSlider">
<div id="slidingImage">
<img src="https://via.placeholder.com/100" alt="image4" />
<div class="text-block">
<p>This is a text to see if this works</p>
</div>
</div>
<div id="slidingImage">
<img src="https://via.placeholder.com/100/ffcccc" alt="image1" />
<div class="text-block">
<p>This is a text to see if this works</p>
</div>
</div>
<div id="slidingImage">
<img src="https://via.placeholder.com/100" alt="image2" />
<div class="text-block">
<p>This is a text to see if this works</p>
</div>
</div>
<div id="slidingImage">
<img src="https://via.placeholder.com/100/ffcccc" alt="image3" />
<div class="text-block">
<p>This is a text to see if this works</p>
</div>
</div>
</div>
</section>
.slidingImage {
height: 100px;
width: 100px;
color: white;
overflow-wrap: break-word;
display: flex;
justify-content:center;
align-items:center
background-repeat: no-repeat;
margin-bottom: 10px
}
<div class="slidingImage" style="background-image: url(https://via.placeholder.com/100)">
<p>This is a text to see if this works</p>
</div>
<div class="slidingImage" style="background-image: url(https://via.placeholder.com/100)">
<p>This is a text to see if this works</p>
</div>
<div class="slidingImage" style="background-image: url(https://via.placeholder.com/100)">
<p>This is a text to see if this works</p>
</div>
<div class="slidingImage" style="background-image: url(https://via.placeholder.com/100)">
<p>This is a text to see if this works</p>
</div>
here
Related
How can i center my icons like <GrTools size="30px"/> along with my text? I am kind of having issues with some of my styled centering components.
my js:
<div id = 'paragraph' className="container" >
<h1 className='text-center' > Title <b> </b> </h1>
<p id='content' className='lead mb-4'> paragraph</p>
<hr className='col-xs-12 '/>
<p id='content' className='lead mb-4'> paragraph</p>
<GrTechnology className = 'responsive-image' size='30px'/>
<p id='content' className='lead mb-4'> Paragraph</p>
<GrTools size="30px"/>
<p id='content' className='lead mb-4'> Paragraph</p>
</div>
my css file:
div#paragraph{
width: 100%;
margin: 0px auto;
}
p#content{
text-align: center;
width: 100%;
margin: 50px auto;
}
Wrap the paragraph and icon in a div(container) and use flex-box display:flex on the container to align the children(icon & p)
as #man517 suggested this guide more then enough css-tricks.com/snippets/css/a-guide-to-flexbox
note: change the class to className 😉
.container{
display: flex;
}
<div id='paragraph' >
<h1 className='text-center'> Title <b> </b> </h1>
<p id='content' className='lead mb-4'> paragraph</p>
<hr className='col-xs-12 ' />
<div class="container">
<p id='content' className='lead mb-4'> paragraph</p>
<img src="https://img.icons8.com/ios-glyphs/30/000000/cat--v1.png" width='30px' />
</div>
<div class="container">
<img src="https://img.icons8.com/ios-glyphs/30/000000/cat--v1.png" width='30px' />
<p id='content' className='lead mb-4'> paragraph</p>
</div>
<p id='content' className='lead mb-4'> Paragraph</p>
</div>
When I was building a 2 columns layout and having the first items of each row floated to left, I was faced with an issue. If the element's text was much bigger than intended, the rows would break, items being pushed down, so instead of it looking like this:
it looks like this:
The code being:
<ul class="layout">
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
CSS:
.layout {
list-style: none;
}
.layout > li {
vertical-align: top;
width: 49%;
}
.layout > li:nth-child(odd) {
margin-right: 1%;
float: left;
}
.layout > li:nth-child(even) {
margin-left: 1%;
float: right;
}
Which works, but if we are to make the longer, it'd break.
If we add this line:
.layout > li:nth-child(even) + li {
clear: both;
}
It works just perfectly, no matter what I throw at it.
How come?
Just use only float: left for ALL elements in your case.
.layout {
list-style: none;
}
.layout>li {
vertical-align: top;
width: 49%;
float: left;
}
.layout>li:nth-child(odd) {
margin-right: 1%;
}
.layout>li:nth-child(even) {
margin-left: 1%;
}
<ul class="layout">
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
<li>
<article>
<div class="thumb">
<img class="img" alt="" src="">
</div>
<div class="post-info">
<h3>Hey there! You should make me bigger to break the layout.</h3>
<p>Some text here...</p>
</div>
</article>
</li>
Application of clear clears out the floats for current container which would have otherwise got applied due to preceding or inherited styles.
The only layout that is now applied to these elements are their own. That's why, it works as desired.
https://developer.mozilla.org/en/docs/Web/CSS/clear
For your layout, you float box 1 to left, then box2 to left. Then, you apply clear:both because you want to stop applying floats. Then, for the next row boxes, you apply floats again because you want to place them left.
"When you apply clear:both to an element, it basically says "stop floating here" — this element and those after it in the source will not float, unless you apply a new float declaration to another element later on."
I am attempting to build a responsive material list view where each card includes an image, some textual details and some user actions.
The textual details can vary between items in the list, so the card heights can vary. As the design needs to be responsive, the width of the card can also vary.
What I need to do is ensure that the image is always a square. I've seen good answers here on how to achieve that in a vertical layout, but not in a horizontal layout.
Here is a mockup of what I am trying to achieve using Flex to show the box layout. I am not tied to Flex as part of the solution.
Sample code
.card {
display: flex;
flex-flow: row wrap;
width: 100%;
margin-bottom: 15px;
}
.card .title {
line-height: 3rem;
font-size: 1.5rem;
font-weight: 300;
}
.card .action {
background: grey;
order: 3;
flex-basis: 100%;
}
.card .content {
background: red;
order: 2;
flex-grow: 1;
}
.card .image {
background: gold;
order: 1;
flex-grow: 1;
}
<div class="row">
<div class="medium-6 columns end">
<div class="card">
<div class="content">
<span class="title">
Just a Title
</span>
</div>
<div class="action">
<p>this is an action</p>
</div>
<div class="image">
<p>Image goes here</p>
</div>
</div>
<div class="card">
<div class="content">
<span class="title">
Title with some text
</span>
<P>This is some content under the title</P>
</div>
<div class="action">
<p>this is an action</p>
</div>
<div class="image">
<p>Image goes here</p>
</div>
</div>
<div class="card">
<div class="content">
<span class="title">
Title with more text
</span>
<P>This is some content under the title</P>
<P>Second line of text</P>
</div>
<div class="action">
<p>this is an action</p>
</div>
<div class="image">
<p>Image goes here</p>
</div>
</div>
</div>
</div>
Try adding this script at the end of your work:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js"></script>
<script>
var cw = $('.image').width();
$('.image').css({
'height': cw + 'px'
});
</script>
EDIT
To act upon window resize, try this:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js"></script>
<script>
var cw = $('.image').width();
$('.image').css({
'height': cw + 'px'
});
window.onresize = function(event) {
var cw = $('.image').width();
$('.image').css({
'height': cw + 'px'
});
};
</script>
You can do it if your images will be square
.card {
display: flex;
flex-flow: row wrap;
width: 100%;
margin-bottom: 15px;
}
.card .title {
line-height: 3rem;
font-size: 1.5rem;
font-weight: 300;
}
.card .action {
background: grey;
order: 3;
flex-basis: 100%;
}
.card .content {
background: red;
order: 2;
flex-grow: 1;
}
.card .image {
background: gold;
order: 1;
flex: 1;
max-width: 30vw; /* scale img block with page */
}
.card .image img {
display: block;
width: 100%;
}
<div class="row">
<div class="medium-6 columns end">
<div class="card">
<div class="content">
<span class="title">
Just a Title
</span>
</div>
<div class="action">
<p>this is an action</p>
</div>
<div class="image">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=img%20goes%20here&w=300&h=300">
</div>
</div>
<div class="card">
<div class="content">
<span class="title">
Title with some text
</span>
<P>This is some content under the title</P>
</div>
<div class="action">
<p>this is an action</p>
</div>
<div class="image">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=img%20goes%20here&w=300&h=300">
</div>
</div>
<div class="card">
<div class="content">
<span class="title">
Title with more text
</span>
<P>This is some content under the title</P>
<P>Second line of text</P>
</div>
<div class="action">
<p>this is an action</p>
</div>
<div class="image">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=img%20goes%20here&w=300&h=300">
</div>
</div>
</div>
</div>
I want the following:
======
=img1= Text
======
======
=img2= Some more Text
======
Current HTML:
<div id="divison-id">
<img src="images/img1.png">
<p>Text</p>
<img src="images/img2.png">
<p>Some more text</p>
</div>
When I add the following CSS rule:
#division-id p {
display: in-line
}
I get this:
====== ======
=img1= Text =img2= Some more Text
====== ======
Why is this happening and what would be the correct way to solve this?
If you can change the HTML a bit, try wrapping the <p> and <img /> inside another <div> or something like this:
#divison-id p {
display: inline;
}
<div id="divison-id">
<div>
<img src="images/img1.png">
<p>Text</p>
</div>
<div>
<img src="images/img2.png">
<p>Some more text</p>
</div>
</div>
And note, there are two errors:
There's no display: in-line.
The selector is wrong.
Try this:
Add <br> tag after each <p> tag. Like this:
<div id="divison-id">
<img src="images/img1.png"
<p>Text goes right</p><br/>
<img src="images/img2.png"
<p>Some more text</p><br/>
</div>
CSS:
#divison-id p{ display:inline; vertical-align:top}
Try this
I added <div class='item'> to wrap each image and text
<div id="division-id">
<div class='item'>
<a href="[href]">
<img src="images/img1.png">
</a>
<p>Text</p>
</div>
<div class='item'>
<a href="[href]">
<img src="images/img2.png">
</a>
<p>Some more text</p>
</div>
</div>
<style>
#division-id p {
display: inline
}
</style>
Hope it helps
I prefer to use lis instead of divs and brs, because you don't need to style anything extra.
ul {
list-style: none;
margin: 0;
}
ul li a {
display: inline-block;
float: left;
margin-right: 10px;
}
<ul id="division-id">
<li>
<img src="images/img1.png">
<p>Text</p>
</li>
<li>
<img src="images/img2.png">
<p>Some more text</p>
</li>
</ul>
#division-id p:after
{
content: '';
display: block;
clear: both;
}
you could try this. I personally suggest that you do not use float:left cuz it will limit your styling in terms of height and width.
<style type="text/css">
.division_id div, .division_id>div>p{
display:inline-block;
}
.division_id>div>a{
vertical-align:middle;
}
</style>
<html>
<div class="division_id">
<div>
<img src="images/img1.png">
<p>Text</p>
</div>
<div>
<img src="images/img2.png">
<p>Some more text</p>
</div>
</div>
</html>
I am a newb. I have finally figured out how to get images aligned on my main page in my index.html along with code in my default.css.
Now I would like to add text under each image. I know this should be easy, but am not able to find anything that seems to work.
Here is my HTML Code:
<div id="random">
<img src="1.jpg" />
<img src="2.jpg" />
<img src="3.jpg" />
</div>
Here is my CSS code:
#random{
max-width: 650px
}
#random img{
display:inline-block;
width:80px;
}
Wrap your images in a container, and put the text under them. Something like this:
http://jsfiddle.net/8xf2N/1/
<div id="random">
<div class='img-container'>
<img src="1.jpg" />
<p>Image One</p>
</div>
<div class='img-container'>
<img src="2.jpg" />
<p>Image Two</p>
</div>
<div class='img-container'>
<img src="3.jpg" />
<p> Image Three</p>
</div>
</div>
CSS:
#random{
max-width: 650px
}
#random img{
width:80px;
}
.img-container{
display: inline-block;
}
You can always use the HTML 5 figure tag. (Assuming your website is follwoing HTML 5 standards). That way, you can nest a tag and style them.
<div id="random>
<figure>
<img src="1.jpg"/>
<figcaption>Your Caption</figcaption>
</figure>
</div>
That way you have selectors to style them with CSS as well.
Try:
#random{
max-width: 650px
}
#random .image-wrap{
display:inline-block;
width:80px;
}
<div id="random">
<div class="image-wrap">
<img src="1.jpg" />
<p>Text for image 1</p>
</div>
<div class="image-wrap">
<img src="2.jpg" />
<p>Text for image 2</p>
</div>
<div class="image-wrap">
<img src="2.jpg" />
<p>Text for image 2</p>
</div>
</div>
You should wrap the images in a div. Here is a fiddle http://jsfiddle.net/a6pNw/
CSS:
#random{
max-width: 650px
}
#random div{
display:inline-block;
width:80px;
text-align:center;
}
HTML:
<div id="random">
<div>
<img src="http://placehold.it/80x80" />
<p>Some text</p>
</div>
<div>
<img src="http://placehold.it/80x80" />
<p>Some text</p>
</div>
<div>
<img src="http://placehold.it/80x80" />
<p>Some text</p>
</div>