I have an image I would like to display as a circle with (border-radius:50%) and on the same line I would like to have some text with a set width and background. I would not like to hard code any values. What is the best way of accomplishing this?
Here is a picture
fiddle
<div class="header">
<img class="i" src="http://www.planwallpaper.com/static/images/colorful-triangles-background_yB0qTG6.jpg"/>
<p class="headingText">Hello</p>
</div>
.i {
width: 80px;
height: 80px;
border-radius: 50%;
}
.headingText {
color: white;
background: black;
display: inline-block;
width: 350px;
padding-top: 10px;
padding-bottom: 10px;
text-align: center;
}
You could try something like this:
.header
{
padding-top:26px;
padding-left:40px;
position:relative;
}
.i
{
position:absolute;
width:80px;
height:80px;
border-radius:50%;
top:0;
left:0;
}
.headingText
{
color:white;
background:black;
display:inline-block;
width:350px;
padding-top:10px;
padding-bottom:10px;
text-align:center;
}
Using pseudo-classes and absolute positioning you can get the effect you want.
The below answer uses your existing HTML so you don't have to change any of that and just changes your CSS.
You can add some more padding to the text to make it a bit more spaced out if required and the background should sort itself out.
.header {
position: relative;
display: inline-block;
margin: 30px;
overflow: visible;
}
.header img.i {
width: 80px;
height: 80px;
border-radius: 50%;
position: absolute;
bottom: 16px;
left: -40px;
z-index: 1;
overflow: hidden;
border: 3px solid black;
}
.header p.headingText {
padding: 16px 32px 16px 80px;
color: black;
border: 3px solid black;
}
<div class="header">
<img class="i" src="http://www.planwallpaper.com/static/images/colorful-triangles-background_yB0qTG6.jpg" />
<p class="headingText">Hello</p>
</div>
Just add position: absolute in i class then control the margin of headingtext:
HTML:
<div class="header">
<img class="i" src="http://www.planwallpaper.com/static/images/colorful-triangles-background_yB0qTG6.jpg"/>
<p class="headingText">Hello</p>
</div>
CSS:
.i
{
width:80px;
height:80px;
border-radius:50%;
position: absolute;
}
.headingText
{
color:white;
background:black;
display:inline-block;
width:350px;
padding-top:10px;
padding-bottom:10px;
text-align:center;
margin: 40px 0 0 37px;
}
FIDDLE
use a block element instead with a negative margin to the top (half circle size - half of the padding) and a margin to the left (half circle size). Just change:
.headingText {
/*display: inline-block;*/
display: block;
margin-top: -45px;
margin-left: 40px;
}
Example fiddle: https://jsfiddle.net/c67dchhv/
just simple make .header class position:relative; if you want to define any height and width you can, .i class position:absolute; give margin on .headingtext class https://jsfiddle.net/hamzanisar/aphzeyyt/ maybe it will helpful for you.
Related
i have a problem like this.
#relative{
position:relative;
width:100%;
height:100%;
text-align:center;
}
button{
margin:10px auto;
width:200px;
height:auto;
border:1px solid;
border-radius:5px;
}
#absolute{
position: absolute;
top: 0;
left:0;
height: 250px;
width: 100%;
border: solid 1px #000000;
color: blue;
font-weight: bold;
padding-top: 60px;
/*opacity:0;*/
}
button:hover{
background-color:#eed5a4;
}
<div id="relative">
<button>
Hover me if you can.
</button>
<div id="absolute">
Absolute its me dude!!<br>
If me >> opacity:0<br>
Button still cant be hover.
</div>
</div>
Any solution for this, and i dont know to use the good english language
Note : button keep like this, do not change the position absolute too.
- my english so bad :(
Add position:relative; and a higher z-index than that of the #absolute div to the button itself, like so:
HTML
<button id="relative-button">Hover me if you can.</button>
CSS
#absolute { z-index:1 }
#relative-button { position:relative; z-index:2 }
replace button css like this
button {
border: 1px solid;
border-radius: 5px;
height: auto;
margin: 10px auto;
position: relative; /* newly added */
width: 200px;
z-index: 9; /* newly added */
}
Thanks #daniel lisik, you are awesome people. Extraordinary
#relative{
position:relative;
width:100%;
height:100%;
text-align:center;
}
button{
position:relative;
z-index:5;
margin:10px auto;
width:200px;
height:auto;
border:1px solid;
border-radius:5px;
}
#absolute{
position: absolute;
z-index:1;
top: 0;
left:0;
height: 250px;
width: 100%;
border: solid 1px #000000;
color: blue;
font-weight: bold;
padding-top: 60px;
/*opacity:0;*/
}
button:hover{
background-color:#eed5a4;
}
<div id="relative">
<button>
Hover me if you can.
</button>
<div id="absolute">
Absolute its me dude!!<br>
If me >> opacity:0<br>
Button still cant be hover.
</div>
</div>
See this fiddle
JSFiddle
CSS:
.containers {
width:100%;
height:auto;
padding:10px;
margin-bottom:0px;
}
#id4 {
float:right;
margin-right:0;
display:inline;
border:5px solid red;
}
#id5 {
text-align:center;
border:5px solid red;
}
HTML:
<div class='containers'>
<div id='id4'>
margin-right:10px;
</div>
<div id='id5'>
center-text;
</div>
In this fiddle I want center-text to be center of the page, not at the center between left-border and float element.
The below is one possible option by adding position: absolute; right: 10px; to the id4 div. This will make the div always stay at 10px from the right margin. But it has to be noted that the element is no longer a float element.
Note: The texts would overlap if the result window is shrunk beyond a certain level. I will update the answer if and when I manage to find a fix for that.
.containers {
width: 100%;
height: auto;
padding: 10px;
margin-bottom: 0px;
text-align: center;
box-sizing: border-box;
}
#id4 {
display: inline-block;
position: absolute;
right: 10px;
border: 5px solid red;
}
#id5 {
display: inline-block;
border: 5px solid red;
}
.containers {
width:100%;
height:auto;
padding:10px;
margin-bottom:0px;
text-align:center;
}
#id4 {
float:right;
margin-right:0;
display:inline;
border:5px solid red;
}
#id5 {
margin: 0 auto;
display:inline-block;
border:5px solid red;
}
DEMO
im using this CSS for my website footer:
what would be the best way to make it display in the centre of the page. my website is responsive so they automatically go underneath each other when the screen is made smaller but when the screen is larger they are more to the left than the right.
i have created a fiddle here so you can also see the html:http://jsfiddle.net/x4A4B/
any help would be much appreciated
#footer {
width:100%;
min-height:500px;
position:relative;
bottom:0;
left:0;
border-top:4px solid #F36F25;
background-color:#666666;
color:#EEEEEE;
}
#footer-inner {
width:80%;
margin:0 auto 0 auto;
height:inherit;
}
#footer-top {
width:100%;
padding-top:10px;
border-bottom:2px #EEEEEE solid;
display:block;
}
#footer-left {
width: 290px;
display:inline-block;
padding: 5px 15px;
border-right:1px #EEEEEE solid;
vertical-align:top;
}
#footer-middle {
width: 294px; /* Account for margins + border values */
display:inline-block;
padding: 5px 15px;
margin: 0px 5px 5px 5px;
border-right:1px #EEEEEE solid;
vertical-align:top;
}
#footer-right {
width: 270px;
padding: 5px 15px;
display:inline-block;
vertical-align:top;
}
#footer-bottom {
margin-top:5px;
padding: 15px 15px;
font-size:12px;
}
are you talking about your Copyright label?
if I understood correctly, you need text-align:center; in footer-bottom as in
#footer-bottom {
margin-top:5px;
padding: 15px 15px;
font-size:12px;
text-align:center;
}
I think you'll need something like this regarding lay-out:
HTML:
<div class="wrapper">
<div class="left">
Content goes here
</div>
<div class="middle">
Content goes here
</div>
<div class="right">
Content goes here
</div>
</div>
CSS:
.wrapper{
position: relative;
float: left;
left: 20.00%;
width: 60.00%;
}
.left{
position: relative;
float: left;
left: 0%;
width: 32.00%;
}
.middle{
position: relative;
float: left;
left: 1.50%;
width: 32.00%;
}
.right{
position: relative;
float: right;
right: 0%;
width: 33.00%;
}
Of course, you'll have to fill the structure with your content, and modify the margins to completely suit your needs, but I think you'll manage to do that. This example is just to get the idea.
See it in action here: JSFiddle
How to create the pop up box as shown below in image with pure css
Here is what I have made with position:absolute which works fine but what I am trying to get is, is it possible to do only with one div by using :after or :before pseudo classes?
.pop{
background:#333;
display:inline-block;
width:250px;
height:120px;
border-radius:8px;
position:relative;
margin-top:25px
}
span{
position:absolute;
left:0;
top:-20px;
color:white;
display:inline-block;
border-radius:8px 8px 0 0;
background:#333;
padding:6px;
width:100px
}
Fiddle
This one is not much flexible, but does thing without additional markup, using pseudo element ::before.
.pop {
background: #333;
width: 250px;
height: 120px;
border-radius: 8px;
display: inline-block;
}
.pop::before {
content: "Pop up head";
display: block;
width: 90px;
background: #333;
border-radius: 8px;
padding: 3px;
margin-top: -14px;
text-align: center;
color: white;
}
<div class="pop"></div>
If I understood your question correctly this is what you need http://jsfiddle.net/slash197/Cup5Y/15/
HTML
<div class="holder">
<div class="header">Header</div>
<div class="pop">asd asd asd </div>
</div>
CSS
.holder {
position: relative;
width: 250px;
height: 140px;
}
.header {
position: absolute;
top: 0px;
left: 0px;
height: 20px;
background:#333;
color: #ffffff;
border-top-left-radius:8px;
border-top-right-radius:8px;
padding: 0px 10px;
}
.pop{
position: absolute;
top: 20px;
left: 0px;
background:#333;
color: #ffffff;
display:inline-block;
width:250px;
height:120px;
padding: 10px;
border-top-right-radius:8px;
border-bottom-left-radius:8px;
border-bottom-right-radius:8px;
}
First you need 2 divs, one for the "header" and one for the "content"
see my example http://jsfiddle.net/Cup5Y/13/
<div class="pop">
<div class="head">
Title
</div>
<div class="content">
</div>
</div>
I have icon, which on click adds new div's (columns) to div container. The problem is that when new div's (columns) appears the button doesn't shift right. Is it possible to somehow add position:fixed only inside the div?
Here is a few screens of what I have
And some code
<div id="grid">
<div id="add-col"></div>
<div class="clear"></div>
<div id="squares"></div>
</div>
#grid{
width:710px;
height: 470px;
border:1px dotted #dddddd;
display: none;
margin: 5px auto;
padding: 5px;
text-align:center;
overflow: auto;
}
#add-col{
margin:5px;
float:right;
background-image: url(images/table-add-column-icon.png);
width: 32px;
height: 32px;
cursor: pointer;
}
Your CSS would look like this :
#grid{
width:710px;
height: 470px;
border:1px dotted #dddddd;
display: none;
margin: 5px auto;
padding: 5px;
text-align:center;
overflow: auto;
position:relative; //added
}
#add-col{
margin:5px;
background-image: url(images/table-add-column-icon.png);
width: 32px;
height: 32px;
cursor: pointer;
position:absolute; //added
top:5px; //added
right:5px; //added
}
With position absolute you can place a button in a corner without having it to move from that position ever again.
To use a position you need to place position:relative; to its parent, else it will fly around the page.
Note: float has been deleted from #add-col