CSS Wrap Text on Images [duplicate] - html

This question already has answers here:
How can I wrap text around a non rectangular image?
(5 answers)
Closed 3 years ago.
I am trying to get an image of mine to float in the center of a div. Code currently:
<style type="text/css">
#navig {
height: 333px;
}
#navig img {
display: block;
margin: 0px auto;
}
</style>
<div id="navig"><img src="images/logo.png" height="333" id="logo" /></div>
The trouble is the image is a diamond and I would like the text to wrap around the diamond with the indents. I believe this is a possibility with <img align='center' /> but this was deprecated in HTML 4.01 and not even supported in HTML 5.
I have tried several possibilities and I still cannot get the text to wrap correctly around the diamond.

Refer to this for some options. I have two options, CSS-Shapes and SVG.
The best option current is to use an SVG image but make sure to use the SVG code and not linking it as an image.
Here is a JSFIDDLE, as you can see the text is able to highlight and can be edited. (More of a pain to edit so do your best with the text in AI before saving but it can still be edited)
This is also very flexible as you can see in this FIDDLE.
This is a very new feature and does not have good browser support yet.
SO CSS-Shapes
Once this,
shape-outside: polygon(50px 0px, 100px 100px, 0px 100px);
is supported you will be able to do this with ease.
I recommend learning the basics so once it is supported by most current browsers you will already know what to do.

I managed to figure out a manual way around this. The image remains in the div and is surrounded by two other closed divs tags.
<div id="navig">
<div id="nav1"></div>
<div id="nav2"><img src="images/logo.png" height="333" id="logo" /></div>
<div id="nav3"></div>
</div>
I then make sure all three of these float left: #navig div {float:left;} and the two empty divs are using text-align. The first one will align right and the last one align left.
The two empty divs are then filled with <ul>s and the menu I wanted around it is filled into the <li> tags. For the examples I'll use some basic menu items.
<div id="navig">
<div id="nav1">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
<div id="nav2">
<img src="images/logo.png" height="333" />
</div>
<div id="nav3">
<ul>
<li>Products</li>
<li>Shipping</li>
<li>Legal</li>
</ul>
</div>
</div>
I then added #nav1 ul li:nth-child(1) and positioned the first element, which would be "Home" against the diamond. I can change "Home" to whatever I fancy and the position remains as it is forced to text-align: right. Adding these with however many <li> items you are using and editing them to suit your needs. For example:
#nav1 ul li:nth-child(1) {
position: relative;
left: 48px;
}
#nav1 ul li:nth-child(2) {
position: relative;
left: 24px;
}
#nav1 ul li:nth-child(3) {
position: relative;
left: 8px;
}
This pushed my first, second and third items over to the diamond but with a little padding so as to not intrude.
A bit of a lengthy process, but plenty of freedom and has given me the desired effect!

You can't do it with just an image.
But you can use shapes, check this page:
https://www.makeuseof.com/tag/csstextwrap/
Using CSSTextWrapper you can easily generate HTML text wraps for any
imaginable shape. It can be circles, zig-zags, triangles or whatever
you want. Quick and simple-to-use, just load the logo (optional) on
the provided dashboard and drag sidelines to define your text wrap.
Quite impressive.

Related

Image overlapping BG image and/or DIVs

I want to incorporate an image that sits on top of an existing image (and maybe straddles two different divs. In general, I would just like to see what general html structure you'd suggest -- and any CSS rules I should include. I've spent hours trying to replicate the structure I wanted -- but after inspecting elements and trying to de-construct and re-construct I was unable to produce anything close to what I wanted.
Also, in the example provided below -- I noticed the overlapping image was placed inside a span tag. Any idea why? If you could just roughly describe how you'd approach this kind of design -- that would be awesome!
This is a pretty neat effect. This is one way out of multiple you can do.
The trick is to have a fixed height on your div with background, and inside it, another div that contains the image.
I've tried to keep height/widths pretty small so you can check them correctly on the embedded snippet. I've tried to keep styles as minimal as possible to recreate what you asked for.
Let me know if something like this does the job.
.first-image{
background: #eee;
height: 250px;
}
.container{
width: 95%;
margin: 0 auto;
max-width: 400px;
}
.container--padding{
padding: 1rem 0;
}
.second-image{
margin: 2rem auto;
}
<header>
<div class="first-image">
<div class="container container--padding">
<h2>I'm the cool title headline.</h2>
<button>Download</button>
</div>
<div class="second-image">
<div class="container">
<img src="http://placehold.it/400x190" alt="placeholder" />
</div>
</div>
</div>
</header>
In the example you're referring to, the images are not <img /> tags but <div /> overlapping on top of each other. Both of these <div /> have a background image.
There are multiple solutions to make 2 <div /> overlaps, you could use absolute positioning, float, negative margins, having the background in a parent <div /> with a height greater than the height of the background image, etc.
For example, using negative margins, if I have 2 <div /> following each other like:
<div class="bg1"></div>
<div class="bg2"></div>
I could simply add a negative top margin to the second one to make it appears on top of the first one to give an illusion of overlapping like:
.bg2 {
margin-top: -40px;
}
You can check an example using negative margin on this JSFiddle.

Creating a specific, responsive layout with floated images

I have been trying to create a specific layout for some images. Layout I would like to create.
I have tried floating the smaller images so that they stand alongside the large image, this works if I add a clearfix but then for some reason the width I apply to the images is no longer effective. So it's either large images in the right positioning or small images all over the place.
I tried putting all images into separate div tags and then a parent div, then floating but that has it's own issues.
Can this be done in HTML & CSS or do I need to be going down the jQuery route?
I will be tidying the code up, I'm just trying to get it right in my head atm.
HTML:
<section id="galleryposition">
<ul id="gallery">
<div id="mainimage">
<li>
<a href="img/8.jpg">
<img src="img/8.jpg" alt=""></a>
</li>
</div>
<div id="smallphotos">
<div id="smalllefttop">
<li>
<a href="img/2.jpg">
<img src="img/2.jpg" alt="">
</a>
</li>
</div>
<div id="smallrighttop">
<li>
<a href="img/3.jpg">
<img src="img/3.jpg" alt="">
</a>
</li>
</div>
<div id="smallleftbottom">
<li>
<a href="img/4.jpg">
<img src="img/4.jpg" alt="">
</a>
</li>
</div>
<div id="smallrightbottom">
<li>
<a href="img/5.jpg">
<img src="img/5.jpg" alt="">
</a>
</li>
</div>
</div>
</ul>
</section>
CSS:
#gallery {
margin: 50px 0 0 0;
padding: 0;
list-style: none;
}
#galleryposition {
text-align: center;
}
#gallery img {
border-radius: 2.5%;
}
#gallery li {
float: left;
margin: .5%;
color: #bdc3c7;
}
#gallery li a p {
margin: 0;
padding: 5%;
font-size: 0.75em;
color: #bdc3c7;
}
#smalllefttop group {
max-width:50%;
float:left;
}
#smallrighttop group{
max-width: 50%;
float:right;
}
#smallleftbottom group{
min-width:50%;
float:left;
}
#smallrightbottom group{
min-width:50%;
float:right;
}
https://jsfiddle.net/apdeng/wyvzmm9q/1/
Thanks in advance.
Ok, so I started to play around with your code, but I was basically just re-starting it for you, which isn't what SO is for, so here are some things you need to consider:
<ul> tags are intended for lists. This definition is often stretched by developers who use them to create a "list" of links used for navigation, but in this case your image layout is complicated by the use of the <ul> and <li> structure. You'd be better served by simple <div> tags, which a) don't require both the <ul> and <li> tags and b) make more sense semantically since this is not, in fact, a list.
It's bad practice to put a <div> inside a <ul> like your #mainimage div.
The selector group in your css isn't actually doing anything. I googled this because I've never seen it before and couldn't come up with what purpose that keyword would serve. The elements followed by "group" aren't getting the styles you're trying to apply to them. I would remove that from your css.
You'll have more success with just plain old width in your css (not max-width)
Never use <br> tags to create space in a layout. Use margins and padding instead.
Make sure all your tags are closed and opened. When JSfiddle highlights the text red, that means you're missing part of a tag. (In your case, you have one too many </a> tags in each group.)
What you basically need to do is clean up your markup as much as you can and make that big image roughly 50% width and each of the other images roughly 25%. I say roughly because when you go to add margin between all of them, your total width will still need to add up to 100% (any more than that and some of your elements will bump down to the next line). That's probably what went wrong when you tried adding width to your images. Look at selectors for nth-child or last-child to help you remove the margin on the blocks on the side.
Let me know if you have more questions!

Problems positioning logo in navigation bar

I'm in the process of making a website, but am having issues positioning the logo in the navigation bar.
I've created a test version of the website at http://www.fearless-music.net/test
The logo isn't appearing in the center of it's space. In smaller browser windows, it hides behind the "Home" area of the navigation bar.
Also, are there any suggestions on code improvements I could make to my navigation bar?
Thanks again!
If you indent your code it is easier to see what's going on. Try adding the image in it's own div and enclosing it in p tags then you will be able to center it with the appropriate css rule. Tip when setting up divs using css add a colour border or background which you can later remove just to help with sizing and positioning.
<div class="header">
<div class="logo">
<p><img src="images/logo.png" alt="fearless music" /></p>
</div>
<ul class="nav">
<li class"currentpage">Home</li>
<li>Link1</li>
<li>Link2</li>
<li>Link3</li>
<li>Link4</li>
<li>Special Link</li>
</ul>
</div>
It is centered in its space. Your list items align in the middle. All the widts of the <li> tags combined are not the same as the total width of the <ul>
Use your element inspector so you can see the outlines well
You need to remove the right padding from the ul. You will see that we have a left padding of 40px.
header ul {
padding-right: 0;
}
try changing lines 31 to this - so you can see you logo, you could also add back in your margin to get in centred back in the li, but I would suggest taking the logo out of the ul so that you can have more control over it.
.nav img {
/* vertical-align: middle; */
padding: 2px 0px;
}
Good luck I hope this helps :)

How to move the H1 to be inline with the top of the DIV

I am having trouble making the <h2 class="feature_description_content"> vertically align with the image to it's left. You can see that it's quite a bit lower than the top of the image, and I can't seem to find the css that is responsible for it.
Here's an image:
Here is the code:
<div class="feature feature-item-248">
<img class="main" src="http://www.bolistylus.com/wp-content/uploads/uclaproduct.png" alt="" /></p>
<div class="feature_description">
<div class="feature_description_header">
<h2 class="descript-heading">PERFECTLY WEIGHTED</h2>
</div>
<div class="feature_description_content">
<p>Touch screens have simplified technology, but there has yet to be a way to capture the precision of a calligrapher or the stroke of an artist. Not only should it meet your needs, but a stylus should have style.</p>
</div></div>
</p></div>
Thanks
This issues is must be due to default margin and padding of default HTML elements you must try out by setting
h2
{
margin:0px;
padding:0px;
}
and then change padding as required
Set its margin-top: 0; - simple :)
The image suppose to be floated to the left and cleared both ways, so text can be aligned properly...
img .main {
float: left;
clear: both;
}

CSS - Help me style this menu without using margins?

I'm creating a site where I've encountered a huge IE lag when hovering over the menus.
I'm using Cufon in combination and it seems like it's causing a huge lag when I apply height, width, margins or paddings to the li:hover element.
So, I need to figure out a smart way of doing this otherwise.
The site is here, http://w3box.com/mat
You can clearly see the menu I guess.
So, what I want is to push the entire menu downwards so it's like 3 or 4 pixels above the bottom of the height line. So it matches about the same vertical position as the logo font to the left.
Then, I want the hover effect to be larger in height. Hard to explain, but when hovering over a menu item, imagine a box where the text is positioned at the very bottom of the box. Like this;
http://img710.imageshack.us/img710/2791/menuheader.jpg
Now, you may notice the arrow looking thingy sticking at the bottom. I don't really need that, but if you have any idea on how to do it, I'd appreciate the help! ;)
I have not tried, but I think this may be an option.
You have everything with in one div, why dont you try to put div with in divs?
this is your current code for header.
<div id="header">
<img class="LogoChef" src="img/LogoKokk2.png" alt="Logo"/>
<img class="LogoMatkalender" src="img/MatkalenderLogo.png" alt="Logo"/>
<ul class="menuwrapper">
<li><h4>Logg ut</h4></li>
<li><h4>Kontakt</h4></li>
<li><h4>Kontrollpanel</h4></li>
<li><h4>Oppskrifter</h4></li>
<li><h4>Hjem</h4></li>
</ul>
</div>
You can try something like this, so you have more control over the different objects.
<div id="header" style="float:left;vertical-align:bottom">
<div id="imgChef">
<img class="LogoChef" src="img/LogoKokk2.png" alt="Logo"/>
</div>
<div id="imgMat" style="float:left;vertical-align:bottom">
<img class="LogoMatkalender" src="img/MatkalenderLogo.png" alt="Logo"/>
</div
<div id="menu" style="float:right;vertical-align:bottom">
<ul class="menuwrapper">
<li><h4>Logg ut</h4></li> <li><h4>Kontakt</h4></li>
<li><h4>Kontrollpanel</h4></li>
<li><h4>Oppskrifter</h4></li>
<li><h4>Hjem</h4></li>
</ul>
</div>
</div>
I am not sure that may be the right combination, but I think with the three divs inside the div you will gain more control over the elements inside the header div.
Omit the h4 in the menu since i think it is not needed. Than set display:block on <a> and use line-height and padding-left , padding-right to make the anchor expand the right size. Also notice that li:hover is not supported in IE6/7 without some tweaks. To position the menu on same level as logo just set a margin-top on ul element.
There're too many rules for me, too many useless rules.
Don't have the time to correct all and test it on FF/IE, but this works ofr example :
.menuwrapper li {
float:right;
list-style: none;
padding: 30px 23px 3px 23px;
position: relative;
top: 7px;
}
What about vertical-align?