How can I align text to the bottom right of a big <a> element inside a div?
Here is what I have, but I want the text at the bottom of the box. I've searched a lot and nothing has worked for me:
<div class="thumbnail">
Link to somewhere
</div>
with the following css:
.thumbnail{
width: 200px;
height: 200px;}
.thumbnail a{
display: block;
height: 100%;
width: 100%;
text-align: right;
background-color: lightgrey;}
http://jsfiddle.net/8JsPV/
Thank you
I changed your HTML and put the entire thing in an <a> tag so it is all clickable. jsFiddle Here.
HTML:
<div class="thumbnail"><span>Link to somewhere</span></div>
CSS:
.thumbnail{
width: 200px;
height: 200px;
position: relative;
background-color: lightgrey;
}
.thumbnail span{
display: block;
position: absolute;
bottom: 0;
right: 0;
}
EDIT:
To do it WITHOUT putting an div inside the <a>, try this.
This should help if you change the HTML accordingly:
.thumbnail{
position: absolute;
bottom: 0;
right: 0;
}
a{
display: block;
position: relative;
width: 200px;
height: 200px;
background-color: lightgrey;
}
HTML:
<div class="thumbnail">Link to somewhere</div>
Updated fiddle
Try this
.thumbnail
{
position: relative;
width: 200px;
height: 200px;
background-color: Orange;
display: block;
}
.thumbnail span
{
position: absolute;
right: 0px;
bottom: 0px;
display: block;
text-align: right;
background-color: Gray;
}
and change the HTML like so
<a class="thumbnail" href="#"><img
src="http://www.healthfiend.com/wp-content/uploads/2011/01/Facial-Exercises.jpg"
alt="face" /><span>Link to somewhere</span></a>
This makes the whole thing clickable and aligns the text to the bottom right. I replaced you div with an img tag as I assume for a thumbnail this is actually what you probably want in the end. Right?
Related
I made a box with <div class="box"></div> then I styled it in css with .box {} but I want to make it so when I click the box, it brings me to another page. Here is my current code.
.box18 {
width: 240px; height: 230px;
outline: 5px solid black;
position: absolute; top: 450px; right: 140px;
background-image: url(wfc.jpg);
background-position: top;
}
<div class="box18" title="Credit: Hasbro/Takara"></div>
I tried to add an anchor tag within the div or within the css styling but it didnt work and made the text dissapear.
You just need to wrap your div in an anchor tag.
.box18 {
width: 240px; height: 230px;
outline: 5px solid black;
position: absolute; top: 450px; right: 140px;
background-image: url(wfc.jpg);
background-position: top;
}
<a href="https://stackoverflow.com" target="_blank">
<div class="box18" title="Credit: Hasbro/Takara"></div>
</a>
Only solution I found was to put a position: fixed on element I want to fully see. Any other options? (I dont want to 'cool-image' fixed). Help or hint would be awesome. Also, if anyone can explain solution - that would be even better
Fiddle: JSFiddle
HTML
<div class="img-cont">
<div id="slider">
<ul>
<li class="slide">
<img src="http://www.sportspearl.com/wp-content/uploads/2017/05/football-150x150.png" >
<div class="cool-image"></div>
</li>
</ul>
</div>
</div>
CSS
.img-cont{
height: 270px;
position: relative;
}
#slider {
position: relative;
background: green;
overflow: hidden;
width: 440px;
height: 200px;
}
#slider ul{
position: relative;
margin: 0;
padding: 0;
}
#slider ul li {
position: relative;
display: block;
float: left;
margin: 0;
padding: 0;
width: 440px;
height: 270px;
text-align: center;
line-height: 300px;
}
div.cool-image{
background-color: white;
position: absolute;
border: 5px solid #EEEEEE;
width: 650px;
height: 350px;
z-index: 1;
display: inline-block;
background-repeat: no-repeat;
background-image: url(https://upload.wikimedia.org/wikipedia/commons/thumb/7/7a/Basketball.png/170px-Basketball.png);
margin-left: -40px; /* Just to product situation */
display: inline-block;
}
Unfortunately, you can't. The child element is only capable of changing within the parents region when the position is not set to fixed or absolute.
If you don't want to make the child fixed, you could try position:absolute; and set the parent to position: relative;
Like this...
.slide img {
position: absolute;
z-index: 2;
}
.slide {
position: relative;
}
Or you could try to only hide the overflow on 1 direction. Like overflow-y:hidden; Or overflow-x: hidden;
i have two divs
first div : text-logo
.text-logo {
width: 250px;
height: 60px;
margin: auto;
border: 2px solid #07a2a0;
border-radius: 15px 50px 15px 50px;
margin-top: 100px;
}
<div class="text-logo"><h4>Just training/cit</h4></div>
second div : image-logo
.image-logo { overflow: hidden; height: 500px;}
.image-logo .left
{
float: left ;
width: 30%;
position: relative;
}
.image-logo .right
{
float: left;
width: 70%;
}
.image-logo .left img
{
width: 180px;
height: 180px;
position: relative;
bottom: 50px;
}
<div class="image-logo">
<div class="left">
<img src="images/logo.png">
</div>
<div class="right">
<h2>Being auomated much more easy than the manual things
</h2>
<hr>
</div>
i cant see the blue logo with the original size, the upper part of the logo is hidden ,
the picture will show you the problem
,
Try to add z-index
.image-logo .left img
{
width: 180px;
height: 180px;
position: relative;
bottom: 50px;
z-index:2;
}
That's because the div .text-logo is above your logo div. You should change the z-index of one of them. It defines which element should be above another element. Use for your z-index a realistic value, to keep your code a bit cleaner.
.image-logo .left img {
width: 180px;
height: 180px;
position: relative;
bottom: 50px;
z-index:5;
}
Check that the element's color is not the same as the background color, as that will obviously make you not to see your element.
I have been a victim of this severally. Hope it helps someone.
I am having trouble centering content of one div inside of another because the content doesn't appear.
#searchbkg {
postition: relative;
width: 100%;
height: 700px;
background-color: #85e085;
}
#searchcentre {
position: absolute;
width: 50%;
margin: 0 auto;
}
<div id="searchbkg">
<div id="searchcentre">Test</div>
</div>
The green box appears but there is no text inside of it.
Your text is appearing fine, but it won't be centered because you have position: absolute; on the inside div. Change it to position: relative; and it will center horizontally. If you need the text to be centered within the div, you can also apply a text-align: center;.
#searchbkg {
position: relative;
width: 100%;
height: 700px;
background-color: #85e085;
}
#searchcentre {
position: relative;
width: 50%;
margin: 0 auto;
text-align: center;
border: 1px solid red;
}
<div id="searchbkg">
<div id="searchcentre">This is a centered div!</div>
</div>
You need to make following 3 changes to make your content in center;
You have typo in one css property inside styles of #searchbkg. There is postition while it should be position.
Remove position: absolute from #searchcentre if not needed (Absolute positioning should be used only if you wants to place one element over another).
Add text-align: center in #searchcentre.
#searchbkg{
position: relative;
width: 100%;
height: 700px;
background-color: #85e085;
}
#searchcentre{
text-align: center;
background: orange;
width: 50%;
margin: 0 auto;
}
<div id="searchbkg">
<div id="searchcentre">Test</div>
</div>
try this:
#searchbkg{
postition: relative;
width: 100%;
height: 700px;
background-color: #85e085;
text-align:center;
}
#searchcentre{
display: inline-block;
width: 50%;
}
<div id="searchbkg">
<div id="searchcentre">Test</div>
</div>
I have the following HTML:
<div class="square">
<a class="block" href="#Model.HyperLink1">
<span>#Model.Text1</span>
</a>
</div>
The CSS is:
.square {
width: 140px;
float: left;
}
.block {
display: block;
width: 140px;
height: 140px;
}
a.block span {
position: absolute;
bottom: 0;
}
However the span appears at the bottom of my page not at the bottom of the square block I have defined.
How can I get the span or text of a hyperlink to appear at the bottom of the block?
Thanks
Add position: relative to the block.
.block {
display: block;
width: 140px;
height: 140px;
position: relative;
}