Hello, How can I do that with CSS? I have seen this somewhere, but can't remember. A fluid border with a text within it.
It's not that complicated, but it's an illusion. The text isn't actually breaking the border, but is layered on top using -margins. You have to set your text to have a background color (in this case white). .mybox{ height: 100px; width: 200px; border: 1px solid #000; text-align:center; } .mytext{ background: #FFF; margin-top: -30px; /* Or whatever you need to move it up far enough. It will depend on your font size. */ }
you can make this with just a single line. <legend>This is a Text in Border</legend> you can add styles in stylesheet.
Add background-color: (color); to the .mybox. So an example with a blue background: .mybox{ background-color: #0000FF; height: 100px; width: 200px; border: 1px solid #000; text-align:center; } .mytext{ background: #FFF; margin-top: -30px; /* Or whatever you need to move it up far enough. It will depend on your font size. */ } Code (markup): Or as the user said above you can use the legend tag. Here is an example: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_fieldset
if you want to style the border then you should style the fieldset an example of style are mention here.
<html> <head> <title> <style> .mybox{ height: 100px; width: 200px; border: 1px solid #000; text-align:center; } .mytext{ background: #FFF; margin-top: -30px; } </style> <body> <h1 id="mytext"> Hello Saad</h1> this is not working
Its good that you are doing these changes in CSS many developers use PHTML files to make design changes.
Assuming it is a form -- if it's not a form you have NO BUSINESS using those tags... you know, semantic markup and all that. Suggesting fieldset and legend JUST because they want a border and offset text is some of the WORST ADVICE you could give somebody! Again, if you are choosing tags based on their default appearance, you are probably choosing all the wrong tags.