I'm trying to add a subtitle below the title on my page. I've got an image to the left of the existing title, and the title is centered to the middle of the image. I'm trying to add a subtitle in a smaller font below the title and I can't seem to figure it out. The code I'm using is like so:
<div class="top_bg">
<div class="wrap">
<div class="container">
<img src="images/grin.png" WIDTH="150" ALT="BRT" />
<div class="text">This is the Title</div>
<div class="clear"></div>
</div>
</div>
</div>
.container {
display:table;
width:100%;
height:auto;
background-color:#171717;
}
.container .text {
display:table-cell;
height:100%;
vertical-align:middle;
font: bold 70px Verdana;
color: #666666;
}
and here's what that looks like:
(I'm not including the code for the menu even though it's in the picture).
And what I'm trying to achieve is this:
Does anyone have any ideas?
You have a div.text which contains your title. Underneath that you need to place your subtitle. This code is called "html markup". You should use <h1> - <h6> tags for titles.
Here is an example (fiddle)
.header {
text-align: center;
}
.header img {
float: left;
}
.clear {
clear: both;
}
<div class="header">
<img src="http://dummyimage.com/100/000000/fff" />
<h1>Hello world</h1>
<h2>This is a subtitle</h2>
<div class="clear"></div>
</div>
Preview:
You can in fact do this with CSS.
div.text {
font-size: 32px;
font-weight: bold;
display: inline-block;
color: #fff;
vertical-align: top;
padding: 2px 1em;
}
div.text:after {
display: block;
text-align: center;
font-size: 20px;
margin-top: 1em;
content: "This is the subtitle";
}
.container {
background-color: #111;
display: inline-block;
}
.container img {
display: inline-block;
}
Now, whether you should do that with CSS is another question entirely. Content that's actually part of your page's message should be part of the page, not part of a style sheet.
Also, your "container" should probably be an <h1> tag. Also you don't need to close <img> tags, and self-closing tags are pointless in an HTML5 document (which yours may or may not be I suppose).
Try this:
<div class="top_bg">
<div class="wrap">
<div class="container">
<img src="images/grin.png" WIDTH="150" ALT="BRT" />
<div class="text">This is the Title</div>
<div class="subtitle">My subtitle</div>
<div class="clear"></div>
</div>
</div>
</div>
.text {
margin-bottom: 0px;
padding-bottom: 0px;
}
.subtitle {
margin-top: 0px;
padding-top: 0px;
}
There's probably 100 different ways to do this... Here's one. In your line of text, just use a <br /> and a <span>
<div class="text">This is the Title<br /><span>The SubTitle would go here</span></div>
Then style your subtitle like so:
.container .text span {
/* Something styled here */
}
The html your using could be improved as it is not really appropriate.
Try something like this
<div class="header">
<img src="images/grin.png" WIDTH="150" ALT="BRT" />
<h1>this is the title</h1>
<h3>This is the subtitle<h3>
</div>
.header{
overflow:hidden
}
.header img {
float:left;
}
.header{
text-align:center;
}
Thanks, #Sergio S. That worked for me. A more general way of doing this, based on Sergio's answer (is the following):
CSS:
.classofheadertext {
margin-bottom: 0px;
padding-bottom: 0px;
}
.classofsubtitletext {
margin-top: 0px;
padding-top: 0px;
}
Full credit once again to Sergio. I've just put this in simple form :D
Related
I am trying to create a round profile pic on a background image. I want the profile pic to be responsive and change size or maintain at an ideal position when switching from different screens.
Currently, I am using margin with fixed values to offset the position, but I don't think it is the right way. Please look at the following output. Even at code snippet all the alignment is off. I am not sure how do I actually code the width and height so that it will maintain at an ideal position on all screens. How to really set the margins or padding? I have tried col-sm and col-md with different parameters but it only takes col-md.
My ideal output is as follow:
iPhone X (The positioning of the profile pic and wordings are ok with the current code)
iPad (The positioning is OFF)
iPhone5/SE The position is OFF again
I have included JSFiddle, please help.
<style>
#sfitness{
position:relative;
}
* {
box-sizing: border-box;
font-family:Arial;
font-size:12px;
}
img {
width: 100%;
}
.prof{
width:90%;
position:absolute;
top:150px;
left:4%;
}
.user{
border-radius:75%; width:80px; height:80px;
}
.name, .pic{
float:left;
}
.name{
margin-left:-25px;
margin-top:20px;
}
.name span{
display:block;
text-transform:none;
font-size:8px;
}
.name p{
text-transform:uppercase;
font-size:10px;
line-height:10px;
}
.credit{
float:right;
margin-top:48px
}
.credit-pic{
width:10px;
height:10px;
}
</style>
</head>
<body id="sfitness">
<img src="https://image.ibb.co/byLwy9/profilepic.png" alt="profilepic" border="0">
<div class="container-fluid" style="">
<div class="row">
<div class="prof">
<div class="col-4 pic">
<img class="user" src="https://image.ibb.co/gGYzJ9/312eaeaba498116ab7c4cfb6ec22a049.jpg" border="0">
</div>
<div class="col-4 name">
<p>Jane Wong <span>Kuala Lampur</span></p>
</div>
<div class="col-4 credit">
<img class="credit-pic" src="https://image.ibb.co/e7UQRU/Asset_19_4x_8.png" /><span style="font-size:8px"> 0 credit</span>
</div>
</div>
</div>
</div>
</body>
This might help you.. In order to make it more responsive use media queries..
To round an image use border-radius:50%; and also specify the width and height of the image.
.user{border-radius:75%; width:100px; height:100px;}
.name, .pic{float:left;}
.prof{width:300px; position:absolute; bottom:-35px; left:4%;}
.name{padding:25px 10px;}
#sfitness{position:relative;}
.name span{display:block; text-transform:none; font-size:16px;}
.name p{text-transform:uppercase; font-size:18px;}
<body id="sfitness">
<img src="https://image.ibb.co/byLwy9/profilepic.png" alt="profilepic" border="0">
<div class="container-fluid" style="">
<div class="row">
<div class="prof">
<div class="col-4 pic">
<img class="user" src="https://image.ibb.co/gGYzJ9/312eaeaba498116ab7c4cfb6ec22a049.jpg" border="0">
</div>
<div class="col-8 name">
<p>Jane Wong <span>Kuala Lampur</span></p>
</div>
</div></div>
</body>
Here is the updated code as you said it will be responsive I think you are also using bootstrap I updated the class and rewrite some CSS
you can check .user,.information, .information p class information is a new calss
* {
box-sizing: border-box;
font-family: Arial;
font-size: 12px;
}
img {
width: 100%;
}
.profile-name {
text-align: left;
font-size: 12px;
font-weight: bold;
margin-top: 5%
}
.user {
display: inline-block;
width: 80px;
height: 80px;
-webkit-border-radius: 100px;
-moz-border-radius: 100px;
border-radius: 100px;
object-fit: cover;
float: right;
}
p {
display: flex;
flex-direction: column;
}
.information {
line-height: 16px;
margin-top: 20px;
}
.information p {
font-size: 152%;
font-weight: bold;
line-height: 19px;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<body id="sfitness">
<img src="https://image.ibb.co/byLwy9/profilepic.png" alt="profilepic" border="0">
<div class="container-fluid" style="">
<div class="row" style="margin-top:-60px">
<div class="col-xs-4 col-sm-6 col-lg-1">
<img class="user" src="https://image.ibb.co/gGYzJ9/312eaeaba498116ab7c4cfb6ec22a049.jpg" border="0">
</div>
<div class="col-xs-6 col-sm-8 col-lg-10 information">
<div class="row">
<p>Jane Worng<span>How are you</span></p>
</div>
</div>
</div>
</body>
Take use of Media Queries for the repsonsive aspect. Its way easier than doing it in javaScript:
body{
background-color: white;
}
#media only screen and (max-width: 750px) {
body {
background-color: black;
}
}
In this example the background-color of the body is white as long as the screen width is 750px or more.
I have this structure...
<body>
<div class="page-wrapper">
<div class="page-content">
<div class="login-welcome">
<h3 class="welcome">
<form class="form-login">
I'm able to apply css to login-welcome and welcome but not to form-login.
In Chrome Debugger, I don't see the styles I've set. These are the relevant styles...
.login-welcome {
position: absolute;
top: 15%;
left: 40%;
display: block;
}
.welcome {
font-weight: 600px;
font-size: 30px;
color: #653487;
}
.form-login {
padding-top: 500px;
}
In debugger, I can adjust the same padding setting by adjusting element.style so I figured using form .form-login or .form-login would work but the classes I've tried has not applied any formatting to the class. Any reason why that would be the case?
When I copy your css to chrome, there is some weird character right after the closing } of .welcome
it seems like it's stopping chrome from interpreting the next css lines
When you remove this character the following css selectors (e.g. .form-login {) are evaluated again and will be applied to your form element - everything should work then
You can use the following:
div.login-welcome .welcome{
color:red;
}
<div class="page-wrapper">
<div class="page-content">
<div class="login-welcome">
Im not affected
<h3 class="welcome">Some heading text</h3>
<form class="form-login">
some form text
</form>
</div>
</div>
</div>
It works as follows: div.login-welcome .welcome is a CSS selector which applies styles for element which have a welcome class and a <div> parent elements which have the class login-welcome.
Hopefully this was helpful.
Your code works:
.login-welcome {
position: absolute;
top: 15%;
left: 40%;
display: block;
}
.welcome {
font-weight: 600px;
font-size: 30px;
color: #653487;
}
.form-login {
padding-top: 500px;
}
<div class="page-wrapper">
<div class="page-content">
<div class="login-welcome">
<h3 class="welcome">Welcome header</h3>
<form class="form-login">
<input type="text">
</form>
</div>
</div>
</div>
look at this fiddle: https://jsbin.com/segiqoyoci/edit?html,css,output
I am trying to design a simple ecommerce website, in that my footer tag text is displayed right beside the section tag. I have no idea where I am doing wrong.
HTML
<aside id="categories">
<header id="headings" class="background_div">Categories</header>
<nav>
<ul>
<li>Staples</li>
<li>Oils</li>
<li>Vegetables</li>
<li>Fruits</li>
</ul>
</nav>
</aside>
<div id="bestsellers">
<header id="headings" class="background_div">Bestsellers</header>
<article class="productarticle">
<figure>
<img src="faded-short-sleeve-tshirts.jpg" alt="cabbage"/>
</figure>
<div class="align_text">
<header id="headings">
<span class="productarticlename">Cabbage 1</span>
</header>
<p class="productprice">$10</p>
<div class="addtocart">
Add to Cart
</div>
</div>
</article>
<!-- 4 More Article Tags will be included here -->
</div>
</section>
<footer>
<div clas="heading">This is footer text</div>
</footer>
CSS
#content{
width: 100% px;
display: block;
}
.carousel_img{
width: 1000px;
}
#headings{
font-weight: bold;
}
#categories{
float: left;
}
#bestsellers{
float: left;
margin-left: 25px;
margin-right: 0 px;
width: 80%;
height: 100%;
margin-bottom: 20 px;
}
.background_div{
background: lightgreen;
}
.productarticle{
float: left;
}
.align_text{
text-align: center;
}
Please help me. I want the content in section tag and the text in footer tag to be displayed in seperate lines.
JS-FIDDLE DEMO
See this fiddle
Since your #content contains of floated elements, you also need to float the #content div. Thus add a float:left; to #content.
Now to clear this float effect from the footer, you need to add clear:both; to your footer CSS. Thus the changed CSS would be like
#content{
width: 100% px;
display: block;
float:left;
}
footer{
clear:both;
}
In my HTML5 document I want to display an image on the far left and right of the page, and then centered inbetween them have my text. I can't for the life of me get the syntax correct. I've been looking at tons of answers for this and but I'm missing something.
My right side image is placed on the next "line" and so the text isn't centered properly.
In my index.html I put this:
<header>
<img class="logo floatLeft" alt="Logo" />
<h1 class="logoHeader">Text Here</h1>
<img class="logo floatRight" alt="Logo" />
</header>
and for my CSS I have this:
.logo {
width: 150px;
height: 120px;
content: url(logo.jpg);
}
.logoHeader {
height: 120px;
vertical-align: middle;
text-align: center;
}
.floatLeft { float: left; }
.floatRight { float: right; }
You need to put both images before ´h1´ element
<header>
<img class="logo floatLeft" alt="Logo" />
<img class="logo floatRight" alt="Logo" />
<h1 class="logoHeader">Text Here</h1>
</header>
It works, here is jsFiddle
EXPLANATION:
If you put div (or h1 or any block element) between two floating elements, its the same as you did clear:both between them, so they will never appear in the same horizontal level.
Also, off-topic here, but if you are using alt="" attribute, due to accessibility issues, if you don't have anything reasonable or descriptive to write, better off leave it empty (but still to keep the attribute) so like this alt="" is fine! The screen reader of a blind person will then skip this image because it is irrelevant for him, instead of bothering him reading "logo graphics"..who cares?. If you don't put alt attribute at all, then it will read image name, so alt="" is great if nothing more descriptive is needed.
Could your header have the 2 logos as background images, leaving the h1 to be the only semantic element in the header?
<header>
<h1>Headline</h1>
</header>
header {
background: url(logo1.png) left top no-repeat,
url(logo2.png) right top no-repeat;
}
h1{
text-align:center
}
See fiddle
In h1 selector at margin-top and margin-bottom
you just need to put 0
header{
border:1px solid black;
}
img, h1{
float:left;
height:100px;
text-align:center;
}
.logo1 {
content: url(logo.jpg);
width: 25%;
}
.logo2 {
content: url(logo.jpg);
width: 25%;
}
h1{
width:50%;
margin-top:0;
}
}
You float the images left & right, and put your text between the two image, like this.
<div class="container">
<div class="left-image">
</div>
This text is centered
<div class="right-image">
</div>
</div>
Jsfiddle
header{
border:1px solid black;
}
img, h1{
float:left;
height:100px;
text-align:center;
}
.logo1 {
content: url(logo.jpg);
width: 25%;
}
.logo2 {
content: url(logo.jpg);
width: 25%;
}
h1{
width:50%;
}
}
UPDATED
I've got a weird CSS float problem in IE6 and IE7.
My HTML is:
<fieldset style="float:left">
<legend>Summary</legend>
<div class="display-label">Recruitment type</div>
<div class="display-field">Permanent Labour</div>
<div class="display-label"># resources</div>
<div class="display-field">2</div>
<div class="display-label">Request Created</div>
<div class="display-field">4/28/2011</div>
<div class="display-label">Requested by</div>
<div class="display-field">1066594</div>
<div class="display-label">Status</div>
<div class="display-field">Active</div>
</fieldset>
and my CSS is:
.display-label, .display-field
{
padding: 0.35em 0.25em;
float: left;
}
.display-label
{
width: 13em;
text-align: right;
clear : left;
font-weight: bold;
}
.display-field
{
margin-left: 1em;
}
IE 8+ and Firefox display this correctly like this:
IE6 and 7 , though, display the following:
How can I fix this?
you do need to contain the floats, i.e. use some form of clearance, but you don't need to float everything
first remove the inline style, unfloat the fieldset
<fieldset style="float:left">
if you want fieldset to "shrink-wrap" (floating an element without a width should do this) you'd be best to set a width or max-width on it, IE hasn't quite got the shrink-wrap behaviour right the element to be "shrunk" contains elements with hasLayout which this 'fieldset` does because of the floated div(s) inside
then this CSS should work without hacking the HTML
.display-label,
.display-field {
padding: 0.35em 0.25em;
}
.display-label {
float: left;
clear: left;
width: 13em;
text-align: right;
background: #eee;
font-weight: bold;
}
.display-field {
overflow: hidden;
}
EDIT: You need to specify a a clear after the label and the field are created. You should technically be wrapping both the label and field with a container element to prevent misalignment, but this should accomplish what you're looking for.
<fieldset style="float:left">
<legend>Summary</legend>
<div class="display-label">Recruitment type</div>
<div class="display-field">Permanent Labour</div>
<div style="clear:both;"></div>
<div class="display-label"># resources</div>
<div class="display-field">2</div>
<div style="clear:both;"></div>
<div class="display-label">Request Created</div>
<div class="display-field">4/28/2011</div>
<div style="clear:both;"></div>
...
</fieldset>