i want to achieve the border and header like this -
[![][1]][1]
Does css have anything for it?
What i tried and works is-
.header{
margin-top:-10px;
background:#fff;
}
Are there any other options to achieve this.?
[1]: https://i.stack.imgur.com/iHCVG.jpg
You can use :before or :after
Fiddle
HTML:
<header></header>
CSS:
header{
border:3px solid;
height:300px;
position:relative;
}
header:before{
content:'Header';
position:absolute;
top:-10px;
left:50px;
background:#fff;
padding:0 20px;
}
You can also use two elements:
header and h1
JSFiddle
html:
<header><h1>Header</h1></header>
CSS:
header{
border:3px solid;
height:300px;
position:relative;
}
header > h1{
position:absolute;
top:-35px;
left:50px;
background:#fff;
padding:0 20px;
}
Or keep it really simple and use fieldset.
JSFiddle
<fieldset>
<legend>Header</legend>
</fieldset>
As already commented, you could use fieldset. Which will work, but isn't the cleanest solution if it isn't used for a form.
The HTML <fieldset> element is used to group several controls as well as labels (<label>) within a web form.
Source.
As alternativ you could try this code:
HTML:
<div class="box">
<h3>title</h3>
</div>
CSS:
.box
width: 400px;
height: 200px;
border: 1px solid black;
}
.box > h3 {
position: absolute;
background: white;
height: 20px;
margin-top: -12px;
margin-left: 10px;
padding: 0 10px;
}
DEMO
Related
I am building webpage with school events. On my webpage I am trying to create div(eventContainer) in which I got another div(eventImgContainer) with an image, and this image when hover do an action, e.g. blur or opacity.
The problem is that it does not respond to hover when div with img is inside any other div.
I was looking at syntax related to hover like ">" or "+" or ', '... nothing seams to work. Any ideas why?
I really want to use only css for this/
html:
<div class="eventContainer">
<div class="eventDescription"><!-- here code with event description--></div>
<div class="eventImgContainer">
<img src="1_Zdjecia/event_1/1.jpg" id="Photo1" title="football">
<p class="hidedText">Go to Gallery</p>
</div>
</div>
CSS:
.eventContainer{
z-index: -1;
position:relative;
margin:auto;
left:0;
right:0;
width:700px;
height:270px;
background-color: #E6E6E6;
border: 4px solid white;
}
.eventImgContainer{
position:relative;
width:375px;
height:217px;
top:20px;
left: 305px;
margin:0;
}
.eventImgContainer img {
position:absolute;
width:100%;
display:block;
}
.eventimgcontainer:hover #Photo1 {
opacity:0.5;
width:400;
}
You last css rules is wrong
.eventImgContainer:hover #Photo1 {
opacity: 0.5;
width: 400px;
}
CSS is case sensitive !
And you shouldn't have negative z-index (you should remove the z-index property or set a positive value).
It works for me when I just change z-index: -1; to z-index: 1;
And your last selector (eventimgcontainer) is wrong, should be "eventImgContainer". But your example works also with this lower case selector. The problem is only your z-index.
.eventContainer{
z-index: 1;
position:relative;
margin:auto;
left:0;
right:0;
width:700px;
height:270px;
background-color: #E6E6E6;
border: 4px solid white;
}
.eventImgContainer{
position:relative;
width:375px;
height:217px;
top:20px;
left: 305px;
margin:0;
}
.eventImgContainer img {
position:absolute;
width:100%;
display:block;
}
.eventImgContainer #Photo1 {
opacity:0.5;
width:400;
}
first of all remove the z-index
.eventContainer{
position:relative;
margin:auto;
left:0;
right:0;
width:700px;
height:270px;
background-color: #E6E6E6;
border: 4px solid white;
}
and then correct the name of the class
.eventImgContainer:hover #Photo1{
opacity:0.5;
width:400;
}
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>
I'm working on a practice project and I'm facing a problem. There is a border box with the border cut off near the text and the button. I shall appreciate it if you people can tell me how to make a box like that. I tried several methods but they were not good at different viewports.
Take a look. Workinglink
HTML:
<div>
<h1>Title</h1>
</div>
CSS:
div{
height:100px;
width:100px;
border:2px solid black;
}
h1{
width:30px;
margin-top:-10px;
margin-left:5px;
background:white;
}
Here is one way you can do it.
Using "margin" in CSS you can do it.
<div class="back-box">
<div class="second-box">
<div class="text-box">
<h2>
My Text here
</h2>
</div>
</div>
</div>
CSS
.back-box{ background-color: black; width: 500px; height: 200px; padding: 50px }
.second-box { border: 1px solid white; width: 500px; height: 200px }
.text-box{ background-color: black; margin-top:-30px; width:200px; margin-left:auto; margin-right:auto; text-align: center }
h2 { color: white; }
Demo
Basically, I'm trying to setup something that looks like this:
However, my code for some reason isn't working. Fist of all, in teh tinkerbin, my arrow image isn't even showing. It works fine on my computer though, so I'm not sure why this is. I also tried jsfiddle and it didn't work there either.
I can get the arrow to be there just fine, but I can't get the text to be centered vertically, let alone even go insie the gray box when the image is there. That is what is confusing me here.
HTML:
<div id="answers">
<div id="arrowcenter"></div><div id="answerstext">Text Next To Arrow</div>
</div><!-- end grayAnswer -->
CsS:
#answers {
width:220px;
height:50px;
background-color:#DDDDDD;
border-top:1px solid black;
border-bottom:1px solid black;
margin-top:20px;
}
#arrowcenter {
width:71px;
height:31px;
background-image:url('http://fortmovies.com/brazil/arrow.png');
background-position:0 50%;
background-repeat:no-repeat;
height:100%;
margin-left:-140px; }
#answerstext {
margin-top:0;
}
1st of all your arrow was isn't showing because you were using margin-left:140px; in #arrow_center
See my Fiddle
Just with 1 <div> Fiddle
This answer is inspired by Mr. Alien's answer of using less markup (id optional).
Reference: jsFiddle
HTML:
<span>Masculino</span>
CSS:
span {
background-image:url('http://fortmovies.com/brazil/arrow.png'); /* 70px x 31px */
background-position: 3px 10px;
background-repeat: no-repeat;
background-color: #DDDDDD;
border-top: 1px solid black;
border-bottom: 1px solid black;
font-family: Arial;
font-weight: bold;
font-size: 30px;
padding: 8px 10px 8px 80px;
}
Status Update: jsFiddle with Div for Navbar method
Just remove margin-left:-140px; and add float:left; to #arrowcenter
Working Demo
Use the tag instead of the tag.
The tag defaults to display: block, which prevents the content of different s to be aligned next to each other. tags default to display:inline; which suits your ideas better. As analternative you could also set those display rules in your css.
#answers {
width:220px;
height:50px;
background-color:#DDDDDD;
border-top:1px solid black;
border-bottom:1px solid black;
margin-top:20px;
}
#arrowcenter {
width:75px;
height:31px;
background-image:url('http://fortmovies.com/brazil/arrow.png');
background-position:0 50%;
background-repeat:no-repeat;
height:100%;
float: left;
}
#answerstext {
margin-top: 16px;
}
Little bit changes that i made in just in your css as follow, and it is working...
#answers {
width:220px;
height:50px;
background-color:#DDDDDD;
border-top:1px solid black;
border-bottom:1px solid black;
margin-top:20px;
}
#arrowcenter {
width:120px;
height:31px; float:left;
background-image:url('http://fortmovies.com/brazil/arrow.png');
background-position:0 50%;
background-repeat:no-repeat;
height:100%;
}
#answerstext {
margin-top:0; float:left; height:50px; line-height:50px;
}
Working Demo
OR
Use this CSS
#answers
{
width: 220px;
height: 50px;
background-color: #DDDDDD;
border-top: 1px solid black;
border-bottom: 1px solid black;
margin-top: 20px;
}
#arrowcenter
{
width: 100px;
height: 50px;
background-image: url('http://fortmovies.com/brazil/arrow.png');
background-position: left center;
background-repeat: no-repeat;
float:left;
}
#answerstext
{
line-height:50px;
margin-left:10px;
font-size:20px;
font-family:Arial;
font-weight:bolder;
}
Use this in HTML :-
<div id="answers">
<div id="arrowcenter">
 </div>
<div id="answerstext">
Masculino</div>
</div>
I hope it'll helps!! :)
What's the purpose of margin-left:-140px; it moves #arrowcenter off-screen remove it and you'll be fine.
Also set both divs to display:inline-block and vertical align appropriately
#arrowcenter {
...
display:inline-block;
vertical-align:middle;
}
#answerstext {
...
display:inline-block;
vertical-align:middle;
}
http://jsfiddle.net/XEk5d/
i am trying to get a div to be my background and am using absolute positioning to achieve it. everything works fine except for the fact that it appears above anything in the normal flow and fiddling with z-indexes does absolutely nothing.
<div id="blind">
<div id="blindbackground"></div>
<div id="blindcontainer">
<div class="loader">
<img class='loader' src="/img/loader.gif"/>
</div>
</div>
<div id="blindclosecontainer">
<img id='blindclose' src="/img/close.gif"/>
</div>
</div>
and this is the css:
#blind{
position :absolute;
width:100%;
z-index: 2;
border-bottom: 1px silver solid;
}
#blindclosecontainer{
text-align: right;
}
#blindbackground{
position:absolute;
top:0;
width:100%;
height:100%;
background-color: white;
filter:alpha(opacity=60);
opacity:0.6;
}
#blindcontainer{
margin:auto;
width:500px;
background-color: white;
padding:10px;
}
.loader{
margin: auto;
width:18px;
margin-top:10px;
margin-bottom: 5px;
}
Add position:relative; to the #blindcontainer and #blindclosecontainer classes.