This question already has answers here:
CSS technique for a horizontal line with words in the middle
(34 answers)
Closed 3 years ago.
I would like to have a divider on my page that looks like this:
What is the best way to do that?
html
<h3><span>My latest work</span></h3>
css
h3 {
position:relative;
text-align:center;}
h3 span {
display:inline-block;
padding:0 10px;
background:#fff;
}
h3:before {
content:"";
display:block;
position:absolute;
z-index:-1;
left:0;
right:0;
top:50%;
height:1px;
background:#ccc;
}
We can do this without images or masking lines like so:
HTML
<div class="rule">
<div class="line"><div></div></div>
<div class="words">words are cool</div>
<div class="line"><div></div></div>
</div>
CSS
.rule {
display: table;
}
.rule>div {
display: table-cell;
white-space:nowrap;
}
.line>div {
border-bottom: 1px solid silver;
height: 1px;
}
.words {
padding: 0 5px;
}
.line {
width: 50%;
vertical-align: middle;
}
Demo: http://jsfiddle.net/5tqE5/1/
This uses attr() which is not supported in older browsers. It could be replaced with an extra element.
<div class="lines" data-text="Some Text Goes Here"></div>
.lines {
position: relative;
font-size: 20px;
font-family: sans-serif;
margin: 0 auto;
border-top: 1px solid silver;
margin-top: 20px;
}
.lines:before{
content: attr(data-text);
background-color: #fff;
position: absolute;
text-align: center;
left: 50%;
width: 220px;
margin-left: -110px;
padding: 10px;
top: -20px;
}
Dunno about the 'best' - you've given no terms by which to assess that. Smallest, fastest, most compatible, etc, etc.
Anyhoo, I just took a 1-pixel wide slice of your image and saved it. I then use it as the background-image of the div.
CSS:
#myDiv
{
background: url(horizline1x41px.png) repeat;
text-align: center;
line-height: 41px;
}
#myDiv span
{
padding-left: 16px;
padding-right: 16px;
background: white;
font-weight: bold;
font-size: 1.5em;
}
HTML:
<div id='myDiv'><span>OUR LATEST WORK</span></div>
Demo: http://jsfiddle.net/8zve4/
I don't like the extra markup, but this should work.
CSS:
.hline {
border: 1px solid #EEE;
color: #666;
font-family: helvetica;
font-weight: bold;
font-variant: small-caps;
letter-spacing: .1em;
line-height: 0px;
text-align: center;
text-transform: uppercase;
}
.hline > span {
background-color: #FFF;
padding: 0px 1em;
}
HTML:
<div class="hline"><span>Our latest work</span></div>
Related
This question already has answers here:
Line before and after title over image [duplicate]
(2 answers)
Closed 7 years ago.
This is the html part :
<div class="sama_productblocks_grid">
<div class="title-bar">
<h3>Nieuwste producten</h3>
</div>
.....
</div>
This is the css
.sama_productblocks_grid .title-bar h3 {
margin: 0;
position: relative;z-index: 3;
font-size:18px;
display: inline-block;
color: #6D6C6C;
font-weight: 400;
text-transform: uppercase;
font-family: "Open Sans",sans-serif !important;
padding: 0px 65px;
}
/*newest product*/
.title-bar{
position: absolute;
overflow: hidden;
margin-bottom: 10px;
text-align: center;
border-bottom:3px solid black;
z-index: 3;
width:100%;
margin-bottom: 10px;
}
.sama_productblocks_descrition {margin-top:40px;}
What i want to achieve is to put a line before and after the text: Nieuwste producten. So I want to look like this:
----------- Nieuwste producten ------------
Is this what you are looking for?
body {
margin-top: 50px;
}
.hr-div {
height: 1px;
background-color: #e6e6e7;
text-align: center;
margin: 10px 0 10px -10px;
}
.hr-span {
background-color: white;
position: relative;
top: -10px;
padding:0 10px;
}
<div class="hr-div">
<span class="hr-span">Your Title Here</span>
</div>
Do you mean something like this:
h3:before {
content: "---------------- "
}
h3:after {
content: " ----------------"
}
This question already has answers here:
How to position text over an image with CSS
(8 answers)
Closed 8 years ago.
I am trying to display some text over an image : http://jsfiddle.net/5AUMA/31/
I need to align this text at the bottom part of the image
I tried putting this in css:
.head_img p {
position: absolute;
left: 0;
width: 100%;
vertical-align:bottom;
}
but this doesn't work ...
.............
Secondly I want this to be scalable with the screen width ... if width less than that of a 13" laptop .. remove the image but keep the text
How do i do that
Try this:
body{
color: #202020; /*#3d3636 #fffaf0; #fdfdfd 8c8c8c*/
font-size:100%;
font-family: 'Maven Pro', sans-serif;
line-height:1.4em;
min-height:100%;
/*padding-left: 5%;*/
background-color: #fdfdfd;
}
.head_img{
margin-top:10%;
font-size:1.5em;
line-height: 1em;
font-weight: bold;
font-style: italic;
color: #000000;
text-align:center;
position:relative;
}
.head_img p {
position: absolute;
left: 0;
width: 100%;
bottom:5px;
margin:0;
padding:0;
}
#media (max-width: 1366px) {
.head_img img { display:none; }
}
I added position:relative; to the .head_img class and positioned the p element absolutely with a bottom of 5px.
Then added a media query to hide the image once the screen width goes below 1366px. You will have to adjust that breakpoint, but I believe it's a common screen width for 13" laptops.
Updated fiddle: http://jsfiddle.net/5AUMA/33/
http://jsfiddle.net/5AUMA/32/
your markup wasn't correctly set (moved the paragraph in the same div that contains the image)
<body class ="body">
<div class ="head_img">
<div style="text-align:center;"><img style="min-width:50%; min-height:60%;" src = "http://i.imgur.com/H56PB85.jpg"/>
<p> display this text over the image <br> and at the bottom part of the image</br></p>
</div>
</div>
</body>
also look for position:relative on the container div to make things work on all browsers
body{
color: #202020; /*#3d3636 #fffaf0; #fdfdfd 8c8c8c*/
font-size:100%;
font-family: 'Maven Pro', sans-serif;
line-height:1.4em;
min-height:100%;
/*padding-left: 5%;*/
background-color: #fdfdfd;
}
.head_img{
margin-top:10%;
font-size:1.5em;
line-height: 1em;
font-weight: bold;
font-style: italic;
color: #000000;
text-align:center;
position: relative; /* HERE */
}
.head_img p {
position: absolute;
left: 0;
width: 100%;
bottom: 0;
color: white;
}
You need to make couple of changes to your css to make it work as follows.
.head_img p {
position: absolute;
left: 0;
width: 100%;
top: 0;--> Added
color: white;--> Added
}
.head_img{
<--Margin Removed-->
font-size:1.5em;
line-height: 1em;
font-weight: bold;
font-style: italic;
color: #000000;
text-align:center;
}
WORKING FIDDLE
Now to make your image to hide in particular width you can use media queries something like this
#media (max-width: 768px) {
.head_img img{
display:none;
}
}
try this
body {
color: #202020;
font-size: 100%;
font-family: 'Maven Pro', sans-serif;
line-height: 1.4em;
min-height: 100%;
background-color: #fdfdfd;
}
.head_img {
margin-top: 10%;
font-size: 1.5em;
line-height: 1em;
font-weight: bold;
font-style: italic;
color: #000000;
text-align: center;
position: relative;
}
.head_img p {
left: 0;
width: 100%;
position: absolute;
bottom: 5px;
margin: 0;
color: #fff;
}
<body class="body">
<div class="head_img">
<div style="text-align:center;">
<img style="min-width:50%; min-height:60%;" src="http://i.imgur.com/H56PB85.jpg" />
</div>
<p>display this text over the image
<br>and at the bottom part of the image</br>
</p>
</div>
</body>
i have added
top: 394px;
color: #fff;
in .head_img p jsfiddle
body {
background-color: #fdfdfd;
color: #202020;
font-family: "Maven Pro",sans-serif;
font-size: 100%;
line-height: 1.4em;
min-height: 100%;
}
.innerimg {
background: url("http://i.imgur.com/H56PB85.jpg") no-repeat scroll center center rgba(0, 0, 0, 0);
border: 2px solid;
height: 500px;
width: 500px;
}
.head_img {
color: #000000;
font-size: 1.5em;
font-style: italic;
font-weight: bold;
line-height: 1em;
margin: 0 auto;
text-align: center;
width: 500px;
}
.head_img p {
display: table-cell;
height: 480px;
text-align: center;
vertical-align: bottom;
width: 500px;
}
<body class ="body">
<div class ="head_img">
<div class="innerimg" style="text-align:center;">
<p> display this text over the image <br> and at the bottom part of the image</br></p>
</div>
</div>
</body>
add HTML tags
<h2><span>display this text over the image <br> and at the bottom part of the image</span></h2>
CSS
h2 span {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.7);
padding: 10px;
}
h2 {
position: absolute;
top: 200px;
left: 0;
width: 100%;
}
i have updated the code in this FIDDLe
I have website http://11klassniki.ru and I try to put text in in the middle using text-align:center but it doesn't work.
#konkurs_ege {
position:absolute;
top:10px;
left:380px;
width:140px;
height:80px;
background-image:url('http://11klassniki.ru/banners/konkurs_ege.jpg');
}
#konkurs_ege a {
text-decoration: none;
text-shadow: -1px -1px 0 #000000;
text-transform: uppercase;
font: 16px Arial, sans-serif;
font-weight:700;
width:100%;
text-align:center;
vertical-align: middle;
}
Here is code
<div id="konkurs_ege">
<a href='http://11klassniki.ru/view_post.php?id=144'>Konkurs!<br>how I made<br>IT</a>
</div>
I would like to have text: "Konkurs! how I made IT" in the middle of box (width:140px;
height:80px).
You need to have display: block.
.secondArticle a {
display: block;
text-align: center;
}
If you do not want to center the paragraph below the image, you can use span tag.
.secondArticle a span {
display: block;
text-align: center;
}
I believe the issue is that you're applying the text-center to the a tag, instead of the container. If you add it to the container ( konjurs_ege ), it should work. Worked for me on Chrome and FF.
#konkurs_ege {
position: absolute;
top: 10px;
left: 380px;
width: 140px;
height: 80px;
text-align: center;
background-image: url('http://11klassniki.ru/banners/konkurs_ege.jpg');
}
I have this div wedged between two bars(other divs), though when I add text into the equation, the div gets repositioned down. It works as intended without the p element and its children. Here's a fiddle to demonstrate the issue: http://jsfiddle.net/57uSQ/
this is the HTML that is causing the problem:
<p>
<span class="name">DOLCE & GABBANA</span>
</br>
<span class="title">THE ONE</span>
</p>
And the correlating CSS:
.videoDesc {
display: inline-block;
border: 1px solid #000000;
border-right: 0px;
height: 200px;
width: 500px;
}
.videoDesc p {
display: inline-block;
margin: 0;
padding: 0;
}
.videoDesc .name {
display: inline-block;
padding: 0px;
}
.videoDesc .title {
display: inline-block;
padding: 0px;
}
.title {
font-family: Lekton;
font-size: 1.25em;
}
.name {
font-family: Oswald;
font-weight: lighter;
font-size: 2.5em;
letter-spacing: 10px;
padding-left: 5px;
}
You need to add vertical-align:top to .videoDesc:
.videoDesc {
display: inline-block;
border: 1px solid #000000;
border-right: 0px;
height: 200px;
width: 500px;
vertical-align:top;
}
jsFiddle example
The default vertical alignment is baseline, which is causing the behavior you see.
http://jsfiddle.net/8zkqu/1/
<div id="button" class="g">
<p>Discover me!</p>
</div> <!-- id button class g -->
and .css file looks like that
#button{
z-index: 1;
font-size: 20px;
border-radius: 5px;
width: 130px;
height: 40px;
position: absolute;
top:20px;
right: 20px;
font-weight: bold;
text-align: center;
}
.g {
background-color: rgb(94,179,74);
color: white;
border: 3px solid green;
position: absolute;
}
Its start to being annoying! How to center text inside buttoN?
I assume you're looking to vertical-align the element ?
Try with display:table-cell
HTML
<div id="button" class="g">
<span>Discover me!</span>
</div> <!-- id button class g -->
CSS
#button{
z-index: 1;
font-size: 20px;
border-radius: 5px;
width: 130px;
height: 40px;
display:table-cell;
vertical-align:middle;
font-weight: bold;
text-align: center;
}
.g {
background-color: rgb(94,179,74);
color: white;
border: 3px solid green;
}
JSFiddle.
Text-aling:center centers the element horinzontal and vertical-align:middle vertical.
This update to the CSS should do the trick:
.g p {
margin: 0;
line-height: 40px;
}
Working Example
Add this to your css:
#button p{
margin: 0px;
line-height: 40px;
}
Margins are added to <p> elements by default, the code above removes them. And line-height centers the text in the button, to achieve this in the future set the line-height to be equal to the button height.
Another option: Add this to your CSS:
#button p{
line-height:0px;
}